OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 5 #ifndef EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
6 #define EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 6 #define EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
7 | 7 |
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
9 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | 9 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" |
10 #include "components/keyed_service/core/keyed_service.h" | 10 #include "components/keyed_service/core/keyed_service.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // a KeyedService that uses this factory template instead of its own separate | 69 // a KeyedService that uses this factory template instead of its own separate |
70 // factory definition to manage its per-profile instances. | 70 // factory definition to manage its per-profile instances. |
71 template <typename T> | 71 template <typename T> |
72 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { | 72 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
73 public: | 73 public: |
74 static T* Get(content::BrowserContext* context) { | 74 static T* Get(content::BrowserContext* context) { |
75 return static_cast<T*>( | 75 return static_cast<T*>( |
76 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); | 76 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); |
77 } | 77 } |
78 | 78 |
79 static T* Get(content::BrowserContext* context, bool create) { | |
not at google - send to devlin
2015/07/20 21:17:57
I'd rather a method like "GetIfExists" in addition
| |
80 return static_cast<T*>( | |
81 T::GetFactoryInstance()->GetServiceForBrowserContext(context, create)); | |
82 } | |
83 | |
79 // Declare dependencies on other factories. | 84 // Declare dependencies on other factories. |
80 // By default, ExtensionSystemFactory is the only dependency; however, | 85 // By default, ExtensionSystemFactory is the only dependency; however, |
81 // specializations can override this. Declare your specialization in | 86 // specializations can override this. Declare your specialization in |
82 // your header file after the BrowserContextKeyedAPI class definition. | 87 // your header file after the BrowserContextKeyedAPI class definition. |
83 // Then in the cc file (or inline in the header), define it, e.g.: | 88 // Then in the cc file (or inline in the header), define it, e.g.: |
84 // template <> | 89 // template <> |
85 // void BrowserContextKeyedAPIFactory< | 90 // void BrowserContextKeyedAPIFactory< |
86 // PushMessagingAPI>::DeclareFactoryDependencies() { | 91 // PushMessagingAPI>::DeclareFactoryDependencies() { |
87 // DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 92 // DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
88 // DependsOn(ProfileSyncServiceFactory::GetInstance()); | 93 // DependsOn(ProfileSyncServiceFactory::GetInstance()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 bool ServiceIsNULLWhileTesting() const override { | 132 bool ServiceIsNULLWhileTesting() const override { |
128 return T::kServiceIsNULLWhileTesting; | 133 return T::kServiceIsNULLWhileTesting; |
129 } | 134 } |
130 | 135 |
131 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); | 136 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); |
132 }; | 137 }; |
133 | 138 |
134 } // namespace extensions | 139 } // namespace extensions |
135 | 140 |
136 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 141 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
OLD | NEW |