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

Side by Side Diff: components/keyed_service/ios/browser_state_keyed_service_factory.h

Issue 1918083002: Convert //components/[f-n]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: … Created 4 years, 7 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
OLDNEW
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 <memory>
9
8 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "components/keyed_service/core/keyed_service_export.h" 12 #include "components/keyed_service/core/keyed_service_export.h"
12 #include "components/keyed_service/core/keyed_service_factory.h" 13 #include "components/keyed_service/core/keyed_service_factory.h"
13 14
14 class BrowserStateDependencyManager; 15 class BrowserStateDependencyManager;
15 class KeyedService; 16 class KeyedService;
16 17
17 namespace web { 18 namespace web {
18 class BrowserState; 19 class BrowserState;
19 } 20 }
20 21
21 // Base class for Factories that take a BrowserState object and return some 22 // Base class for Factories that take a BrowserState object and return some
22 // service on a one-to-one mapping. Each factory that derives from this class 23 // service on a one-to-one mapping. Each factory that derives from this class
23 // *must* be a Singleton (only unit tests don't do that). 24 // *must* be a Singleton (only unit tests don't do that).
24 // 25 //
25 // We do this because services depend on each other and we need to control 26 // We do this because services depend on each other and we need to control
26 // shutdown/destruction order. In each derived classes' constructors, the 27 // shutdown/destruction order. In each derived classes' constructors, the
27 // implementors must explicitly state which services are depended on. 28 // implementors must explicitly state which services are depended on.
28 class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory 29 class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory
29 : public KeyedServiceFactory { 30 : public KeyedServiceFactory {
30 public: 31 public:
31 // A function that supplies the instance of a KeyedService for a given 32 // A function that supplies the instance of a KeyedService for a given
32 // BrowserState. This is used primarily for testing, where we want to feed 33 // BrowserState. This is used primarily for testing, where we want to feed
33 // a specific mock into the BSKSF system. 34 // a specific mock into the BSKSF system.
34 typedef scoped_ptr<KeyedService>(*TestingFactoryFunction)( 35 using TestingFactoryFunction =
35 web::BrowserState* context); 36 std::unique_ptr<KeyedService> (*)(web::BrowserState* context);
36 37
37 // Associates |factory| with |context| so that |factory| is used to create 38 // Associates |factory| with |context| so that |factory| is used to create
38 // the KeyedService when requested. |factory| can be NULL to signal that 39 // the KeyedService when requested. |factory| can be NULL to signal that
39 // KeyedService should be NULL. Multiple calls to SetTestingFactory() are 40 // KeyedService should be NULL. Multiple calls to SetTestingFactory() are
40 // allowed; previous services will be shut down. 41 // allowed; previous services will be shut down.
41 void SetTestingFactory(web::BrowserState* context, 42 void SetTestingFactory(web::BrowserState* context,
42 TestingFactoryFunction factory); 43 TestingFactoryFunction factory);
43 44
44 // Associates |factory| with |context| and immediately returns the created 45 // Associates |factory| with |context| and immediately returns the created
45 // KeyedService. Since the factory will be used immediately, it may not be 46 // KeyedService. Since the factory will be used immediately, it may not be
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // You can override this so that by default, the service associated with the 84 // You can override this so that by default, the service associated with the
84 // TestingBrowserState is NULL. (This is just a shortcut around 85 // TestingBrowserState is NULL. (This is just a shortcut around
85 // SetTestingFactory() to make sure our contexts don't directly refer to the 86 // SetTestingFactory() to make sure our contexts don't directly refer to the
86 // services they use.) 87 // services they use.)
87 bool ServiceIsNULLWhileTesting() const override; 88 bool ServiceIsNULLWhileTesting() const override;
88 89
89 // Interface for people building a type of BrowserStateKeyedFactory: ------- 90 // Interface for people building a type of BrowserStateKeyedFactory: -------
90 91
91 // All subclasses of BrowserStateKeyedServiceFactory must return a 92 // All subclasses of BrowserStateKeyedServiceFactory must return a
92 // KeyedService instead of just a BrowserStateKeyedBase. 93 // KeyedService instead of just a BrowserStateKeyedBase.
93 virtual scoped_ptr<KeyedService> BuildServiceInstanceFor( 94 virtual std::unique_ptr<KeyedService> BuildServiceInstanceFor(
94 web::BrowserState* context) const = 0; 95 web::BrowserState* context) const = 0;
95 96
96 // A helper object actually listens for notifications about BrowserState 97 // A helper object actually listens for notifications about BrowserState
97 // destruction, calculates the order in which things are destroyed and then 98 // destruction, calculates the order in which things are destroyed and then
98 // does a two pass shutdown. 99 // does a two pass shutdown.
99 // 100 //
100 // First, BrowserStateShutdown() is called on every ServiceFactory and will 101 // First, BrowserStateShutdown() is called on every ServiceFactory and will
101 // usually call KeyedService::Shutdown(), which gives each 102 // usually call KeyedService::Shutdown(), which gives each
102 // KeyedService a chance to remove dependencies on other 103 // KeyedService a chance to remove dependencies on other
103 // services that it may be holding. 104 // services that it may be holding.
104 // 105 //
105 // Secondly, BrowserStateDestroyed() is called on every ServiceFactory 106 // Secondly, BrowserStateDestroyed() is called on every ServiceFactory
106 // and the default implementation removes it from |mapping_| and deletes 107 // and the default implementation removes it from |mapping_| and deletes
107 // the pointer. 108 // the pointer.
108 virtual void BrowserStateShutdown(web::BrowserState* context); 109 virtual void BrowserStateShutdown(web::BrowserState* context);
109 virtual void BrowserStateDestroyed(web::BrowserState* context); 110 virtual void BrowserStateDestroyed(web::BrowserState* context);
110 111
111 private: 112 private:
112 // Registers any user preferences on this service. This is called by 113 // Registers any user preferences on this service. This is called by
113 // RegisterPrefsIfNecessaryForContext() and should be overriden by any service 114 // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
114 // that wants to register profile-specific preferences. 115 // that wants to register profile-specific preferences.
115 virtual void RegisterBrowserStatePrefs( 116 virtual void RegisterBrowserStatePrefs(
116 user_prefs::PrefRegistrySyncable* registry) {} 117 user_prefs::PrefRegistrySyncable* registry) {}
117 118
118 // KeyedServiceFactory: 119 // KeyedServiceFactory:
119 scoped_ptr<KeyedService> BuildServiceInstanceFor( 120 std::unique_ptr<KeyedService> BuildServiceInstanceFor(
120 base::SupportsUserData* context) const final; 121 base::SupportsUserData* context) const final;
121 bool IsOffTheRecord(base::SupportsUserData* context) const final; 122 bool IsOffTheRecord(base::SupportsUserData* context) const final;
122 123
123 // KeyedServiceBaseFactory: 124 // KeyedServiceBaseFactory:
124 base::SupportsUserData* GetContextToUse( 125 base::SupportsUserData* GetContextToUse(
125 base::SupportsUserData* context) const final; 126 base::SupportsUserData* context) const final;
126 bool ServiceIsCreatedWithContext() const final; 127 bool ServiceIsCreatedWithContext() const final;
127 void ContextShutdown(base::SupportsUserData* context) final; 128 void ContextShutdown(base::SupportsUserData* context) final;
128 void ContextDestroyed(base::SupportsUserData* context) final; 129 void ContextDestroyed(base::SupportsUserData* context) final;
129 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) final; 130 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) final;
130 131
131 DISALLOW_COPY_AND_ASSIGN(BrowserStateKeyedServiceFactory); 132 DISALLOW_COPY_AND_ASSIGN(BrowserStateKeyedServiceFactory);
132 }; 133 };
133 134
134 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_ 135 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_KEYED_SERVICE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698