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

Side by Side Diff: components/browser_context_keyed_service/browser_context_keyed_base_factory.h

Issue 15517005: Remove references to Profile from browser_context_keyed_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase & style Created 7 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 | Annotate | Revision Log
OLDNEW
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 COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_FACT ORY_H_ 5 #ifndef COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_FACT ORY_H_
6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_FACT ORY_H_ 6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_FACT ORY_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/threading/non_thread_safe.h" 10 #include "base/threading/non_thread_safe.h"
11 #include "components/browser_context_keyed_service/dependency_node.h" 11 #include "components/browser_context_keyed_service/dependency_node.h"
12 12
13 class BrowserContextDependencyManager;
13 class PrefService; 14 class PrefService;
14 class ProfileDependencyManager;
15 15
16 namespace content { 16 namespace content {
17 class BrowserContext; 17 class BrowserContext;
18 } 18 }
19 19
20 namespace user_prefs { 20 namespace user_prefs {
21 class PrefRegistrySyncable; 21 class PrefRegistrySyncable;
22 } 22 }
23 // Base class for Factories that take a Profile object and return some service. 23
24 // Base class for Factories that take a BrowserContext object and return some
25 // service.
24 // 26 //
25 // Unless you're trying to make a new type of Factory, you probably don't want 27 // Unless you're trying to make a new type of Factory, you probably don't want
26 // this class, but its subclasses: ProfileKeyedServiceFactory and 28 // this class, but its subclasses: BrowserContextKeyedServiceFactory and
27 // RefcountedProfileKeyedServiceFactory. This object describes general 29 // RefcountedBrowserContextKeyedServiceFactory. This object describes general
28 // dependency management between Factories; subclasses react to lifecycle 30 // dependency management between Factories; subclasses react to lifecycle
29 // events and implement memory management. 31 // events and implement memory management.
30 class ProfileKeyedBaseFactory : public base::NonThreadSafe, 32 class BrowserContextKeyedBaseFactory : public base::NonThreadSafe,
31 public DependencyNode { 33 public DependencyNode {
32 public: 34 public:
33 // Registers preferences used in this service on the pref service of 35 // Registers preferences used in this service on the pref service of
34 // |profile|. This is the public interface and is safe to be called multiple 36 // |context|. This is the public interface and is safe to be called multiple
35 // times because testing code can have multiple services of the same type 37 // times because testing code can have multiple services of the same type
36 // attached to a single |profile|. 38 // attached to a single |context|.
37 void RegisterUserPrefsOnProfile(content::BrowserContext* profile); 39 void RegisterUserPrefsOnBrowserContext(content::BrowserContext* context);
38 40
39 #ifndef NDEBUG 41 #ifndef NDEBUG
40 // Returns our name. We don't keep track of this in release mode. 42 // Returns our name. We don't keep track of this in release mode.
41 const char* name() const { return service_name_; } 43 const char* name() const { return service_name_; }
42 #endif 44 #endif
43 45
44 protected: 46 protected:
45 ProfileKeyedBaseFactory(const char* name, 47 BrowserContextKeyedBaseFactory(const char* name,
46 ProfileDependencyManager* manager); 48 BrowserContextDependencyManager* manager);
47 virtual ~ProfileKeyedBaseFactory(); 49 virtual ~BrowserContextKeyedBaseFactory();
48 50
49 // The main public interface for declaring dependencies between services 51 // The main public interface for declaring dependencies between services
50 // created by factories. 52 // created by factories.
51 void DependsOn(ProfileKeyedBaseFactory* rhs); 53 void DependsOn(BrowserContextKeyedBaseFactory* rhs);
52 54
53 // Interface for people building a concrete FooServiceFactory: -------------- 55 // Interface for people building a concrete FooServiceFactory: --------------
54 56
55 // Finds which browser context (if any) to use. 57 // Finds which browser context (if any) to use.
56 virtual content::BrowserContext* GetBrowserContextToUse( 58 virtual content::BrowserContext* GetBrowserContextToUse(
57 content::BrowserContext* context) const; 59 content::BrowserContext* context) const;
58 60
59 // Register any user preferences on this service. This is called during 61 // Register any user preferences on this service. This is called during
60 // CreateProfileService() since preferences are registered on a per Profile 62 // CreateBrowserContextService() since preferences are registered on a per
61 // basis. 63 // BrowserContext basis.
62 virtual void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry) {} 64 virtual void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry) {}
63 65
64 // By default, we create instances of a service lazily and wait until 66 // By default, we create instances of a service lazily and wait until
65 // GetForProfile() is called on our subclass. Some services need to be 67 // GetForBrowserContext() is called on our subclass. Some services need to be
66 // created as soon as the Profile has been brought up. 68 // created as soon as the BrowserContext has been brought up.
67 virtual bool ServiceIsCreatedWithProfile() const; 69 virtual bool ServiceIsCreatedWithBrowserContext() const;
68 70
69 // By default, TestingProfiles will be treated like normal profiles. You can 71 // By default, TestingBrowserContexts will be treated like normal contexts.
70 // override this so that by default, the service associated with the 72 // You can override this so that by default, the service associated with the
71 // TestingProfile is NULL. (This is just a shortcut around 73 // TestingBrowserContext is NULL. (This is just a shortcut around
72 // SetTestingFactory() to make sure our profiles don't directly refer to the 74 // SetTestingFactory() to make sure our contexts don't directly refer to the
73 // services they use.) 75 // services they use.)
74 virtual bool ServiceIsNULLWhileTesting() const; 76 virtual bool ServiceIsNULLWhileTesting() const;
75 77
76 // Interface for people building a type of ProfileKeyedFactory: ------------- 78 // Interface for people building a type of BrowserContextKeyedFactory: -------
77 79
78 // A helper object actually listens for notifications about Profile 80 // A helper object actually listens for notifications about BrowserContext
79 // destruction, calculates the order in which things are destroyed and then 81 // destruction, calculates the order in which things are destroyed and then
80 // does a two pass shutdown. 82 // does a two pass shutdown.
81 // 83 //
82 // It is up to the individual factory types to determine what this two pass 84 // It is up to the individual factory types to determine what this two pass
83 // shutdown means. The general framework guarantees the following: 85 // shutdown means. The general framework guarantees the following:
84 // 86 //
85 // - Each ProfileShutdown() is called in dependency order (and you may reach 87 // - Each BrowserContextShutdown() is called in dependency order (and you may
86 // out to other services during this phase). 88 // reach out to other services during this phase).
87 // 89 //
88 // - Each ProfileDestroyed() is called in dependency order. We will 90 // - Each BrowserContextDestroyed() is called in dependency order. We will
89 // NOTREACHED() if you attempt to GetForProfile() any other service. You 91 // NOTREACHED() if you attempt to GetForBrowserContext() any other service.
90 // should delete/deref/do other final memory management things during this 92 // You should delete/deref/do other final memory management things during
91 // phase. You must also call the base class method as the last thing you 93 // this phase. You must also call the base class method as the last thing
92 // do. 94 // you do.
93 virtual void ProfileShutdown(content::BrowserContext* profile) = 0; 95 virtual void BrowserContextShutdown(content::BrowserContext* context) = 0;
94 virtual void ProfileDestroyed(content::BrowserContext* profile); 96 virtual void BrowserContextDestroyed(content::BrowserContext* context);
95 97
96 // Returns whether we've registered the preferences on this profile. 98 // Returns whether we've registered the preferences on this context.
97 bool ArePreferencesSetOn(content::BrowserContext* profile) const; 99 bool ArePreferencesSetOn(content::BrowserContext* context) const;
98 100
99 // Mark profile as Preferences set. 101 // Mark context as Preferences set.
100 void MarkPreferencesSetOn(content::BrowserContext* profile); 102 void MarkPreferencesSetOn(content::BrowserContext* context);
101 103
102 private: 104 private:
103 friend class ProfileDependencyManager; 105 friend class BrowserContextDependencyManager;
104 friend class ProfileDependencyManagerUnittests; 106 friend class BrowserContextDependencyManagerUnittests;
105 107
106 // These two methods are for tight integration with the 108 // These two methods are for tight integration with the
107 // ProfileDependencyManager. 109 // BrowserContextDependencyManager.
108 110
109 // Because of ServiceIsNULLWhileTesting(), we need a way to tell different 111 // Because of ServiceIsNULLWhileTesting(), we need a way to tell different
110 // subclasses that they should disable testing. 112 // subclasses that they should disable testing.
111 virtual void SetEmptyTestingFactory(content::BrowserContext* profile) = 0; 113 virtual void SetEmptyTestingFactory(content::BrowserContext* context) = 0;
112 114
113 // We also need a generalized, non-returning method that generates the object 115 // We also need a generalized, non-returning method that generates the object
114 // now for when we're creating the profile. 116 // now for when we're creating the context.
115 virtual void CreateServiceNow(content::BrowserContext* profile) = 0; 117 virtual void CreateServiceNow(content::BrowserContext* context) = 0;
116 118
117 // Which ProfileDependencyManager we should communicate with. In real code, 119 // Which BrowserContextDependencyManager we should communicate with.
118 // this will always be ProfileDependencyManager::GetInstance(), but unit 120 // In real code, this will always be
119 // tests will want to use their own copy. 121 // BrowserContextDependencyManager::GetInstance(), but unit tests will want
120 ProfileDependencyManager* dependency_manager_; 122 // to use their own copy.
123 BrowserContextDependencyManager* dependency_manager_;
121 124
122 // Profiles that have this service's preferences registered on them. 125 // BrowserContexts that have this service's preferences registered on them.
123 std::set<content::BrowserContext*> registered_preferences_; 126 std::set<content::BrowserContext*> registered_preferences_;
124 127
125 #if !defined(NDEBUG) 128 #if !defined(NDEBUG)
126 // A static string passed in to our constructor. Should be unique across all 129 // A static string passed in to our constructor. Should be unique across all
127 // services. This is used only for debugging in debug mode. (We can print 130 // services. This is used only for debugging in debug mode. (We can print
128 // pretty graphs with GraphViz with this information.) 131 // pretty graphs with GraphViz with this information.)
129 const char* service_name_; 132 const char* service_name_;
130 #endif 133 #endif
131 }; 134 };
132 135
133 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_F ACTORY_H_ 136 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_BASE_F ACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698