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