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"
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
{
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();
27 friend struct base::DefaultLazyInstanceTraits
<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
> >
42 FeatureProviderMap feature_providers_
;
45 base::LazyInstance
<Static
> g_static
= LAZY_INSTANCE_INITIALIZER
;
50 const FeatureProvider
* FeatureProvider::GetByName(const std::string
& name
) {
51 return g_static
.Get().GetFeatures(name
);
55 const FeatureProvider
* FeatureProvider::GetAPIFeatures() {
56 return GetByName("api");
60 const FeatureProvider
* FeatureProvider::GetManifestFeatures() {
61 return GetByName("manifest");
65 const FeatureProvider
* FeatureProvider::GetPermissionFeatures() {
66 return GetByName("permission");
69 } // namespace extensions