| 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_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" | 12 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" |
| 13 | 13 |
| 14 class Profile; | 14 class Profile; |
| 15 | 15 |
| 16 namespace policy { | 16 namespace policy { |
| 17 | 17 |
| 18 class UserCloudPolicyManager; | 18 class UserCloudPolicyManager; |
| 19 | 19 |
| 20 // ProfileKeyedBaseFactory implementation for UserCloudPolicyManager | 20 // BrowserContextKeyedBaseFactory implementation for UserCloudPolicyManager |
| 21 // instances that initialize per-profile cloud policy settings on the desktop | 21 // instances that initialize per-profile cloud policy settings on the desktop |
| 22 // platforms. | 22 // platforms. |
| 23 // | 23 // |
| 24 // UserCloudPolicyManager is handled different than other ProfileKeyedServices | 24 // UserCloudPolicyManager is handled different than other |
| 25 // because it is a dependency of PrefService. Therefore, lifetime of instances | 25 // BrowserContextKeyedServices because it is a dependency of PrefService. |
| 26 // is managed by Profile, Profile startup code invokes CreateForProfile() | 26 // Therefore, lifetime of instances is managed by Profile, Profile startup code |
| 27 // explicitly, takes ownership, and the instance is only deleted after | 27 // invokes CreateForProfile() explicitly, takes ownership, and the instance |
| 28 // PrefService destruction. | 28 // is only deleted after PrefService destruction. |
| 29 // | 29 // |
| 30 // TODO(mnissler): Remove the special lifetime management in favor of | 30 // TODO(mnissler): Remove the special lifetime management in favor of |
| 31 // PrefService directly depending on UserCloudPolicyManager once the former has | 31 // PrefService directly depending on UserCloudPolicyManager once the former has |
| 32 // been converted to a ProfileKeyedService. See also http://crbug.com/131843 and | 32 // been converted to a BrowserContextKeyedService. |
| 33 // http://crbug.com/131844. | 33 // See also http://crbug.com/131843 and http://crbug.com/131844. |
| 34 class UserCloudPolicyManagerFactory : public ProfileKeyedBaseFactory { | 34 class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory { |
| 35 public: | 35 public: |
| 36 // Returns an instance of the UserCloudPolicyManagerFactory singleton. | 36 // Returns an instance of the UserCloudPolicyManagerFactory singleton. |
| 37 static UserCloudPolicyManagerFactory* GetInstance(); | 37 static UserCloudPolicyManagerFactory* GetInstance(); |
| 38 | 38 |
| 39 // Returns the UserCloudPolicyManager instance associated with |profile|. | 39 // Returns the UserCloudPolicyManager instance associated with |profile|. |
| 40 static UserCloudPolicyManager* GetForProfile(Profile* profile); | 40 static UserCloudPolicyManager* GetForProfile(Profile* profile); |
| 41 | 41 |
| 42 // Creates an instance for |profile|. Note that the caller is responsible for | 42 // Creates an instance for |profile|. Note that the caller is responsible for |
| 43 // managing the lifetime of the instance. Subsequent calls to GetForProfile() | 43 // managing the lifetime of the instance. Subsequent calls to GetForProfile() |
| 44 // will return the created instance as long as it lives. | 44 // will return the created instance as long as it lives. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 | 55 |
| 56 UserCloudPolicyManagerFactory(); | 56 UserCloudPolicyManagerFactory(); |
| 57 virtual ~UserCloudPolicyManagerFactory(); | 57 virtual ~UserCloudPolicyManagerFactory(); |
| 58 | 58 |
| 59 // See comments for the static versions above. | 59 // See comments for the static versions above. |
| 60 UserCloudPolicyManager* GetManagerForProfile(Profile* profile); | 60 UserCloudPolicyManager* GetManagerForProfile(Profile* profile); |
| 61 scoped_ptr<UserCloudPolicyManager> CreateManagerForProfile( | 61 scoped_ptr<UserCloudPolicyManager> CreateManagerForProfile( |
| 62 Profile* profile, | 62 Profile* profile, |
| 63 bool force_immediate_load); | 63 bool force_immediate_load); |
| 64 | 64 |
| 65 // ProfileKeyedBaseFactory: | 65 // BrowserContextKeyedBaseFactory: |
| 66 virtual void ProfileShutdown(content::BrowserContext* profile) OVERRIDE; | 66 virtual void BrowserContextShutdown( |
| 67 content::BrowserContext* profile) OVERRIDE; |
| 67 virtual void SetEmptyTestingFactory( | 68 virtual void SetEmptyTestingFactory( |
| 68 content::BrowserContext* profile) OVERRIDE; | 69 content::BrowserContext* profile) OVERRIDE; |
| 69 virtual void CreateServiceNow(content::BrowserContext* profile) OVERRIDE; | 70 virtual void CreateServiceNow(content::BrowserContext* profile) OVERRIDE; |
| 70 | 71 |
| 71 // Invoked by UserCloudPolicyManager to register/unregister instances. | 72 // Invoked by UserCloudPolicyManager to register/unregister instances. |
| 72 void Register(Profile* profile, UserCloudPolicyManager* instance); | 73 void Register(Profile* profile, UserCloudPolicyManager* instance); |
| 73 void Unregister(Profile* profile, UserCloudPolicyManager* instance); | 74 void Unregister(Profile* profile, UserCloudPolicyManager* instance); |
| 74 | 75 |
| 75 typedef std::map<Profile*, UserCloudPolicyManager*> ManagerMap; | 76 typedef std::map<Profile*, UserCloudPolicyManager*> ManagerMap; |
| 76 ManagerMap managers_; | 77 ManagerMap managers_; |
| 77 | 78 |
| 78 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory); | 79 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory); |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 } // namespace policy | 82 } // namespace policy |
| 82 | 83 |
| 83 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | 84 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ |
| OLD | NEW |