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 <stack> | 7 #include <stack> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 std::vector<std::string> split; | 55 std::vector<std::string> split; |
56 base::SplitString(iter.key(), '.', &split); | 56 base::SplitString(iter.key(), '.', &split); |
57 | 57 |
58 // Push parent features on the stack, starting with the current feature. | 58 // Push parent features on the stack, starting with the current feature. |
59 // If one of the features has "noparent" set, stop pushing features on | 59 // If one of the features has "noparent" set, stop pushing features on |
60 // the stack. The features will then be parsed in order, starting with | 60 // the stack. The features will then be parsed in order, starting with |
61 // the farthest parent that is either top level or has "noparent" set. | 61 // the farthest parent that is either top level or has "noparent" set. |
62 std::stack<std::pair<std::string, const base::DictionaryValue*> > | 62 std::stack<std::pair<std::string, const base::DictionaryValue*> > |
63 parse_stack; | 63 parse_stack; |
64 while (!split.empty()) { | 64 while (!split.empty()) { |
65 std::string parent_name = JoinString(split, '.'); | 65 std::string parent_name = base::JoinString(split, "."); |
66 split.pop_back(); | 66 split.pop_back(); |
67 if (root.HasKey(parent_name)) { | 67 if (root.HasKey(parent_name)) { |
68 const base::DictionaryValue* parent = nullptr; | 68 const base::DictionaryValue* parent = nullptr; |
69 if (!root.GetDictionaryWithoutPathExpansion(parent_name, &parent)) { | 69 if (!root.GetDictionaryWithoutPathExpansion(parent_name, &parent)) { |
70 // If the parent is a complex feature, find the parent with the | 70 // If the parent is a complex feature, find the parent with the |
71 // 'default_parent' flag. | 71 // 'default_parent' flag. |
72 const base::ListValue* parent_list = nullptr; | 72 const base::ListValue* parent_list = nullptr; |
73 CHECK(root.GetListWithoutPathExpansion(parent_name, &parent_list)); | 73 CHECK(root.GetListWithoutPathExpansion(parent_name, &parent_list)); |
74 for (size_t i = 0; i < parent_list->GetSize(); ++i) { | 74 for (size_t i = 0; i < parent_list->GetSize(); ++i) { |
75 CHECK(parent_list->GetDictionary(i, &parent)); | 75 CHECK(parent_list->GetDictionary(i, &parent)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 Feature* BaseFeatureProvider::GetParent(Feature* feature) const { | 169 Feature* BaseFeatureProvider::GetParent(Feature* feature) const { |
170 CHECK(feature); | 170 CHECK(feature); |
171 if (feature->no_parent()) | 171 if (feature->no_parent()) |
172 return nullptr; | 172 return nullptr; |
173 | 173 |
174 std::vector<std::string> split; | 174 std::vector<std::string> split; |
175 base::SplitString(feature->name(), '.', &split); | 175 base::SplitString(feature->name(), '.', &split); |
176 if (split.size() < 2) | 176 if (split.size() < 2) |
177 return nullptr; | 177 return nullptr; |
178 split.pop_back(); | 178 split.pop_back(); |
179 return GetFeature(JoinString(split, '.')); | 179 return GetFeature(base::JoinString(split, ".")); |
180 } | 180 } |
181 | 181 |
182 // Children of a given API are named starting with parent.name()+".", which | 182 // Children of a given API are named starting with parent.name()+".", which |
183 // means they'll be contiguous in the features_ std::map. | 183 // means they'll be contiguous in the features_ std::map. |
184 std::vector<Feature*> BaseFeatureProvider::GetChildren(const Feature& parent) | 184 std::vector<Feature*> BaseFeatureProvider::GetChildren(const Feature& parent) |
185 const { | 185 const { |
186 std::string prefix = parent.name() + "."; | 186 std::string prefix = parent.name() + "."; |
187 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix); | 187 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix); |
188 | 188 |
189 // All children have names before (parent.name() + ('.'+1)). | 189 // All children have names before (parent.name() + ('.'+1)). |
190 ++prefix[prefix.size() - 1]; | 190 ++prefix[prefix.size() - 1]; |
191 const FeatureMap::const_iterator after_children = | 191 const FeatureMap::const_iterator after_children = |
192 features_.lower_bound(prefix); | 192 features_.lower_bound(prefix); |
193 | 193 |
194 std::vector<Feature*> result; | 194 std::vector<Feature*> result; |
195 result.reserve(std::distance(first_child, after_children)); | 195 result.reserve(std::distance(first_child, after_children)); |
196 for (FeatureMap::const_iterator it = first_child; it != after_children; | 196 for (FeatureMap::const_iterator it = first_child; it != after_children; |
197 ++it) { | 197 ++it) { |
198 result.push_back(it->second.get()); | 198 result.push_back(it->second.get()); |
199 } | 199 } |
200 return result; | 200 return result; |
201 } | 201 } |
202 | 202 |
203 } // namespace extensions | 203 } // namespace extensions |
OLD | NEW |