| 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_POLICY_MANAGER_FACTORY_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_MANAGER_FACTORY_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_MANAGER_FACTORY_CHROMEOS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_MANAGER_FACTORY_CHROMEOS_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; | 28 class ConfigurationPolicyProvider; |
| 29 class UserActiveDirectoryPolicyManager; | 29 class ActiveDirectoryPolicyManager; |
| 30 class UserCloudPolicyManagerChromeOS; | 30 class UserCloudPolicyManagerChromeOS; |
| 31 | 31 |
| 32 // Shared BrowserContextKeyedBaseFactory implementation for | 32 // Shared BrowserContextKeyedBaseFactory implementation for |
| 33 // UserCloudPolicyManagerChromeOS and | 33 // UserCloudPolicyManagerChromeOS and ActiveDirectoryPolicyManager. |
| 34 // UserActiveDirectoryPolicyManager. | |
| 35 // | 34 // |
| 36 // UserCloudPolicyManagerChromeOS/UserActiveDirectoryPolicyManager is handled | 35 // UserCloudPolicyManagerChromeOS/ActiveDirectoryPolicyManager is handled |
| 37 // differently than other KeyedServices because it is a dependency of | 36 // differently than other KeyedServices because it is a dependency of |
| 38 // PrefService. Therefore, lifetime of instances is managed by Profile, Profile | 37 // PrefService. Therefore, lifetime of instances is managed by Profile, Profile |
| 39 // startup code invokes CreateForProfile() explicitly, takes ownership, and the | 38 // startup code invokes CreateForProfile() explicitly, takes ownership, and the |
| 40 // instance is only deleted after PrefService destruction. | 39 // instance is only deleted after PrefService destruction. |
| 41 // | 40 // |
| 42 // TODO(mnissler): Remove the special lifetime management in favor of | 41 // TODO(mnissler): Remove the special lifetime management in favor of |
| 43 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the | 42 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the |
| 44 // former has been converted to a KeyedService. | 43 // former has been converted to a KeyedService. |
| 45 // See also http://crbug.com/131843 and http://crbug.com/131844. | 44 // See also http://crbug.com/131843 and http://crbug.com/131844. |
| 46 class UserPolicyManagerFactoryChromeOS : public BrowserContextKeyedBaseFactory { | 45 class UserPolicyManagerFactoryChromeOS : public BrowserContextKeyedBaseFactory { |
| 47 public: | 46 public: |
| 48 // Returns an instance of the UserPolicyManagerFactoryChromeOS singleton. | 47 // Returns an instance of the UserPolicyManagerFactoryChromeOS singleton. |
| 49 static UserPolicyManagerFactoryChromeOS* GetInstance(); | 48 static UserPolicyManagerFactoryChromeOS* GetInstance(); |
| 50 | 49 |
| 51 // Get the ConfigurationPolicyProvider instance associated with |profile|. | 50 // Get the ConfigurationPolicyProvider instance associated with |profile|. |
| 52 // Depending on the type of management, either a | 51 // Depending on the type of management, either a |
| 53 // UserCloudPolicyManagerChromeOS or a UserActiveDirectoryPolicyManager or | 52 // UserCloudPolicyManagerChromeOS or an ActiveDirectoryPolicyManager or |
| 54 // nullptr is returned. | 53 // nullptr is returned. |
| 55 static ConfigurationPolicyProvider* GetForProfile(Profile* profile); | 54 static ConfigurationPolicyProvider* GetForProfile(Profile* profile); |
| 56 | 55 |
| 57 // Returns the UserCloudPolicyManagerChromeOS instance associated with | 56 // Returns the UserCloudPolicyManagerChromeOS instance associated with |
| 58 // |profile| or nullptr in case there is none. | 57 // |profile| or nullptr in case there is none. |
| 59 static UserCloudPolicyManagerChromeOS* GetCloudPolicyManagerForProfile( | 58 static UserCloudPolicyManagerChromeOS* GetCloudPolicyManagerForProfile( |
| 60 Profile* profile); | 59 Profile* profile); |
| 61 | 60 |
| 62 // Returns the UserActiveDirectoryPolicyManager instance associated with | 61 // Returns the ActiveDirectoryPolicyManager instance associated with |profile| |
| 63 // |profile| or nullptr in case there is none. | 62 // or nullptr in case there is none. |
| 64 static UserActiveDirectoryPolicyManager* | 63 static ActiveDirectoryPolicyManager* |
| 65 GetActiveDirectoryPolicyManagerForProfile(Profile* profile); | 64 GetActiveDirectoryPolicyManagerForProfile(Profile* profile); |
| 66 | 65 |
| 67 // Creates an instance for |profile|. Note that the caller is responsible for | 66 // Creates an instance for |profile|. Note that the caller is responsible for |
| 68 // managing the lifetime of the instance. Subsequent calls to GetForProfile() | 67 // managing the lifetime of the instance. Subsequent calls to GetForProfile() |
| 69 // will return the created instance as long as it lives. | 68 // will return the created instance as long as it lives. |
| 70 // | 69 // |
| 71 // If |force_immediate_load| is true, policy is loaded synchronously from | 70 // If |force_immediate_load| is true, policy is loaded synchronously from |
| 72 // UserCloudPolicyStore at startup. | 71 // UserCloudPolicyStore at startup. |
| 73 static std::unique_ptr<ConfigurationPolicyProvider> CreateForProfile( | 72 static std::unique_ptr<ConfigurationPolicyProvider> CreateForProfile( |
| 74 Profile* profile, | 73 Profile* profile, |
| 75 bool force_immediate_load, | 74 bool force_immediate_load, |
| 76 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | 75 scoped_refptr<base::SequencedTaskRunner> background_task_runner); |
| 77 | 76 |
| 78 private: | 77 private: |
| 79 friend struct base::DefaultSingletonTraits<UserPolicyManagerFactoryChromeOS>; | 78 friend struct base::DefaultSingletonTraits<UserPolicyManagerFactoryChromeOS>; |
| 80 | 79 |
| 81 UserPolicyManagerFactoryChromeOS(); | 80 UserPolicyManagerFactoryChromeOS(); |
| 82 ~UserPolicyManagerFactoryChromeOS() override; | 81 ~UserPolicyManagerFactoryChromeOS() override; |
| 83 | 82 |
| 84 // See comments for the static versions above. | 83 // See comments for the static versions above. |
| 85 UserCloudPolicyManagerChromeOS* GetCloudPolicyManager(Profile* profile); | 84 UserCloudPolicyManagerChromeOS* GetCloudPolicyManager(Profile* profile); |
| 86 UserActiveDirectoryPolicyManager* GetActiveDirectoryPolicyManager( | 85 ActiveDirectoryPolicyManager* GetActiveDirectoryPolicyManager( |
| 87 Profile* profile); | 86 Profile* profile); |
| 88 std::unique_ptr<ConfigurationPolicyProvider> CreateManagerForProfile( | 87 std::unique_ptr<ConfigurationPolicyProvider> CreateManagerForProfile( |
| 89 Profile* profile, | 88 Profile* profile, |
| 90 bool force_immediate_load, | 89 bool force_immediate_load, |
| 91 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | 90 scoped_refptr<base::SequencedTaskRunner> background_task_runner); |
| 92 | 91 |
| 93 // BrowserContextKeyedBaseFactory: | 92 // BrowserContextKeyedBaseFactory: |
| 94 void BrowserContextShutdown(content::BrowserContext* context) override; | 93 void BrowserContextShutdown(content::BrowserContext* context) override; |
| 95 void BrowserContextDestroyed(content::BrowserContext* context) override; | 94 void BrowserContextDestroyed(content::BrowserContext* context) override; |
| 96 void SetEmptyTestingFactory(content::BrowserContext* context) override; | 95 void SetEmptyTestingFactory(content::BrowserContext* context) override; |
| 97 bool HasTestingFactory(content::BrowserContext* context) override; | 96 bool HasTestingFactory(content::BrowserContext* context) override; |
| 98 void CreateServiceNow(content::BrowserContext* context) override; | 97 void CreateServiceNow(content::BrowserContext* context) override; |
| 99 | 98 |
| 100 std::map<Profile*, UserCloudPolicyManagerChromeOS*> cloud_managers_; | 99 std::map<Profile*, UserCloudPolicyManagerChromeOS*> cloud_managers_; |
| 101 std::map<Profile*, UserActiveDirectoryPolicyManager*> | 100 std::map<Profile*, ActiveDirectoryPolicyManager*> active_directory_managers_; |
| 102 active_directory_managers_; | |
| 103 | 101 |
| 104 DISALLOW_COPY_AND_ASSIGN(UserPolicyManagerFactoryChromeOS); | 102 DISALLOW_COPY_AND_ASSIGN(UserPolicyManagerFactoryChromeOS); |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 } // namespace policy | 105 } // namespace policy |
| 108 | 106 |
| 109 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_MANAGER_FACTORY_CHROMEOS_H
_ | 107 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_MANAGER_FACTORY_CHROMEOS_H
_ |
| OLD | NEW |