| 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 COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ | 5 #ifndef COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ |
| 6 #define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ | 6 #define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "components/keyed_service/core/keyed_service_export.h" | 11 #include "components/keyed_service/core/keyed_service_export.h" |
| 11 #include "components/keyed_service/core/keyed_service_factory.h" | 12 #include "components/keyed_service/core/keyed_service_factory.h" |
| 12 | 13 |
| 13 class BrowserStateDependencyManager; | 14 class BrowserStateDependencyManager; |
| 14 class KeyedService; | 15 class KeyedService; |
| 15 | 16 |
| 16 namespace web { | 17 namespace web { |
| 17 class BrowserState; | 18 class BrowserState; |
| 18 } | 19 } |
| 19 | 20 |
| 20 // Base class for Factories that take a BrowserState object and return some | 21 // Base class for Factories that take a BrowserState object and return some |
| 21 // service on a one-to-one mapping. Each factory that derives from this class | 22 // service on a one-to-one mapping. Each factory that derives from this class |
| 22 // *must* be a Singleton (only unit tests don't do that). | 23 // *must* be a Singleton (only unit tests don't do that). |
| 23 // | 24 // |
| 24 // We do this because services depend on each other and we need to control | 25 // We do this because services depend on each other and we need to control |
| 25 // shutdown/destruction order. In each derived classes' constructors, the | 26 // shutdown/destruction order. In each derived classes' constructors, the |
| 26 // implementors must explicitly state which services are depended on. | 27 // implementors must explicitly state which services are depended on. |
| 27 class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory | 28 class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory |
| 28 : public KeyedServiceFactory { | 29 : public KeyedServiceFactory { |
| 29 public: | 30 public: |
| 30 // A function that supplies the instance of a KeyedService for a given | 31 // A function that supplies the instance of a KeyedService for a given |
| 31 // BrowserState. This is used primarily for testing, where we want to feed | 32 // BrowserState. This is used primarily for testing, where we want to feed |
| 32 // a specific mock into the BSKSF system. | 33 // a specific mock into the BSKSF system. |
| 33 typedef KeyedService* (*TestingFactoryFunction)(web::BrowserState* context); | 34 typedef scoped_ptr<KeyedService>(*TestingFactoryFunction)( |
| 35 web::BrowserState* context); |
| 34 | 36 |
| 35 // Associates |factory| with |context| so that |factory| is used to create | 37 // Associates |factory| with |context| so that |factory| is used to create |
| 36 // the KeyedService when requested. |factory| can be NULL to signal that | 38 // the KeyedService when requested. |factory| can be NULL to signal that |
| 37 // KeyedService should be NULL. Multiple calls to SetTestingFactory() are | 39 // KeyedService should be NULL. Multiple calls to SetTestingFactory() are |
| 38 // allowed; previous services will be shut down. | 40 // allowed; previous services will be shut down. |
| 39 void SetTestingFactory(web::BrowserState* context, | 41 void SetTestingFactory(web::BrowserState* context, |
| 40 TestingFactoryFunction factory); | 42 TestingFactoryFunction factory); |
| 41 | 43 |
| 42 // Associates |factory| with |context| and immediately returns the created | 44 // Associates |factory| with |context| and immediately returns the created |
| 43 // KeyedService. Since the factory will be used immediately, it may not be | 45 // KeyedService. Since the factory will be used immediately, it may not be |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 virtual void BrowserStateDestroyed(web::BrowserState* context); | 109 virtual void BrowserStateDestroyed(web::BrowserState* context); |
| 108 | 110 |
| 109 private: | 111 private: |
| 110 // Registers any user preferences on this service. This is called by | 112 // Registers any user preferences on this service. This is called by |
| 111 // RegisterPrefsIfNecessaryForContext() and should be overriden by any service | 113 // RegisterPrefsIfNecessaryForContext() and should be overriden by any service |
| 112 // that wants to register profile-specific preferences. | 114 // that wants to register profile-specific preferences. |
| 113 virtual void RegisterBrowserStatePrefs( | 115 virtual void RegisterBrowserStatePrefs( |
| 114 user_prefs::PrefRegistrySyncable* registry) {} | 116 user_prefs::PrefRegistrySyncable* registry) {} |
| 115 | 117 |
| 116 // KeyedServiceFactory: | 118 // KeyedServiceFactory: |
| 117 KeyedService* BuildServiceInstanceFor( | 119 scoped_ptr<KeyedService> BuildServiceInstanceFor( |
| 118 base::SupportsUserData* context) const final; | 120 base::SupportsUserData* context) const final; |
| 119 bool IsOffTheRecord(base::SupportsUserData* context) const final; | 121 bool IsOffTheRecord(base::SupportsUserData* context) const final; |
| 120 | 122 |
| 121 // KeyedServiceBaseFactory: | 123 // KeyedServiceBaseFactory: |
| 122 #if defined(OS_IOS) | 124 #if defined(OS_IOS) |
| 123 base::SupportsUserData* GetTypedContext( | 125 base::SupportsUserData* GetTypedContext( |
| 124 base::SupportsUserData* context) const override; | 126 base::SupportsUserData* context) const override; |
| 125 base::SupportsUserData* GetContextForDependencyManager( | 127 base::SupportsUserData* GetContextForDependencyManager( |
| 126 base::SupportsUserData* context) const override; | 128 base::SupportsUserData* context) const override; |
| 127 #endif // defined(OS_IOS) | 129 #endif // defined(OS_IOS) |
| 128 base::SupportsUserData* GetContextToUse( | 130 base::SupportsUserData* GetContextToUse( |
| 129 base::SupportsUserData* context) const final; | 131 base::SupportsUserData* context) const final; |
| 130 bool ServiceIsCreatedWithContext() const final; | 132 bool ServiceIsCreatedWithContext() const final; |
| 131 void ContextShutdown(base::SupportsUserData* context) final; | 133 void ContextShutdown(base::SupportsUserData* context) final; |
| 132 void ContextDestroyed(base::SupportsUserData* context) final; | 134 void ContextDestroyed(base::SupportsUserData* context) final; |
| 133 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) final; | 135 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) final; |
| 134 | 136 |
| 135 DISALLOW_COPY_AND_ASSIGN(BrowserStateKeyedServiceFactory); | 137 DISALLOW_COPY_AND_ASSIGN(BrowserStateKeyedServiceFactory); |
| 136 }; | 138 }; |
| 137 | 139 |
| 138 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ | 140 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ |
| OLD | NEW |