Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO S_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO S_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO S_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO S_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" | 14 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class BrowserContext; | 23 class BrowserContext; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace policy { | 26 namespace policy { |
| 27 | 27 |
| 28 class ConfigurationPolicyProvider; | |
| 29 class UserActiveDirectoryPolicyManager; | |
| 28 class UserCloudPolicyManagerChromeOS; | 30 class UserCloudPolicyManagerChromeOS; |
| 29 | 31 |
| 30 // BrowserContextKeyedBaseFactory implementation | 32 // BrowserContextKeyedBaseFactory implementation |
| 31 // for UserCloudPolicyManagerChromeOS instances that initialize per-profile | 33 // for UserCloudPolicyManagerChromeOS instances that initialize per-profile |
| 32 // cloud policy settings on ChromeOS. | 34 // cloud policy settings on Chrome OS. |
| 33 // | 35 // |
| 34 // UserCloudPolicyManagerChromeOS is handled different than other | 36 // UserCloudPolicyManagerChromeOS is handled different than other |
| 35 // KeyedServices because it is a dependency of PrefService. | 37 // KeyedServices because it is a dependency of PrefService. |
| 36 // Therefore, lifetime of instances is managed by Profile, Profile startup code | 38 // Therefore, lifetime of instances is managed by Profile, Profile startup code |
| 37 // invokes CreateForProfile() explicitly, takes ownership, and the instance | 39 // invokes CreateForProfile() explicitly, takes ownership, and the instance |
| 38 // is only deleted after PrefService destruction. | 40 // is only deleted after PrefService destruction. |
| 39 // | 41 // |
| 40 // TODO(mnissler): Remove the special lifetime management in favor of | 42 // TODO(mnissler): Remove the special lifetime management in favor of |
| 41 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the | 43 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the |
| 42 // former has been converted to a KeyedService. | 44 // former has been converted to a KeyedService. |
| 43 // See also http://crbug.com/131843 and http://crbug.com/131844. | 45 // See also http://crbug.com/131843 and http://crbug.com/131844. |
| 46 | |
| 47 // TODO(tnagel): Rename to make clear that the factory also provides AD | |
|
emaxx
2016/12/28 19:09:19
Don't you want to do the renaming straight away?
Thiemo Nagel
2016/12/29 15:08:27
Done. (As discussed offline.)
| |
| 48 // managers. | |
| 44 class UserCloudPolicyManagerFactoryChromeOS | 49 class UserCloudPolicyManagerFactoryChromeOS |
| 45 : public BrowserContextKeyedBaseFactory { | 50 : public BrowserContextKeyedBaseFactory { |
| 46 public: | 51 public: |
| 47 // Returns an instance of the UserCloudPolicyManagerFactoryChromeOS singleton. | 52 // Returns an instance of the UserCloudPolicyManagerFactoryChromeOS singleton. |
| 48 static UserCloudPolicyManagerFactoryChromeOS* GetInstance(); | 53 static UserCloudPolicyManagerFactoryChromeOS* GetInstance(); |
| 49 | 54 |
| 55 // Get the ConfigurationPolicyProvider instance associated with | |
| 56 // |profile|. Depending on the type of management either a | |
|
emaxx
2016/12/28 19:09:19
nit: s/management either/management, either/
Thiemo Nagel
2016/12/29 15:08:27
Done.
| |
| 57 // UserCloudPolicyManagerChromeOS or a UserActiveDirectoryPolicyManager or a | |
|
emaxx
2016/12/28 19:09:19
nit: s/a nullptr/nullptr/
Thiemo Nagel
2016/12/29 15:08:27
Done.
| |
| 58 // nullptr is returned. | |
| 59 static ConfigurationPolicyProvider* GetForProfile(Profile* profile); | |
| 60 | |
| 50 // Returns the UserCloudPolicyManagerChromeOS instance associated with | 61 // Returns the UserCloudPolicyManagerChromeOS instance associated with |
| 51 // |profile|. | 62 // |profile| or nullptr in case there is none. |
| 52 static UserCloudPolicyManagerChromeOS* GetForProfile(Profile* profile); | 63 static UserCloudPolicyManagerChromeOS* GetCloudPolicyManagerForProfile( |
| 64 Profile* profile); | |
| 65 | |
| 66 // Returns the UserActiveDirectoryPolicyManager instance associated with | |
| 67 // |profile| or nullptr in case there is none. | |
| 68 static UserActiveDirectoryPolicyManager* | |
| 69 GetActiveDirectoryPolicyManagerForProfile(Profile* profile); | |
| 53 | 70 |
| 54 // Creates an instance for |profile|. Note that the caller is responsible for | 71 // Creates an instance for |profile|. Note that the caller is responsible for |
| 55 // managing the lifetime of the instance. Subsequent calls to GetForProfile() | 72 // managing the lifetime of the instance. Subsequent calls to GetForProfile() |
| 56 // will return the created instance as long as it lives. | 73 // will return the created instance as long as it lives. |
| 57 // | 74 // |
| 58 // If |force_immediate_load| is true, policy is loaded synchronously from | 75 // If |force_immediate_load| is true, policy is loaded synchronously from |
| 59 // UserCloudPolicyStore at startup. | 76 // UserCloudPolicyStore at startup. |
| 60 static std::unique_ptr<UserCloudPolicyManagerChromeOS> CreateForProfile( | 77 static std::unique_ptr<ConfigurationPolicyProvider> CreateForProfile( |
| 61 Profile* profile, | 78 Profile* profile, |
| 62 bool force_immediate_load, | 79 bool force_immediate_load, |
| 63 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | 80 scoped_refptr<base::SequencedTaskRunner> background_task_runner); |
| 64 | 81 |
| 65 private: | 82 private: |
| 66 friend struct base::DefaultSingletonTraits< | 83 friend struct base::DefaultSingletonTraits< |
| 67 UserCloudPolicyManagerFactoryChromeOS>; | 84 UserCloudPolicyManagerFactoryChromeOS>; |
| 68 | 85 |
| 69 UserCloudPolicyManagerFactoryChromeOS(); | 86 UserCloudPolicyManagerFactoryChromeOS(); |
| 70 ~UserCloudPolicyManagerFactoryChromeOS() override; | 87 ~UserCloudPolicyManagerFactoryChromeOS() override; |
| 71 | 88 |
| 72 // See comments for the static versions above. | 89 // See comments for the static versions above. |
| 73 UserCloudPolicyManagerChromeOS* GetManagerForProfile(Profile* profile); | 90 UserCloudPolicyManagerChromeOS* GetCloudPolicyManager(Profile* profile); |
| 74 std::unique_ptr<UserCloudPolicyManagerChromeOS> CreateManagerForProfile( | 91 UserActiveDirectoryPolicyManager* GetActiveDirectoryPolicyManager( |
| 92 Profile* profile); | |
| 93 std::unique_ptr<ConfigurationPolicyProvider> CreateManagerForProfile( | |
| 75 Profile* profile, | 94 Profile* profile, |
| 76 bool force_immediate_load, | 95 bool force_immediate_load, |
| 77 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | 96 scoped_refptr<base::SequencedTaskRunner> background_task_runner); |
| 78 | 97 |
| 79 // BrowserContextKeyedBaseFactory: | 98 // BrowserContextKeyedBaseFactory: |
| 80 void BrowserContextShutdown(content::BrowserContext* context) override; | 99 void BrowserContextShutdown(content::BrowserContext* context) override; |
| 81 void BrowserContextDestroyed(content::BrowserContext* context) override; | 100 void BrowserContextDestroyed(content::BrowserContext* context) override; |
| 82 void SetEmptyTestingFactory(content::BrowserContext* context) override; | 101 void SetEmptyTestingFactory(content::BrowserContext* context) override; |
| 83 bool HasTestingFactory(content::BrowserContext* context) override; | 102 bool HasTestingFactory(content::BrowserContext* context) override; |
| 84 void CreateServiceNow(content::BrowserContext* context) override; | 103 void CreateServiceNow(content::BrowserContext* context) override; |
| 85 | 104 |
| 86 typedef std::map<Profile*, UserCloudPolicyManagerChromeOS*> ManagerMap; | 105 std::map<Profile*, UserCloudPolicyManagerChromeOS*> cloud_managers_; |
| 87 ManagerMap managers_; | 106 std::map<Profile*, UserActiveDirectoryPolicyManager*> |
| 107 active_directory_managers_; | |
| 88 | 108 |
| 89 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS); | 109 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS); |
| 90 }; | 110 }; |
| 91 | 111 |
| 92 } // namespace policy | 112 } // namespace policy |
| 93 | 113 |
| 94 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHRO MEOS_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHRO MEOS_H_ |
| OLD | NEW |