OLD | NEW |
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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // } | 54 // } |
55 }; | 55 }; |
56 | 56 |
57 // A template for factories for BrowserContextKeyedServices that manage | 57 // A template for factories for BrowserContextKeyedServices that manage |
58 // extension APIs. T is a BrowserContextKeyedService that uses this factory | 58 // extension APIs. T is a BrowserContextKeyedService that uses this factory |
59 // template instead of its own separate factory definition to manage its | 59 // template instead of its own separate factory definition to manage its |
60 // per-profile instances. | 60 // per-profile instances. |
61 template <typename T> | 61 template <typename T> |
62 class ProfileKeyedAPIFactory : public BrowserContextKeyedServiceFactory { | 62 class ProfileKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
63 public: | 63 public: |
| 64 // TODO(yoz): Delete this one. |
64 static T* GetForProfile(Profile* profile) { | 65 static T* GetForProfile(Profile* profile) { |
65 return static_cast<T*>( | 66 return static_cast<T*>( |
66 T::GetFactoryInstance()->GetServiceForBrowserContext(profile, true)); | 67 T::GetFactoryInstance()->GetServiceForBrowserContext(profile, true)); |
67 } | 68 } |
68 | 69 |
| 70 static T* GetForProfile(content::BrowserContext* context) { |
| 71 return static_cast<T*>(T::GetFactoryInstance()->GetServiceForBrowserContext( |
| 72 Profile::FromBrowserContext(context), true)); |
| 73 } |
| 74 |
69 // Declare dependencies on other factories. | 75 // Declare dependencies on other factories. |
70 // By default, ExtensionSystemFactory is the only dependency; however, | 76 // By default, ExtensionSystemFactory is the only dependency; however, |
71 // specializations can override this. Declare your specialization in | 77 // specializations can override this. Declare your specialization in |
72 // your header file after the ProfileKeyedAPI class definition. | 78 // your header file after the ProfileKeyedAPI class definition. |
73 // Then in the cc file (or inline in the header), define it, e.g.: | 79 // Then in the cc file (or inline in the header), define it, e.g.: |
74 // template <> | 80 // template <> |
75 // ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 81 // ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
76 // DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 82 // DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
77 // DependsOn(ProfileSyncServiceFactory::GetInstance()); | 83 // DependsOn(ProfileSyncServiceFactory::GetInstance()); |
78 // } | 84 // } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { | 123 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { |
118 return T::kServiceIsNULLWhileTesting; | 124 return T::kServiceIsNULLWhileTesting; |
119 } | 125 } |
120 | 126 |
121 DISALLOW_COPY_AND_ASSIGN(ProfileKeyedAPIFactory); | 127 DISALLOW_COPY_AND_ASSIGN(ProfileKeyedAPIFactory); |
122 }; | 128 }; |
123 | 129 |
124 } // namespace extensions | 130 } // namespace extensions |
125 | 131 |
126 #endif // CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_ | 132 #endif // CHROME_BROWSER_EXTENSIONS_API_PROFILE_KEYED_API_FACTORY_H_ |
OLD | NEW |