| OLD | NEW |
| 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(); |
| 43 | 48 |
| 44 // The main public interface for declaring dependencies between services | 49 // The main public interface for declaring dependencies between services |
| 45 // created by factories. | 50 // created by factories. |
| 46 void DependsOn(ProfileKeyedBaseFactory* rhs); | 51 void DependsOn(ProfileKeyedBaseFactory* rhs); |
| 47 | 52 |
| 48 // Finds which profile (if any) to use using the Service.*Incognito methods. | 53 // Finds which profile (if any) to use using the Service.*Incognito methods. |
| 49 Profile* GetProfileToUse(Profile* profile); | 54 content::BrowserContext* GetProfileToUse(content::BrowserContext* profile); |
| 50 | 55 |
| 51 // Interface for people building a concrete FooServiceFactory: -------------- | 56 // Interface for people building a concrete FooServiceFactory: -------------- |
| 52 | 57 |
| 53 // Register any user preferences on this service. This is called during | 58 // Register any user preferences on this service. This is called during |
| 54 // CreateProfileService() since preferences are registered on a per Profile | 59 // CreateProfileService() since preferences are registered on a per Profile |
| 55 // basis. | 60 // basis. |
| 56 virtual void RegisterUserPrefs(PrefRegistrySyncable* registry) {} | 61 virtual void RegisterUserPrefs(PrefRegistrySyncable* registry) {} |
| 57 | 62 |
| 58 // By default, if we are asked for a service with an Incognito profile, we | 63 // By default, if we are asked for a service with an Incognito profile, we |
| 59 // pass back NULL. To redirect to the Incognito's original profile or to | 64 // pass back NULL. To redirect to the Incognito's original profile or to |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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_ |
| OLD | NEW |