| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/features/base_feature_provider.h" | 5 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 BaseFeatureProvider::~BaseFeatureProvider() { | 182 BaseFeatureProvider::~BaseFeatureProvider() { |
| 183 } | 183 } |
| 184 | 184 |
| 185 // static | 185 // static |
| 186 FeatureProvider* BaseFeatureProvider::GetByName( | 186 FeatureProvider* BaseFeatureProvider::GetByName( |
| 187 const std::string& name) { | 187 const std::string& name) { |
| 188 return g_static.Get().GetFeatures(name); | 188 return g_static.Get().GetFeatures(name); |
| 189 } | 189 } |
| 190 | 190 |
| 191 const std::vector<std::string>& BaseFeatureProvider::GetAllFeatureNames() { | 191 const std::vector<std::string>& BaseFeatureProvider::GetAllFeatureNames() |
| 192 const { |
| 192 if (feature_names_.empty()) { | 193 if (feature_names_.empty()) { |
| 193 for (FeatureMap::const_iterator iter = features_.begin(); | 194 for (FeatureMap::const_iterator iter = features_.begin(); |
| 194 iter != features_.end(); ++iter) { | 195 iter != features_.end(); ++iter) { |
| 195 feature_names_.push_back(iter->first); | 196 feature_names_.push_back(iter->first); |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 return feature_names_; | 199 return feature_names_; |
| 199 } | 200 } |
| 200 | 201 |
| 201 Feature* BaseFeatureProvider::GetFeature(const std::string& name) { | 202 Feature* BaseFeatureProvider::GetFeature(const std::string& name) const { |
| 202 FeatureMap::iterator iter = features_.find(name); | 203 FeatureMap::const_iterator iter = features_.find(name); |
| 203 if (iter != features_.end()) | 204 if (iter != features_.end()) |
| 204 return iter->second.get(); | 205 return iter->second.get(); |
| 205 else | 206 else |
| 206 return NULL; | 207 return NULL; |
| 207 } | 208 } |
| 208 | 209 |
| 209 Feature* BaseFeatureProvider::GetParent(Feature* feature) { | 210 Feature* BaseFeatureProvider::GetParent(Feature* feature) const { |
| 210 CHECK(feature); | 211 CHECK(feature); |
| 211 if (feature->no_parent()) | 212 if (feature->no_parent()) |
| 212 return NULL; | 213 return NULL; |
| 213 | 214 |
| 214 std::vector<std::string> split; | 215 std::vector<std::string> split; |
| 215 base::SplitString(feature->name(), '.', &split); | 216 base::SplitString(feature->name(), '.', &split); |
| 216 if (split.size() < 2) | 217 if (split.size() < 2) |
| 217 return NULL; | 218 return NULL; |
| 218 split.pop_back(); | 219 split.pop_back(); |
| 219 return GetFeature(JoinString(split, '.')); | 220 return GetFeature(JoinString(split, '.')); |
| 220 } | 221 } |
| 221 | 222 |
| 222 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |