• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "extensions/common/features/feature_provider.h"
6 
7 #include <map>
8 
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"
13 
14 namespace extensions {
15 
16 namespace {
17 
18 class Static {
19  public:
GetFeatures(const std::string & name) const20   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();
24   }
25 
26  private:
27   friend struct base::DefaultLazyInstanceTraits<Static>;
28 
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());
37   }
38 
39   typedef std::map<std::string, linked_ptr<FeatureProvider> >
40       FeatureProviderMap;
41 
42   FeatureProviderMap feature_providers_;
43 };
44 
45 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
46 
47 }  // namespace
48 
49 // static
GetByName(const std::string & name)50 const FeatureProvider* FeatureProvider::GetByName(const std::string& name) {
51   return g_static.Get().GetFeatures(name);
52 }
53 
54 // static
GetAPIFeatures()55 const FeatureProvider* FeatureProvider::GetAPIFeatures() {
56   return GetByName("api");
57 }
58 
59 // static
GetManifestFeatures()60 const FeatureProvider* FeatureProvider::GetManifestFeatures() {
61   return GetByName("manifest");
62 }
63 
64 // static
GetPermissionFeatures()65 const FeatureProvider* FeatureProvider::GetPermissionFeatures() {
66   return GetByName("permission");
67 }
68 
69 }  // namespace extensions
70