| 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_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO
S_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEO
S_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 UserCloudPolicyManagerChromeOS; | |
| 29 | |
| 30 // BrowserContextKeyedBaseFactory implementation | |
| 31 // for UserCloudPolicyManagerChromeOS instances that initialize per-profile | |
| 32 // cloud policy settings on ChromeOS. | |
| 33 // | |
| 34 // UserCloudPolicyManagerChromeOS is handled different than other | |
| 35 // KeyedServices because it is a dependency of PrefService. | |
| 36 // Therefore, lifetime of instances is managed by Profile, Profile startup code | |
| 37 // invokes CreateForProfile() explicitly, takes ownership, and the instance | |
| 38 // is only deleted after PrefService destruction. | |
| 39 // | |
| 40 // TODO(mnissler): Remove the special lifetime management in favor of | |
| 41 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the | |
| 42 // former has been converted to a KeyedService. | |
| 43 // See also http://crbug.com/131843 and http://crbug.com/131844. | |
| 44 class UserCloudPolicyManagerFactoryChromeOS | |
| 45 : public BrowserContextKeyedBaseFactory { | |
| 46 public: | |
| 47 // Returns an instance of the UserCloudPolicyManagerFactoryChromeOS singleton. | |
| 48 static UserCloudPolicyManagerFactoryChromeOS* GetInstance(); | |
| 49 | |
| 50 // Returns the UserCloudPolicyManagerChromeOS instance associated with | |
| 51 // |profile|. | |
| 52 static UserCloudPolicyManagerChromeOS* GetForProfile(Profile* profile); | |
| 53 | |
| 54 // Creates an instance for |profile|. Note that the caller is responsible for | |
| 55 // managing the lifetime of the instance. Subsequent calls to GetForProfile() | |
| 56 // will return the created instance as long as it lives. | |
| 57 // | |
| 58 // If |force_immediate_load| is true, policy is loaded synchronously from | |
| 59 // UserCloudPolicyStore at startup. | |
| 60 static std::unique_ptr<UserCloudPolicyManagerChromeOS> CreateForProfile( | |
| 61 Profile* profile, | |
| 62 bool force_immediate_load, | |
| 63 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | |
| 64 | |
| 65 private: | |
| 66 friend struct base::DefaultSingletonTraits< | |
| 67 UserCloudPolicyManagerFactoryChromeOS>; | |
| 68 | |
| 69 UserCloudPolicyManagerFactoryChromeOS(); | |
| 70 ~UserCloudPolicyManagerFactoryChromeOS() override; | |
| 71 | |
| 72 // See comments for the static versions above. | |
| 73 UserCloudPolicyManagerChromeOS* GetManagerForProfile(Profile* profile); | |
| 74 std::unique_ptr<UserCloudPolicyManagerChromeOS> CreateManagerForProfile( | |
| 75 Profile* profile, | |
| 76 bool force_immediate_load, | |
| 77 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | |
| 78 | |
| 79 // BrowserContextKeyedBaseFactory: | |
| 80 void BrowserContextShutdown(content::BrowserContext* context) override; | |
| 81 void BrowserContextDestroyed(content::BrowserContext* context) override; | |
| 82 void SetEmptyTestingFactory(content::BrowserContext* context) override; | |
| 83 bool HasTestingFactory(content::BrowserContext* context) override; | |
| 84 void CreateServiceNow(content::BrowserContext* context) override; | |
| 85 | |
| 86 typedef std::map<Profile*, UserCloudPolicyManagerChromeOS*> ManagerMap; | |
| 87 ManagerMap managers_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS); | |
| 90 }; | |
| 91 | |
| 92 } // namespace policy | |
| 93 | |
| 94 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHRO
MEOS_H_ | |
| OLD | NEW |