Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: extensions/browser/api/declarative/deduping_factory.h

Issue 2236443003: extensions: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't add braces Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__ 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__
6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__ 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 : max_number_prototypes_(max_number_prototypes) {} 99 : max_number_prototypes_(max_number_prototypes) {}
100 100
101 template<typename BaseClassT> 101 template<typename BaseClassT>
102 DedupingFactory<BaseClassT>::~DedupingFactory() {} 102 DedupingFactory<BaseClassT>::~DedupingFactory() {}
103 103
104 template<typename BaseClassT> 104 template<typename BaseClassT>
105 void DedupingFactory<BaseClassT>::RegisterFactoryMethod( 105 void DedupingFactory<BaseClassT>::RegisterFactoryMethod(
106 const std::string& instance_type, 106 const std::string& instance_type,
107 typename DedupingFactory<BaseClassT>::Parameterized parameterized, 107 typename DedupingFactory<BaseClassT>::Parameterized parameterized,
108 FactoryMethod factory_method) { 108 FactoryMethod factory_method) {
109 DCHECK(!ContainsKey(factory_methods_, instance_type)); 109 DCHECK(!base::ContainsKey(factory_methods_, instance_type));
110 factory_methods_[instance_type] = factory_method; 110 factory_methods_[instance_type] = factory_method;
111 if (parameterized == IS_PARAMETERIZED) 111 if (parameterized == IS_PARAMETERIZED)
112 parameterized_types_.insert(instance_type); 112 parameterized_types_.insert(instance_type);
113 } 113 }
114 114
115 template<typename BaseClassT> 115 template<typename BaseClassT>
116 scoped_refptr<const BaseClassT> DedupingFactory<BaseClassT>::Instantiate( 116 scoped_refptr<const BaseClassT> DedupingFactory<BaseClassT>::Instantiate(
117 const std::string& instance_type, 117 const std::string& instance_type,
118 const base::Value* value, 118 const base::Value* value,
119 std::string* error, 119 std::string* error,
120 bool* bad_message) { 120 bool* bad_message) {
121 typename FactoryMethods::const_iterator factory_method_iter = 121 typename FactoryMethods::const_iterator factory_method_iter =
122 factory_methods_.find(instance_type); 122 factory_methods_.find(instance_type);
123 if (factory_method_iter == factory_methods_.end()) { 123 if (factory_method_iter == factory_methods_.end()) {
124 *error = "Invalid instance type " + instance_type; 124 *error = "Invalid instance type " + instance_type;
125 *bad_message = true; 125 *bad_message = true;
126 return scoped_refptr<const BaseClassT>(); 126 return scoped_refptr<const BaseClassT>();
127 } 127 }
128 128
129 FactoryMethod factory_method = factory_method_iter->second; 129 FactoryMethod factory_method = factory_method_iter->second;
130 130
131 PrototypeList& prototypes = prototypes_[instance_type]; 131 PrototypeList& prototypes = prototypes_[instance_type];
132 132
133 // We can take a shortcut for objects that are not parameterized. For those 133 // We can take a shortcut for objects that are not parameterized. For those
134 // only a single instance may ever exist so we can simplify the creation 134 // only a single instance may ever exist so we can simplify the creation
135 // logic. 135 // logic.
136 if (!ContainsKey(parameterized_types_, instance_type)) { 136 if (!base::ContainsKey(parameterized_types_, instance_type)) {
137 if (prototypes.empty()) { 137 if (prototypes.empty()) {
138 scoped_refptr<const BaseClassT> new_object = 138 scoped_refptr<const BaseClassT> new_object =
139 (*factory_method)(instance_type, value, error, bad_message); 139 (*factory_method)(instance_type, value, error, bad_message);
140 if (!new_object.get() || !error->empty() || *bad_message) 140 if (!new_object.get() || !error->empty() || *bad_message)
141 return scoped_refptr<const BaseClassT>(); 141 return scoped_refptr<const BaseClassT>();
142 prototypes.push_back(new_object); 142 prototypes.push_back(new_object);
143 } 143 }
144 return prototypes.front(); 144 return prototypes.front();
145 } 145 }
146 146
(...skipping 26 matching lines...) Expand all
173 } 173 }
174 174
175 template<typename BaseClassT> 175 template<typename BaseClassT>
176 void DedupingFactory<BaseClassT>::ClearPrototypes() { 176 void DedupingFactory<BaseClassT>::ClearPrototypes() {
177 prototypes_.clear(); 177 prototypes_.clear();
178 } 178 }
179 179
180 } // namespace extensions 180 } // namespace extensions
181 181
182 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__ 182 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__
OLDNEW
« no previous file with comments | « extensions/browser/api/declarative/declarative_rule_unittest.cc ('k') | extensions/browser/api/declarative/rules_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698