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

Unified Diff: chrome/browser/extensions/api/profile_keyed_api_factory.h

Issue 11682005: Remove some Profile-keyed factory boilerplate: management omnibox preference push_messaging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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: chrome/browser/extensions/api/profile_keyed_api_factory.h
diff --git a/chrome/browser/extensions/api/profile_keyed_api_factory.h b/chrome/browser/extensions/api/profile_keyed_api_factory.h
index e8cb29d379cc771cd738943496d0fdda25f06b9b..f6d34a8d74bd1ca2ed1ead124bb2beea2042ec28 100644
--- a/chrome/browser/extensions/api/profile_keyed_api_factory.h
+++ b/chrome/browser/extensions/api/profile_keyed_api_factory.h
@@ -12,6 +12,9 @@
namespace extensions {
+template <typename T>
+class ProfileKeyedAPIFactory;
+
// Instantiations of ProfileKeyedAPIFactory should use this base class
// and also define a static const char* service_name() function (used in the
// ProfileKeyedBaseFactory constructor). These fields should be accessible
@@ -21,7 +24,30 @@ class ProfileKeyedAPI : public ProfileKeyedService {
// Defaults for flags that control ProfileKeyedAPIFactory behavior.
// See ProfileKeyedBaseFactory for usage.
static const bool kServiceRedirectedInIncognito = false;
+ static const bool kServiceIsCreatedWithProfile = true;
static const bool kServiceIsNULLWhileTesting = false;
+
+ // Users of this factory template must define a GetFactoryInstance()
+ // and manage their own instances (typically using LazyInstance or
+ // Singleton), because those cannot be included in more than one
+ // translation unit (and thus cannot be initialized in a header file).
+ //
+ // In the header file, declare GetFactoryInstance(), e.g.:
+ // class ProcessesAPI {
+ // ...
+ // public:
+ // static ProfileKeyedAPIFactory<ProcessesAPI>* GetFactoryInstance();
+ // };
+ //
+ // In the cc file, provide the implementation, e.g.:
+ // static base::LazyInstance<ProfileKeyedAPIFactory<ProcessesAPI> >
+ // g_factory = LAZY_INSTANCE_INITIALIZER;
+ //
+ // // static
+ // ProfileKeyedAPIFactory<ProcessesAPI>*
+ // ProcessesAPI::GetFactoryInstance() {
+ // return &g_factory.Get();
+ // }
};
// A template for factories for ProfileKeyedServices that manage extension APIs.
@@ -32,31 +58,9 @@ class ProfileKeyedAPIFactory : public ProfileKeyedServiceFactory {
public:
static T* GetForProfile(Profile* profile) {
return static_cast<T*>(
- GetInstance()->GetServiceForProfile(profile, true));
+ T::GetFactoryInstance()->GetServiceForProfile(profile, true));
}
- // Users of this factory template must manage their own instances
- // (typically using LazyInstance or Singleton), because those cannot be
- // included in more than one translation unit (and thus cannot be initialized
- // in a header file).
- //
- // In the header file, declare the specialization, e.g.:
- // template <>
- // ProfileKeyedAPIFactory<ProcessesAPI>
- // ProfileKeyedAPIFactory<ProcessesAPI>::GetInstance();
- //
- // In the cc file, provide the implementation:
- // static base::LazyInstance<ProfileKeyedAPIFactory<ProcessesAPI> >
- // g_factory = LAZY_INSTANCE_INITIALIZER;
- //
- // template <>
- // ProfileKeyedAPIFactory<ProcessesAPI>*
- // ProfileKeyedAPIFactory<ProcessesAPI>::GetInstance() {
- // return &g_factory.Get();
- // }
-
- static ProfileKeyedAPIFactory* GetInstance();
-
// Declare dependencies on other factories.
// By default, ExtensionSystemFactory is the only dependency; however,
// specializations can override this. Declare your specialization in
@@ -94,7 +98,7 @@ class ProfileKeyedAPIFactory : public ProfileKeyedServiceFactory {
}
virtual bool ServiceIsCreatedWithProfile() const OVERRIDE {
- return true;
+ return T::kServiceIsCreatedWithProfile;
}
virtual bool ServiceIsNULLWhileTesting() const OVERRIDE {

Powered by Google App Engine
This is Rietveld 408576698