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

Side by Side Diff: chrome/browser/profiles/profile_keyed_base_factory.h

Issue 14141006: [components] Switch {RefCounted}ProfileKeyedService to use BrowserContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_ 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_ 6 #define CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_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 "chrome/browser/profiles/dependency_node.h" 11 #include "chrome/browser/profiles/dependency_node.h"
12 12
13 namespace content {
14 class BrowserContext;
15 };
16
13 class PrefRegistrySyncable; 17 class PrefRegistrySyncable;
14 class PrefService; 18 class PrefService;
19 class ProfileDependencyManager;
20
15 class Profile; 21 class Profile;
16 class ProfileDependencyManager;
17 22
18 // Base class for Factories that take a Profile object and return some service. 23 // Base class for Factories that take a Profile object and return some service.
19 // 24 //
20 // Unless you're trying to make a new type of Factory, you probably don't want 25 // Unless you're trying to make a new type of Factory, you probably don't want
21 // this class, but its subclasses: ProfileKeyedServiceFactory and 26 // this class, but its subclasses: ProfileKeyedServiceFactory and
22 // RefcountedProfileKeyedServiceFactory. This object describes general 27 // RefcountedProfileKeyedServiceFactory. This object describes general
23 // dependency management between Factories; subclasses react to lifecycle 28 // dependency management between Factories; subclasses react to lifecycle
24 // events and implement memory management. 29 // events and implement memory management.
25 class ProfileKeyedBaseFactory : public base::NonThreadSafe, 30 class ProfileKeyedBaseFactory : public base::NonThreadSafe,
26 public DependencyNode { 31 public DependencyNode {
27 public: 32 public:
28 // Registers preferences used in this service on the pref service of 33 // Registers preferences used in this service on the pref service of
29 // |profile|. This is the public interface and is safe to be called multiple 34 // |profile|. This is the public interface and is safe to be called multiple
30 // times because testing code can have multiple services of the same type 35 // times because testing code can have multiple services of the same type
31 // attached to a single |profile|. 36 // attached to a single |profile|.
32 void RegisterUserPrefsOnProfile(Profile* profile); 37 void RegisterUserPrefsOnProfile(content::BrowserContext* profile);
33 38
34 #ifndef NDEBUG 39 #ifndef NDEBUG
35 // Returns our name. We don't keep track of this in release mode. 40 // Returns our name. We don't keep track of this in release mode.
36 const char* name() const { return service_name_; } 41 const char* name() const { return service_name_; }
37 #endif 42 #endif
38 43
39 protected: 44 protected:
40 ProfileKeyedBaseFactory(const char* name, 45 ProfileKeyedBaseFactory(const char* name,
41 ProfileDependencyManager* manager); 46 ProfileDependencyManager* manager);
42 virtual ~ProfileKeyedBaseFactory(); 47 virtual ~ProfileKeyedBaseFactory();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // shutdown means. The general framework guarantees the following: 89 // shutdown means. The general framework guarantees the following:
85 // 90 //
86 // - Each ProfileShutdown() is called in dependency order (and you may reach 91 // - Each ProfileShutdown() is called in dependency order (and you may reach
87 // out to other services during this phase). 92 // out to other services during this phase).
88 // 93 //
89 // - Each ProfileDestroyed() is called in dependency order. We will 94 // - Each ProfileDestroyed() is called in dependency order. We will
90 // NOTREACHED() if you attempt to GetForProfile() any other service. You 95 // NOTREACHED() if you attempt to GetForProfile() any other service. You
91 // should delete/deref/do other final memory management things during this 96 // should delete/deref/do other final memory management things during this
92 // phase. You must also call the base class method as the last thing you 97 // phase. You must also call the base class method as the last thing you
93 // do. 98 // do.
94 virtual void ProfileShutdown(Profile* profile) = 0; 99 virtual void ProfileShutdown(content::BrowserContext* profile) = 0;
95 virtual void ProfileDestroyed(Profile* profile); 100 virtual void ProfileDestroyed(content::BrowserContext* profile);
96 101
97 // Returns whether we've registered the preferences on this profile. 102 // Returns whether we've registered the preferences on this profile.
98 bool ArePreferencesSetOn(Profile* profile) const; 103 bool ArePreferencesSetOn(content::BrowserContext* profile) const;
99 104
100 // Mark profile as Preferences set. 105 // Mark profile as Preferences set.
101 void MarkPreferencesSetOn(Profile* profile); 106 void MarkPreferencesSetOn(content::BrowserContext* profile);
102 107
103 private: 108 private:
104 friend class ProfileDependencyManager; 109 friend class ProfileDependencyManager;
105 friend class ProfileDependencyManagerUnittests; 110 friend class ProfileDependencyManagerUnittests;
106 111
107 // These two methods are for tight integration with the 112 // These two methods are for tight integration with the
108 // ProfileDependencyManager. 113 // ProfileDependencyManager.
109 114
110 // Because of ServiceIsNULLWhileTesting(), we need a way to tell different 115 // Because of ServiceIsNULLWhileTesting(), we need a way to tell different
111 // subclasses that they should disable testing. 116 // subclasses that they should disable testing.
112 virtual void SetEmptyTestingFactory(Profile* profile) = 0; 117 virtual void SetEmptyTestingFactory(content::BrowserContext* profile) = 0;
113 118
114 // We also need a generalized, non-returning method that generates the object 119 // We also need a generalized, non-returning method that generates the object
115 // now for when we're creating the profile. 120 // now for when we're creating the profile.
116 virtual void CreateServiceNow(Profile* profile) = 0; 121 virtual void CreateServiceNow(content::BrowserContext* profile) = 0;
117 122
118 // Which ProfileDependencyManager we should communicate with. In real code, 123 // Which ProfileDependencyManager we should communicate with. In real code,
119 // this will always be ProfileDependencyManager::GetInstance(), but unit 124 // this will always be ProfileDependencyManager::GetInstance(), but unit
120 // tests will want to use their own copy. 125 // tests will want to use their own copy.
121 ProfileDependencyManager* dependency_manager_; 126 ProfileDependencyManager* dependency_manager_;
122 127
123 // Profiles that have this service's preferences registered on them. 128 // Profiles that have this service's preferences registered on them.
124 std::set<Profile*> registered_preferences_; 129 std::set<content::BrowserContext*> registered_preferences_;
125 130
126 #if !defined(NDEBUG) 131 #if !defined(NDEBUG)
127 // A static string passed in to our constructor. Should be unique across all 132 // A static string passed in to our constructor. Should be unique across all
128 // services. This is used only for debugging in debug mode. (We can print 133 // services. This is used only for debugging in debug mode. (We can print
129 // pretty graphs with GraphViz with this information.) 134 // pretty graphs with GraphViz with this information.)
130 const char* service_name_; 135 const char* service_name_;
131 #endif 136 #endif
132 }; 137 };
133 138
134 #endif // CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_ 139 #endif // CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698