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

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

Issue 10908088: Cleanup: Constify some ProfileKeyedBaseFactory methods and all overrides. Remove ProfileKeyedBaseFa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase, remove a few more lines of code Created 8 years, 3 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 <map>
9 #include <set> 8 #include <set>
10 9
11 #include "base/threading/non_thread_safe.h" 10 #include "base/threading/non_thread_safe.h"
12 11
13 class PrefService; 12 class PrefService;
14 class Profile; 13 class Profile;
15 class ProfileDependencyManager; 14 class ProfileDependencyManager;
16 15
17 // Base class for Factories that take a Profile object and return some service. 16 // Base class for Factories that take a Profile object and return some service.
18 // 17 //
19 // Unless you're trying to make a new type of Factory, you probably don't want 18 // Unless you're trying to make a new type of Factory, you probably don't want
20 // this class, but its subclasses: ProfileKeyedServiceFactory and 19 // this class, but its subclasses: ProfileKeyedServiceFactory and
21 // RefcountedProfileKeyedServiceFactory. This object describes general 20 // RefcountedProfileKeyedServiceFactory. This object describes general
22 // dependency management between Factories; subclasses react to lifecycle 21 // dependency management between Factories; subclasses react to lifecycle
23 // events and implement memory management. 22 // events and implement memory management.
24 class ProfileKeyedBaseFactory : public base::NonThreadSafe { 23 class ProfileKeyedBaseFactory : public base::NonThreadSafe {
25 public: 24 public:
26 // Registers preferences used in this service on the pref service of 25 // Registers preferences used in this service on the pref service of
27 // |profile|. This is the public interface and is safe to be called multiple 26 // |profile|. This is the public interface and is safe to be called multiple
28 // times because testing code can have multiple services of the same type 27 // times because testing code can have multiple services of the same type
29 // attached to a single |profile|. 28 // attached to a single |profile|.
30 void RegisterUserPrefsOnProfile(Profile* profile); 29 void RegisterUserPrefsOnProfile(Profile* profile);
31 30
32 // Some unit tests don't run with a Profile, or switch out PrefServices and
33 // require reregistration. They should do neither of those things, but there
34 // are too many of them to go fix.
35 //
36 // DO NOT USE THIS IN REAL CODE.
37 void ForceRegisterPrefsForTest(PrefService* prefs);
38
39 #ifndef NDEBUG 31 #ifndef NDEBUG
40 // Returns our name. We don't keep track of this in release mode. 32 // Returns our name. We don't keep track of this in release mode.
41 const char* name() const { return service_name_; } 33 const char* name() const { return service_name_; }
42 #endif 34 #endif
43 35
44 protected: 36 protected:
45 ProfileKeyedBaseFactory(const char* name, 37 ProfileKeyedBaseFactory(const char* name,
46 ProfileDependencyManager* manager); 38 ProfileDependencyManager* manager);
47 virtual ~ProfileKeyedBaseFactory(); 39 virtual ~ProfileKeyedBaseFactory();
48 40
49 // The main public interface for declaring dependencies between services 41 // The main public interface for declaring dependencies between services
50 // created by factories. 42 // created by factories.
51 void DependsOn(ProfileKeyedBaseFactory* rhs); 43 void DependsOn(ProfileKeyedBaseFactory* rhs);
52 44
53 // Finds which profile (if any) to use using the Service.*Incognito methods. 45 // Finds which profile (if any) to use using the Service.*Incognito methods.
54 Profile* GetProfileToUse(Profile* profile); 46 Profile* GetProfileToUse(Profile* profile);
55 47
56 // Interface for people building a concrete FooServiceFactory: -------------- 48 // Interface for people building a concrete FooServiceFactory: --------------
57 49
58 // Register any user preferences on this service. This is called during 50 // Register any user preferences on this service. This is called during
59 // CreateProfileService() since preferences are registered on a per Profile 51 // CreateProfileService() since preferences are registered on a per Profile
60 // basis. 52 // basis.
61 virtual void RegisterUserPrefs(PrefService* user_prefs) {} 53 virtual void RegisterUserPrefs(PrefService* user_prefs) {}
62 54
63 // By default, if we are asked for a service with an Incognito profile, we 55 // By default, if we are asked for a service with an Incognito profile, we
64 // pass back NULL. To redirect to the Incognito's original profile or to 56 // pass back NULL. To redirect to the Incognito's original profile or to
65 // create another instance, even for Incognito windows, override one of the 57 // create another instance, even for Incognito windows, override one of the
66 // following methods: 58 // following methods:
67 virtual bool ServiceRedirectedInIncognito(); 59 virtual bool ServiceRedirectedInIncognito() const;
68 virtual bool ServiceHasOwnInstanceInIncognito(); 60 virtual bool ServiceHasOwnInstanceInIncognito() const;
69 61
70 // By default, we create instances of a service lazily and wait until 62 // By default, we create instances of a service lazily and wait until
71 // GetForProfile() is called on our subclass. Some services need to be 63 // GetForProfile() is called on our subclass. Some services need to be
72 // created as soon as the Profile has been brought up. 64 // created as soon as the Profile has been brought up.
73 virtual bool ServiceIsCreatedWithProfile(); 65 virtual bool ServiceIsCreatedWithProfile() const;
74 66
75 // By default, TestingProfiles will be treated like normal profiles. You can 67 // By default, TestingProfiles will be treated like normal profiles. You can
76 // override this so that by default, the service associated with the 68 // override this so that by default, the service associated with the
77 // TestingProfile is NULL. (This is just a shortcut around 69 // TestingProfile is NULL. (This is just a shortcut around
78 // SetTestingFactory() to make sure our profiles don't directly refer to the 70 // SetTestingFactory() to make sure our profiles don't directly refer to the
79 // services they use.) 71 // services they use.)
80 virtual bool ServiceIsNULLWhileTesting(); 72 virtual bool ServiceIsNULLWhileTesting() const;
81 73
82 // Interface for people building a type of ProfileKeyedFactory: ------------- 74 // Interface for people building a type of ProfileKeyedFactory: -------------
83 75
84 // A helper object actually listens for notifications about Profile 76 // A helper object actually listens for notifications about Profile
85 // destruction, calculates the order in which things are destroyed and then 77 // destruction, calculates the order in which things are destroyed and then
86 // does a two pass shutdown. 78 // does a two pass shutdown.
87 // 79 //
88 // It is up to the individual factory types to determine what this two pass 80 // It is up to the individual factory types to determine what this two pass
89 // shutdown means. The general framework guarantees the following: 81 // shutdown means. The general framework guarantees the following:
90 // 82 //
91 // - Each ProfileShutdown() is called in dependency order (and you may reach 83 // - Each ProfileShutdown() is called in dependency order (and you may reach
92 // out to other services during this phase). 84 // out to other services during this phase).
93 // 85 //
94 // - Each ProfileDestroyed() is called in dependency order. We will 86 // - Each ProfileDestroyed() is called in dependency order. We will
95 // NOTREACHED() if you attempt to GetForProfile() any other service. You 87 // NOTREACHED() if you attempt to GetForProfile() any other service. You
96 // should delete/deref/do other final memory management things during this 88 // should delete/deref/do other final memory management things during this
97 // phase. You must also call the base class method as the last thing you 89 // phase. You must also call the base class method as the last thing you
98 // do. 90 // do.
99 virtual void ProfileShutdown(Profile* profile) = 0; 91 virtual void ProfileShutdown(Profile* profile) = 0;
100 virtual void ProfileDestroyed(Profile* profile); 92 virtual void ProfileDestroyed(Profile* profile);
101 93
102 protected:
103 // Returns whether we've registered the preferences on this profile. 94 // Returns whether we've registered the preferences on this profile.
104 bool ArePreferencesSetOn(Profile* profile); 95 bool ArePreferencesSetOn(Profile* profile) const;
105 96
106 // Mark profile as Preferences set. 97 // Mark profile as Preferences set.
107 void MarkPreferencesSetOn(Profile* profile); 98 void MarkPreferencesSetOn(Profile* profile);
108 99
109 private: 100 private:
110 friend class ProfileDependencyManager; 101 friend class ProfileDependencyManager;
111 friend class ProfileDependencyManagerUnittests; 102 friend class ProfileDependencyManagerUnittests;
112 103
113 // These two methods are for tight integration with the 104 // These two methods are for tight integration with the
114 // ProfileDependencyManager. 105 // ProfileDependencyManager.
(...skipping 16 matching lines...) Expand all
131 122
132 #if !defined(NDEBUG) 123 #if !defined(NDEBUG)
133 // A static string passed in to our constructor. Should be unique across all 124 // A static string passed in to our constructor. Should be unique across all
134 // services. This is used only for debugging in debug mode. (We can print 125 // services. This is used only for debugging in debug mode. (We can print
135 // pretty graphs with GraphViz with this information.) 126 // pretty graphs with GraphViz with this information.)
136 const char* service_name_; 127 const char* service_name_;
137 #endif 128 #endif
138 }; 129 };
139 130
140 #endif // CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_ 131 #endif // CHROME_BROWSER_PROFILES_PROFILE_KEYED_BASE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698