OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 PrototypeList& prototypes = prototypes_[instance_type]; | 128 PrototypeList& prototypes = prototypes_[instance_type]; |
129 | 129 |
130 // We can take a shortcut for objects that are not parameterized. For those | 130 // We can take a shortcut for objects that are not parameterized. For those |
131 // only a single instance may ever exist so we can simplify the creation | 131 // only a single instance may ever exist so we can simplify the creation |
132 // logic. | 132 // logic. |
133 if (!ContainsKey(parameterized_types_, instance_type)) { | 133 if (!ContainsKey(parameterized_types_, instance_type)) { |
134 if (prototypes.empty()) { | 134 if (prototypes.empty()) { |
135 scoped_refptr<const BaseClassT> new_object = | 135 scoped_refptr<const BaseClassT> new_object = |
136 (*factory_method)(instance_type, value, error, bad_message); | 136 (*factory_method)(instance_type, value, error, bad_message); |
137 if (!new_object || !error->empty() || *bad_message) | 137 if (!new_object.get() || !error->empty() || *bad_message) |
138 return scoped_refptr<const BaseClassT>(); | 138 return scoped_refptr<const BaseClassT>(); |
139 prototypes.push_back(new_object); | 139 prototypes.push_back(new_object); |
140 } | 140 } |
141 return prototypes.front(); | 141 return prototypes.front(); |
142 } | 142 } |
143 | 143 |
144 // Handle parameterized objects. | 144 // Handle parameterized objects. |
145 scoped_refptr<const BaseClassT> new_object = | 145 scoped_refptr<const BaseClassT> new_object = |
146 (*factory_method)(instance_type, value, error, bad_message); | 146 (*factory_method)(instance_type, value, error, bad_message); |
147 if (!new_object || !error->empty() || *bad_message) | 147 if (!new_object.get() || !error->empty() || *bad_message) |
148 return scoped_refptr<const BaseClassT>(); | 148 return scoped_refptr<const BaseClassT>(); |
149 | 149 |
150 size_t length = 0; | 150 size_t length = 0; |
151 for (typename PrototypeList::iterator i = prototypes.begin(); | 151 for (typename PrototypeList::iterator i = prototypes.begin(); |
152 i != prototypes.end(); | 152 i != prototypes.end(); |
153 ++i) { | 153 ++i) { |
154 if ((*i)->Equals(new_object.get())) { | 154 if ((*i)->Equals(new_object.get())) { |
155 // Move the old object to the end of the queue so that it gets | 155 // Move the old object to the end of the queue so that it gets |
156 // discarded later. | 156 // discarded later. |
157 scoped_refptr<const BaseClassT> old_object = *i; | 157 scoped_refptr<const BaseClassT> old_object = *i; |
(...skipping 12 matching lines...) Expand all Loading... |
170 } | 170 } |
171 | 171 |
172 template<typename BaseClassT> | 172 template<typename BaseClassT> |
173 void DedupingFactory<BaseClassT>::ClearPrototypes() { | 173 void DedupingFactory<BaseClassT>::ClearPrototypes() { |
174 prototypes_.clear(); | 174 prototypes_.clear(); |
175 } | 175 } |
176 | 176 |
177 } // namespace extensions | 177 } // namespace extensions |
178 | 178 |
179 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ | 179 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_DEDUPING_FACTORY_H__ |
OLD | NEW |