OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 5 #ifndef EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
6 #define EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 6 #define EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
7 | 7 |
8 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
9 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 9 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" |
10 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | 10 #include "components/keyed_service/core/keyed_service.h" |
11 #include "extensions/browser/extension_system_provider.h" | 11 #include "extensions/browser/extension_system_provider.h" |
12 #include "extensions/browser/extensions_browser_client.h" | 12 #include "extensions/browser/extensions_browser_client.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 template <typename T> | 16 template <typename T> |
17 class BrowserContextKeyedAPIFactory; | 17 class BrowserContextKeyedAPIFactory; |
18 | 18 |
19 // Instantiations of BrowserContextKeyedAPIFactory should use this base class | 19 // Instantiations of BrowserContextKeyedAPIFactory should use this base class |
20 // and also define a static const char* service_name() function (used in the | 20 // and also define a static const char* service_name() function (used in the |
21 // BrowserContextKeyedBaseFactory constructor). These fields should | 21 // BrowserContextKeyedBaseFactory constructor). These fields should |
22 // be accessible to the BrowserContextKeyedAPIFactory for the service. | 22 // be accessible to the BrowserContextKeyedAPIFactory for the service. |
23 class BrowserContextKeyedAPI : public BrowserContextKeyedService { | 23 class BrowserContextKeyedAPI : public KeyedService { |
24 protected: | 24 protected: |
25 // Defaults for flags that control BrowserContextKeyedAPIFactory behavior. | 25 // Defaults for flags that control BrowserContextKeyedAPIFactory behavior. |
26 // These can be overridden by subclasses to change that behavior. | 26 // These can be overridden by subclasses to change that behavior. |
27 // See BrowserContextKeyedBaseFactory for usage. | 27 // See BrowserContextKeyedBaseFactory for usage. |
28 | 28 |
29 // These flags affect what instance is returned when Get() is called | 29 // These flags affect what instance is returned when Get() is called |
30 // on an incognito profile. By default, it returns NULL. If | 30 // on an incognito profile. By default, it returns NULL. If |
31 // kServiceRedirectedInIncognito is true, it returns the instance for the | 31 // kServiceRedirectedInIncognito is true, it returns the instance for the |
32 // corresponding regular profile. If kServiceHasOwnInstanceInIncognito | 32 // corresponding regular profile. If kServiceHasOwnInstanceInIncognito |
33 // is true, it returns a separate instance. | 33 // is true, it returns a separate instance. |
(...skipping 24 matching lines...) Expand all Loading... | |
58 // static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> > | 58 // static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> > |
59 // g_factory = LAZY_INSTANCE_INITIALIZER; | 59 // g_factory = LAZY_INSTANCE_INITIALIZER; |
60 // | 60 // |
61 // // static | 61 // // static |
62 // BrowserContextKeyedAPIFactory<HistoryAPI>* | 62 // BrowserContextKeyedAPIFactory<HistoryAPI>* |
63 // HistoryAPI::GetFactoryInstance() { | 63 // HistoryAPI::GetFactoryInstance() { |
64 // return g_factory.Pointer(); | 64 // return g_factory.Pointer(); |
65 // } | 65 // } |
66 }; | 66 }; |
67 | 67 |
68 // A template for factories for BrowserContextKeyedServices that manage | 68 // A template for factories for BrowserContextKeyedServices that manage |
Yoyo Zhou
2014/03/12 18:30:57
Should all these references be to KeyedService now
blundell
2014/03/12 20:12:50
Yep, my mffr.py input didn't account for the plura
| |
69 // extension APIs. T is a BrowserContextKeyedService that uses this factory | 69 // extension APIs. T is a KeyedService that uses this factory |
70 // template instead of its own separate factory definition to manage its | 70 // template instead of its own separate factory definition to manage its |
71 // per-profile instances. | 71 // per-profile instances. |
72 template <typename T> | 72 template <typename T> |
73 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { | 73 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
74 public: | 74 public: |
75 static T* Get(content::BrowserContext* context) { | 75 static T* Get(content::BrowserContext* context) { |
76 return static_cast<T*>( | 76 return static_cast<T*>( |
77 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); | 77 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); |
78 } | 78 } |
79 | 79 |
(...skipping 16 matching lines...) Expand all Loading... | |
96 : BrowserContextKeyedServiceFactory( | 96 : BrowserContextKeyedServiceFactory( |
97 T::service_name(), | 97 T::service_name(), |
98 BrowserContextDependencyManager::GetInstance()) { | 98 BrowserContextDependencyManager::GetInstance()) { |
99 DeclareFactoryDependencies(); | 99 DeclareFactoryDependencies(); |
100 } | 100 } |
101 | 101 |
102 virtual ~BrowserContextKeyedAPIFactory() {} | 102 virtual ~BrowserContextKeyedAPIFactory() {} |
103 | 103 |
104 private: | 104 private: |
105 // BrowserContextKeyedServiceFactory implementation. | 105 // BrowserContextKeyedServiceFactory implementation. |
106 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 106 virtual KeyedService* BuildServiceInstanceFor( |
107 content::BrowserContext* context) const OVERRIDE { | 107 content::BrowserContext* context) const OVERRIDE { |
108 return new T(context); | 108 return new T(context); |
109 } | 109 } |
110 | 110 |
111 // BrowserContextKeyedBaseFactory implementation. | 111 // BrowserContextKeyedBaseFactory implementation. |
112 // These can be effectively overridden with template specializations. | 112 // These can be effectively overridden with template specializations. |
113 virtual content::BrowserContext* GetBrowserContextToUse( | 113 virtual content::BrowserContext* GetBrowserContextToUse( |
114 content::BrowserContext* context) const OVERRIDE { | 114 content::BrowserContext* context) const OVERRIDE { |
115 if (T::kServiceRedirectedInIncognito) | 115 if (T::kServiceRedirectedInIncognito) |
116 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 116 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
(...skipping 11 matching lines...) Expand all Loading... | |
128 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { | 128 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { |
129 return T::kServiceIsNULLWhileTesting; | 129 return T::kServiceIsNULLWhileTesting; |
130 } | 130 } |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); | 132 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); |
133 }; | 133 }; |
134 | 134 |
135 } // namespace extensions | 135 } // namespace extensions |
136 | 136 |
137 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 137 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
OLD | NEW |