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

Side by Side Diff: chrome/browser/extensions/api/profile_keyed_api_factory.h

Issue 168253002: Cleanup many APIs to use ProfileKeyedAPI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: profile->browsercontext Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_
7 7
8 #include "chrome/browser/profiles/incognito_helpers.h" 8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 10 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
11 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 11 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 12 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
13 #include "extensions/browser/extension_system_provider.h" 13 #include "extensions/browser/extension_system_provider.h"
14 #include "extensions/browser/extensions_browser_client.h" 14 #include "extensions/browser/extensions_browser_client.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 template <typename T> 18 template <typename T>
19 class ProfileKeyedAPIFactory; 19 class ProfileKeyedAPIFactory;
20 20
21 // Instantiations of ProfileKeyedAPIFactory should use this base class 21 // Instantiations of ProfileKeyedAPIFactory should use this base class
22 // and also define a static const char* service_name() function (used in the 22 // and also define a static const char* service_name() function (used in the
23 // BrowserContextKeyedBaseFactory constructor). These fields should 23 // BrowserContextKeyedBaseFactory constructor). These fields should
24 // be accessible to the ProfileKeyedAPIFactory for the service. 24 // be accessible to the ProfileKeyedAPIFactory for the service.
25 class ProfileKeyedAPI : public BrowserContextKeyedService { 25 class ProfileKeyedAPI : public BrowserContextKeyedService {
26 protected: 26 protected:
27 // Defaults for flags that control ProfileKeyedAPIFactory behavior. 27 // Defaults for flags that control ProfileKeyedAPIFactory behavior.
28 // See BrowserContextKeyedBaseFactory for usage. 28 // See BrowserContextKeyedBaseFactory for usage.
29 static const bool kServiceRedirectedInIncognito = false; 29 static const bool kServiceRedirectedInIncognito = false;
30 static const bool kServiceIsNULLWhileTesting = false; 30 static const bool kServiceIsNULLWhileTesting = false;
James Cook 2014/02/27 01:15:59 One tiny thing that might help is to make the orde
31 static const bool kServiceHasOwnInstanceInIncognito = false; 31 static const bool kServiceHasOwnInstanceInIncognito = false;
32 static const bool kServiceIsCreatedWithBrowserContext = true; 32 static const bool kServiceIsCreatedWithBrowserContext = true;
33 33
34 // Users of this factory template must define a GetFactoryInstance() 34 // Users of this factory template must define a GetFactoryInstance()
35 // and manage their own instances (typically using LazyInstance or 35 // and manage their own instances (typically using LazyInstance or
36 // Singleton), because those cannot be included in more than one 36 // Singleton), because those cannot be included in more than one
37 // translation unit (and thus cannot be initialized in a header file). 37 // translation unit (and thus cannot be initialized in a header file).
38 // 38 //
39 // In the header file, declare GetFactoryInstance(), e.g.: 39 // In the header file, declare GetFactoryInstance(), e.g.:
40 // class ProcessesAPI { 40 // class ProcessesAPI {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 BrowserContextDependencyManager::GetInstance()) { 92 BrowserContextDependencyManager::GetInstance()) {
93 DeclareFactoryDependencies(); 93 DeclareFactoryDependencies();
94 } 94 }
95 95
96 virtual ~ProfileKeyedAPIFactory() { 96 virtual ~ProfileKeyedAPIFactory() {
97 } 97 }
98 98
99 private: 99 private:
100 // BrowserContextKeyedServiceFactory implementation. 100 // BrowserContextKeyedServiceFactory implementation.
101 virtual BrowserContextKeyedService* BuildServiceInstanceFor( 101 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
102 content::BrowserContext* profile) const OVERRIDE { 102 content::BrowserContext* context) const OVERRIDE {
103 return new T(static_cast<Profile*>(profile)); 103 return new T(static_cast<Profile*>(context));
104 } 104 }
105 105
106 // BrowserContextKeyedBaseFactory implementation. 106 // BrowserContextKeyedBaseFactory implementation.
107 // These can be effectively overridden with template specializations. 107 // These can be effectively overridden with template specializations.
108 virtual content::BrowserContext* GetBrowserContextToUse( 108 virtual content::BrowserContext* GetBrowserContextToUse(
109 content::BrowserContext* context) const OVERRIDE { 109 content::BrowserContext* context) const OVERRIDE {
110 if (T::kServiceRedirectedInIncognito) 110 if (T::kServiceRedirectedInIncognito)
111 return chrome::GetBrowserContextRedirectedInIncognito(context); 111 return chrome::GetBrowserContextRedirectedInIncognito(context);
112 112
113 if (T::kServiceHasOwnInstanceInIncognito) 113 if (T::kServiceHasOwnInstanceInIncognito)
114 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 114 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
115 115
116 return BrowserContextKeyedServiceFactory::GetBrowserContextToUse(context); 116 return BrowserContextKeyedServiceFactory::GetBrowserContextToUse(context);
117 } 117 }
118 118
119 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE { 119 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE {
120 return T::kServiceIsCreatedWithBrowserContext; 120 return T::kServiceIsCreatedWithBrowserContext;
121 } 121 }
122 122
123 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { 123 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE {
124 return T::kServiceIsNULLWhileTesting; 124 return T::kServiceIsNULLWhileTesting;
125 } 125 }
126 126
127 DISALLOW_COPY_AND_ASSIGN(ProfileKeyedAPIFactory); 127 DISALLOW_COPY_AND_ASSIGN(ProfileKeyedAPIFactory);
128 }; 128 };
129 129
130 } // namespace extensions 130 } // namespace extensions
131 131
132 #endif // CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_ 132 #endif // CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698