Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / features / feature_provider.cc
blob1923836a91cf5dd71772bb22e68059d0c3e0af1c
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
3 // found in the LICENSE file.
5 #include "extensions/common/features/feature_provider.h"
7 #include <map>
9 #include "base/basictypes.h"
10 #include "base/lazy_instance.h"
11 #include "base/memory/linked_ptr.h"
12 #include "extensions/common/extensions_client.h"
14 namespace extensions {
16 namespace {
18 class Static {
19 public:
20 FeatureProvider* GetFeatures(const std::string& name) const {
21 FeatureProviderMap::const_iterator it = feature_providers_.find(name);
22 CHECK(it != feature_providers_.end());
23 return it->second.get();
26 private:
27 friend struct base::DefaultLazyInstanceTraits<Static>;
29 Static() {
30 ExtensionsClient* client = ExtensionsClient::Get();
31 feature_providers_["api"] =
32 make_linked_ptr(client->CreateFeatureProvider("api").release());
33 feature_providers_["manifest"] =
34 make_linked_ptr(client->CreateFeatureProvider("manifest").release());
35 feature_providers_["permission"] =
36 make_linked_ptr(client->CreateFeatureProvider("permission").release());
39 typedef std::map<std::string, linked_ptr<FeatureProvider> >
40 FeatureProviderMap;
42 FeatureProviderMap feature_providers_;
45 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
47 } // namespace
49 // static
50 const FeatureProvider* FeatureProvider::GetByName(const std::string& name) {
51 return g_static.Get().GetFeatures(name);
54 // static
55 const FeatureProvider* FeatureProvider::GetAPIFeatures() {
56 return GetByName("api");
59 // static
60 const FeatureProvider* FeatureProvider::GetManifestFeatures() {
61 return GetByName("manifest");
64 // static
65 const FeatureProvider* FeatureProvider::GetPermissionFeatures() {
66 return GetByName("permission");
69 } // namespace extensions