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

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

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: . Created 3 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "extensions/common/features/feature_provider.h" 5 #include "extensions/common/features/feature_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return iter->second.get(); 133 return iter->second.get();
134 else 134 else
135 return nullptr; 135 return nullptr;
136 } 136 }
137 137
138 Feature* FeatureProvider::GetParent(Feature* feature) const { 138 Feature* FeatureProvider::GetParent(Feature* feature) const {
139 CHECK(feature); 139 CHECK(feature);
140 if (feature->no_parent()) 140 if (feature->no_parent())
141 return nullptr; 141 return nullptr;
142 142
143 std::vector<base::StringPiece> split = base::SplitStringPiece( 143 base::StringPiece name = feature->name();
144 feature->name(), ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 144 base::StringPiece::size_type pos = base::StringPiece::npos;
145 if (split.size() < 2) 145 // Continue searching up the chain, so that foo.child.grandchild has a parent
146 return nullptr; 146 // of foo (even if foo.child isn't explicitly defined).
147 split.pop_back(); 147 while ((pos = name.rfind('.')) != base::StringPiece::npos) {
148 return GetFeature(base::JoinString(split, ".")); 148 name = name.substr(0, pos);
149 Feature* feature = GetFeature(name.as_string());
150 if (feature)
151 return feature;
152 }
153 return nullptr;
149 } 154 }
150 155
151 // Children of a given API are named starting with parent.name()+".", which 156 // Children of a given API are named starting with parent.name()+".", which
152 // means they'll be contiguous in the features_ std::map. 157 // means they'll be contiguous in the features_ std::map.
153 std::vector<Feature*> FeatureProvider::GetChildren( 158 std::vector<Feature*> FeatureProvider::GetChildren(
154 const Feature& parent) const { 159 const Feature& parent) const {
155 std::string prefix = parent.name() + "."; 160 std::string prefix = parent.name() + ".";
156 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix); 161 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix);
157 162
158 // All children have names before (parent.name() + ('.'+1)). 163 // All children have names before (parent.name() + ('.'+1)).
(...skipping 18 matching lines...) Expand all
177 void FeatureProvider::AddFeature(base::StringPiece name, 182 void FeatureProvider::AddFeature(base::StringPiece name,
178 std::unique_ptr<Feature> feature) { 183 std::unique_ptr<Feature> feature) {
179 features_[name.as_string()] = std::move(feature); 184 features_[name.as_string()] = std::move(feature);
180 } 185 }
181 186
182 void FeatureProvider::AddFeature(base::StringPiece name, Feature* feature) { 187 void FeatureProvider::AddFeature(base::StringPiece name, Feature* feature) {
183 features_[name.as_string()] = std::unique_ptr<Feature>(feature); 188 features_[name.as_string()] = std::unique_ptr<Feature>(feature);
184 } 189 }
185 190
186 } // namespace extensions 191 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698