Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3176)

Unified Diff: extensions/browser/browser_context_keyed_api_factory.h

Issue 2863213004: ProcessManagerFactory: fix dependencies in ApiResourceManager, LazyBgndTaskFactory (Closed)
Patch Set: devlin feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ac3caeb98573c914fad039805e727fbe64d3966e 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.
+// 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,31 +107,24 @@ 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());
- // }
- void DeclareFactoryDependencies() {
- DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
- }
+ // Declares dependencies on other factories.
+ // Deprecated. Use BrowserContextFactoryDependencies<> to declare
+ // dependencies instead.
+ void DeclareFactoryDependencies() {}
BrowserContextKeyedAPIFactory()
: BrowserContextKeyedServiceFactory(
T::service_name(),
BrowserContextDependencyManager::GetInstance()) {
DeclareFactoryDependencies();
+ BrowserContextFactoryDependencies<T>::DeclareFactoryDependencies(this);
Devlin 2017/05/12 22:53:59 Hmm... wouldn't doing this result in ExtensionSyst
Kevin M 2017/05/15 18:09:04 Hm, yes. Thanks. How's this for backwards compatib
Devlin 2017/05/15 18:24:52 SGTM; that should work!
}
~BrowserContextKeyedAPIFactory() override {}
private:
+ friend struct BrowserContextFactoryDependencies<T>;
+
// BrowserContextKeyedServiceFactory implementation.
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override {

Powered by Google App Engine
This is Rietveld 408576698