Chromium Code Reviews| Index: extensions/browser/browser_context_keyed_api_factory.h |
| diff --git a/extensions/browser/browser_context_keyed_api_factory.h b/extensions/browser/browser_context_keyed_api_factory.h |
| index 1316c08875870e9263f000909b929389661d860b..ab67cc7659664138522af4bfd56eed9d164ef1f9 100644 |
| --- a/extensions/browser/browser_context_keyed_api_factory.h |
| +++ b/extensions/browser/browser_context_keyed_api_factory.h |
| @@ -66,6 +66,31 @@ class BrowserContextKeyedAPI : public KeyedService { |
| // } |
| }; |
| +// Declare dependencies on other factories. |
| +// By default, ExtensionSystemFactory is the only dependency; however, |
| +// specializations can override this. Declare your specialization in |
| +// your header file after the BrowserContextKeyedAPI class definition. |
| +// Declare this struct in the header file. The implementation may optionally |
| +// be placed in your .cc file. |
|
Devlin
2017/05/15 18:24:52
For background, maybe we should include a comment
Kevin M
2017/05/15 18:34:39
Done - added the explanation to the deprecated Dec
Devlin
2017/05/15 18:37:47
I dunno - I think it might help avoid a well-meani
Kevin M
2017/05/15 18:43:01
Done.
|
| +// template <> |
| +// struct BrowserContextFactoryDependencies<MyService> { |
| +// static void DeclareFactoryDependencies( |
| +// BrowserContextKeyedAPIFactory<ApiResourceManager<T>>* factory) { |
| +// factory->DependsOn( |
| +// ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| +// factory->DependsOn(ProfileSyncServiceFactory::GetInstance()); |
| +// ... |
| +// } |
| +// }; |
| +template <typename T> |
| +struct BrowserContextFactoryDependencies { |
| + static void DeclareFactoryDependencies( |
| + BrowserContextKeyedAPIFactory<T>* factory) { |
| + factory->DependsOn( |
| + ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| + } |
| +}; |
| + |
| // A template for factories for KeyedServices that manage extension APIs. T is |
| // a KeyedService that uses this factory template instead of its own separate |
| // factory definition to manage its per-profile instances. |
| @@ -82,19 +107,11 @@ class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
| T::GetFactoryInstance()->GetServiceForBrowserContext(context, false)); |
| } |
| - // Declare dependencies on other factories. |
| - // By default, ExtensionSystemFactory is the only dependency; however, |
| - // specializations can override this. Declare your specialization in |
| - // your header file after the BrowserContextKeyedAPI class definition. |
| - // Then in the cc file (or inline in the header), define it, e.g.: |
| - // template <> |
| - // void BrowserContextKeyedAPIFactory< |
| - // PushMessagingAPI>::DeclareFactoryDependencies() { |
| - // DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| - // DependsOn(ProfileSyncServiceFactory::GetInstance()); |
| - // } |
| + // Declares dependencies on other factories. |
| + // Deprecated. Use BrowserContextFactoryDependencies<> to declare |
| + // dependencies instead. |
| void DeclareFactoryDependencies() { |
| - DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| + BrowserContextFactoryDependencies<T>::DeclareFactoryDependencies(this); |
| } |
| BrowserContextKeyedAPIFactory() |
| @@ -107,6 +124,8 @@ class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
| ~BrowserContextKeyedAPIFactory() override {} |
| private: |
| + friend struct BrowserContextFactoryDependencies<T>; |
| + |
| // BrowserContextKeyedServiceFactory implementation. |
| KeyedService* BuildServiceInstanceFor( |
| content::BrowserContext* context) const override { |