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

Side by Side Diff: extensions/common/features/base_feature_provider.cc

Issue 1272823003: Update SplitString calls to new form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « extensions/common/csp_validator.cc ('k') | extensions/common/manifest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 : factory_(factory) { 45 : factory_(factory) {
46 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd(); 46 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd();
47 iter.Advance()) { 47 iter.Advance()) {
48 if (IsNocompile(iter.value())) { 48 if (IsNocompile(iter.value())) {
49 continue; 49 continue;
50 } 50 }
51 51
52 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) { 52 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) {
53 linked_ptr<SimpleFeature> feature((*factory_)()); 53 linked_ptr<SimpleFeature> feature((*factory_)());
54 54
55 std::vector<std::string> split; 55 std::vector<std::string> split = base::SplitString(
56 base::SplitString(iter.key(), '.', &split); 56 iter.key(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
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 = base::JoinString(split, "."); 65 std::string parent_name = base::JoinString(split, ".");
66 split.pop_back(); 66 split.pop_back();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return iter->second.get(); 164 return iter->second.get();
165 else 165 else
166 return nullptr; 166 return nullptr;
167 } 167 }
168 168
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 = base::SplitString(
175 base::SplitString(feature->name(), '.', &split); 175 feature->name(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
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(base::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
OLDNEW
« no previous file with comments | « extensions/common/csp_validator.cc ('k') | extensions/common/manifest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698