| 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/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 9 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 9 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 10 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 10 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "extensions/browser/extension_system_provider.h" | 11 #include "extensions/browser/extension_system_provider.h" |
| 12 #include "extensions/browser/extensions_browser_client.h" | 12 #include "extensions/browser/extensions_browser_client.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 template <typename T> | 16 template <typename T> |
| 17 class BrowserContextKeyedAPIFactory; | 17 class BrowserContextKeyedAPIFactory; |
| 18 | 18 |
| 19 // Instantiations of BrowserContextKeyedAPIFactory should use this base class | 19 // Instantiations of BrowserContextKeyedAPIFactory should use this base class |
| 20 // and also define a static const char* service_name() function (used in the | 20 // and also define a static const char* service_name() function (used in the |
| 21 // BrowserContextKeyedBaseFactory constructor). These fields should | 21 // BrowserContextKeyedBaseFactory constructor). These fields should |
| 22 // be accessible to the BrowserContextKeyedAPIFactory for the service. | 22 // be accessible to the BrowserContextKeyedAPIFactory for the service. |
| 23 class BrowserContextKeyedAPI : public BrowserContextKeyedService { | 23 class BrowserContextKeyedAPI : public KeyedService { |
| 24 protected: | 24 protected: |
| 25 // Defaults for flags that control BrowserContextKeyedAPIFactory behavior. | 25 // Defaults for flags that control BrowserContextKeyedAPIFactory behavior. |
| 26 // These can be overridden by subclasses to change that behavior. | 26 // These can be overridden by subclasses to change that behavior. |
| 27 // See BrowserContextKeyedBaseFactory for usage. | 27 // See BrowserContextKeyedBaseFactory for usage. |
| 28 | 28 |
| 29 // These flags affect what instance is returned when Get() is called | 29 // These flags affect what instance is returned when Get() is called |
| 30 // on an incognito profile. By default, it returns NULL. If | 30 // on an incognito profile. By default, it returns NULL. If |
| 31 // kServiceRedirectedInIncognito is true, it returns the instance for the | 31 // kServiceRedirectedInIncognito is true, it returns the instance for the |
| 32 // corresponding regular profile. If kServiceHasOwnInstanceInIncognito | 32 // corresponding regular profile. If kServiceHasOwnInstanceInIncognito |
| 33 // is true, it returns a separate instance. | 33 // is true, it returns a separate instance. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 58 // static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> > | 58 // static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> > |
| 59 // g_factory = LAZY_INSTANCE_INITIALIZER; | 59 // g_factory = LAZY_INSTANCE_INITIALIZER; |
| 60 // | 60 // |
| 61 // // static | 61 // // static |
| 62 // BrowserContextKeyedAPIFactory<HistoryAPI>* | 62 // BrowserContextKeyedAPIFactory<HistoryAPI>* |
| 63 // HistoryAPI::GetFactoryInstance() { | 63 // HistoryAPI::GetFactoryInstance() { |
| 64 // return g_factory.Pointer(); | 64 // return g_factory.Pointer(); |
| 65 // } | 65 // } |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // A template for factories for BrowserContextKeyedServices that manage | 68 // A template for factories for KeyedServices that manage extension APIs. T is |
| 69 // extension APIs. T is a BrowserContextKeyedService that uses this factory | 69 // a KeyedService that uses this factory template instead of its own separate |
| 70 // template instead of its own separate factory definition to manage its | 70 // factory definition to manage its per-profile instances. |
| 71 // per-profile instances. | |
| 72 template <typename T> | 71 template <typename T> |
| 73 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { | 72 class BrowserContextKeyedAPIFactory : public BrowserContextKeyedServiceFactory { |
| 74 public: | 73 public: |
| 75 static T* Get(content::BrowserContext* context) { | 74 static T* Get(content::BrowserContext* context) { |
| 76 return static_cast<T*>( | 75 return static_cast<T*>( |
| 77 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); | 76 T::GetFactoryInstance()->GetServiceForBrowserContext(context, true)); |
| 78 } | 77 } |
| 79 | 78 |
| 80 // Declare dependencies on other factories. | 79 // Declare dependencies on other factories. |
| 81 // By default, ExtensionSystemFactory is the only dependency; however, | 80 // By default, ExtensionSystemFactory is the only dependency; however, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 96 : BrowserContextKeyedServiceFactory( | 95 : BrowserContextKeyedServiceFactory( |
| 97 T::service_name(), | 96 T::service_name(), |
| 98 BrowserContextDependencyManager::GetInstance()) { | 97 BrowserContextDependencyManager::GetInstance()) { |
| 99 DeclareFactoryDependencies(); | 98 DeclareFactoryDependencies(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 virtual ~BrowserContextKeyedAPIFactory() {} | 101 virtual ~BrowserContextKeyedAPIFactory() {} |
| 103 | 102 |
| 104 private: | 103 private: |
| 105 // BrowserContextKeyedServiceFactory implementation. | 104 // BrowserContextKeyedServiceFactory implementation. |
| 106 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 105 virtual KeyedService* BuildServiceInstanceFor( |
| 107 content::BrowserContext* context) const OVERRIDE { | 106 content::BrowserContext* context) const OVERRIDE { |
| 108 return new T(context); | 107 return new T(context); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // BrowserContextKeyedBaseFactory implementation. | 110 // BrowserContextKeyedBaseFactory implementation. |
| 112 // These can be effectively overridden with template specializations. | 111 // These can be effectively overridden with template specializations. |
| 113 virtual content::BrowserContext* GetBrowserContextToUse( | 112 virtual content::BrowserContext* GetBrowserContextToUse( |
| 114 content::BrowserContext* context) const OVERRIDE { | 113 content::BrowserContext* context) const OVERRIDE { |
| 115 if (T::kServiceRedirectedInIncognito) | 114 if (T::kServiceRedirectedInIncognito) |
| 116 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 115 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { | 127 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE { |
| 129 return T::kServiceIsNULLWhileTesting; | 128 return T::kServiceIsNULLWhileTesting; |
| 130 } | 129 } |
| 131 | 130 |
| 132 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); | 131 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedAPIFactory); |
| 133 }; | 132 }; |
| 134 | 133 |
| 135 } // namespace extensions | 134 } // namespace extensions |
| 136 | 135 |
| 137 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ | 136 #endif // EXTENSIONS_BROWSER_BROWSER_CONTEXT_KEYED_API_FACTORY_H_ |
| OLD | NEW |