OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "extensions/common/features/base_feature_provider.h" | 5 #include "extensions/common/features/base_feature_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <stack> | 9 #include <stack> |
10 #include <utility> | 10 #include <utility> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 BaseFeatureProvider::BaseFeatureProvider(const base::DictionaryValue& root, | 46 BaseFeatureProvider::BaseFeatureProvider(const base::DictionaryValue& root, |
47 FeatureFactory factory) | 47 FeatureFactory factory) |
48 : factory_(factory) { | 48 : factory_(factory) { |
49 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd(); | 49 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd(); |
50 iter.Advance()) { | 50 iter.Advance()) { |
51 if (IsNocompile(iter.value())) { | 51 if (IsNocompile(iter.value())) { |
52 continue; | 52 continue; |
53 } | 53 } |
54 | 54 |
55 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) { | 55 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) { |
56 scoped_ptr<SimpleFeature> feature((*factory_)()); | 56 std::unique_ptr<SimpleFeature> feature((*factory_)()); |
57 | 57 |
58 std::vector<std::string> split = base::SplitString( | 58 std::vector<std::string> split = base::SplitString( |
59 iter.key(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 59 iter.key(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
60 | 60 |
61 // Push parent features on the stack, starting with the current feature. | 61 // Push parent features on the stack, starting with the current feature. |
62 // If one of the features has "noparent" set, stop pushing features on | 62 // If one of the features has "noparent" set, stop pushing features on |
63 // the stack. The features will then be parsed in order, starting with | 63 // the stack. The features will then be parsed in order, starting with |
64 // the farthest parent that is either top level or has "noparent" set. | 64 // the farthest parent that is either top level or has "noparent" set. |
65 std::stack<std::pair<std::string, const base::DictionaryValue*> > | 65 std::stack<std::pair<std::string, const base::DictionaryValue*> > |
66 parse_stack; | 66 parse_stack; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (parse_error) | 107 if (parse_error) |
108 continue; | 108 continue; |
109 | 109 |
110 features_[iter.key()] = std::move(feature); | 110 features_[iter.key()] = std::move(feature); |
111 } else if (iter.value().GetType() == base::Value::TYPE_LIST) { | 111 } else if (iter.value().GetType() == base::Value::TYPE_LIST) { |
112 // This is a complex feature. | 112 // This is a complex feature. |
113 const base::ListValue* list = | 113 const base::ListValue* list = |
114 static_cast<const base::ListValue*>(&iter.value()); | 114 static_cast<const base::ListValue*>(&iter.value()); |
115 CHECK_GT(list->GetSize(), 0UL); | 115 CHECK_GT(list->GetSize(), 0UL); |
116 | 116 |
117 scoped_ptr<ComplexFeature::FeatureList> features( | 117 std::unique_ptr<ComplexFeature::FeatureList> features( |
118 new ComplexFeature::FeatureList()); | 118 new ComplexFeature::FeatureList()); |
119 | 119 |
120 // Parse and add all SimpleFeatures from the list. | 120 // Parse and add all SimpleFeatures from the list. |
121 for (base::ListValue::const_iterator list_iter = list->begin(); | 121 for (base::ListValue::const_iterator list_iter = list->begin(); |
122 list_iter != list->end(); ++list_iter) { | 122 list_iter != list->end(); ++list_iter) { |
123 if ((*list_iter)->GetType() != base::Value::TYPE_DICTIONARY) { | 123 if ((*list_iter)->GetType() != base::Value::TYPE_DICTIONARY) { |
124 LOG(ERROR) << iter.key() << ": Feature rules must be dictionaries."; | 124 LOG(ERROR) << iter.key() << ": Feature rules must be dictionaries."; |
125 continue; | 125 continue; |
126 } | 126 } |
127 | 127 |
128 scoped_ptr<SimpleFeature> feature((*factory_)()); | 128 std::unique_ptr<SimpleFeature> feature((*factory_)()); |
129 if (!ParseFeature(static_cast<const base::DictionaryValue*>(*list_iter), | 129 if (!ParseFeature(static_cast<const base::DictionaryValue*>(*list_iter), |
130 iter.key(), | 130 iter.key(), |
131 feature.get())) | 131 feature.get())) |
132 continue; | 132 continue; |
133 | 133 |
134 features->push_back(std::move(feature)); | 134 features->push_back(std::move(feature)); |
135 } | 135 } |
136 | 136 |
137 scoped_ptr<ComplexFeature> feature( | 137 std::unique_ptr<ComplexFeature> feature( |
138 new ComplexFeature(std::move(features))); | 138 new ComplexFeature(std::move(features))); |
139 feature->set_name(iter.key()); | 139 feature->set_name(iter.key()); |
140 | 140 |
141 features_[iter.key()] = std::move(feature); | 141 features_[iter.key()] = std::move(feature); |
142 } else { | 142 } else { |
143 LOG(ERROR) << iter.key() << ": Feature description must be dictionary or" | 143 LOG(ERROR) << iter.key() << ": Feature description must be dictionary or" |
144 << " list of dictionaries."; | 144 << " list of dictionaries."; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 std::vector<Feature*> result; | 189 std::vector<Feature*> result; |
190 result.reserve(std::distance(first_child, after_children)); | 190 result.reserve(std::distance(first_child, after_children)); |
191 for (FeatureMap::const_iterator it = first_child; it != after_children; | 191 for (FeatureMap::const_iterator it = first_child; it != after_children; |
192 ++it) { | 192 ++it) { |
193 result.push_back(it->second.get()); | 193 result.push_back(it->second.get()); |
194 } | 194 } |
195 return result; | 195 return result; |
196 } | 196 } |
197 | 197 |
198 } // namespace extensions | 198 } // namespace extensions |
OLD | NEW |