Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_cloud_policy_manager_factory_chromeos.h
blobd018515fd19f6088cc6dce2632e3dcdc867d1f8e
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEOS_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/singleton.h"
13 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
15 class Profile;
17 namespace base {
18 class SequencedTaskRunner;
21 namespace content {
22 class BrowserContext;
25 namespace policy {
27 class UserCloudPolicyManagerChromeOS;
29 // BrowserContextKeyedBaseFactory implementation
30 // for UserCloudPolicyManagerChromeOS instances that initialize per-profile
31 // cloud policy settings on ChromeOS.
33 // UserCloudPolicyManagerChromeOS is handled different than other
34 // KeyedServices because it is a dependency of PrefService.
35 // Therefore, lifetime of instances is managed by Profile, Profile startup code
36 // invokes CreateForProfile() explicitly, takes ownership, and the instance
37 // is only deleted after PrefService destruction.
39 // TODO(mnissler): Remove the special lifetime management in favor of
40 // PrefService directly depending on UserCloudPolicyManagerChromeOS once the
41 // former has been converted to a KeyedService.
42 // See also http://crbug.com/131843 and http://crbug.com/131844.
43 class UserCloudPolicyManagerFactoryChromeOS
44 : public BrowserContextKeyedBaseFactory {
45 public:
46 // Returns an instance of the UserCloudPolicyManagerFactoryChromeOS singleton.
47 static UserCloudPolicyManagerFactoryChromeOS* GetInstance();
49 // Returns the UserCloudPolicyManagerChromeOS instance associated with
50 // |profile|.
51 static UserCloudPolicyManagerChromeOS* GetForProfile(Profile* profile);
53 // Creates an instance for |profile|. Note that the caller is responsible for
54 // managing the lifetime of the instance. Subsequent calls to GetForProfile()
55 // will return the created instance as long as it lives.
57 // If |force_immediate_load| is true, policy is loaded synchronously from
58 // UserCloudPolicyStore at startup.
59 static scoped_ptr<UserCloudPolicyManagerChromeOS> CreateForProfile(
60 Profile* profile,
61 bool force_immediate_load,
62 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
64 private:
65 friend struct base::DefaultSingletonTraits<
66 UserCloudPolicyManagerFactoryChromeOS>;
68 UserCloudPolicyManagerFactoryChromeOS();
69 ~UserCloudPolicyManagerFactoryChromeOS() override;
71 // See comments for the static versions above.
72 UserCloudPolicyManagerChromeOS* GetManagerForProfile(Profile* profile);
73 scoped_ptr<UserCloudPolicyManagerChromeOS> CreateManagerForProfile(
74 Profile* profile,
75 bool force_immediate_load,
76 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
78 // BrowserContextKeyedBaseFactory:
79 void BrowserContextShutdown(content::BrowserContext* context) override;
80 void BrowserContextDestroyed(content::BrowserContext* context) override;
81 void SetEmptyTestingFactory(content::BrowserContext* context) override;
82 bool HasTestingFactory(content::BrowserContext* context) override;
83 void CreateServiceNow(content::BrowserContext* context) override;
85 typedef std::map<Profile*, UserCloudPolicyManagerChromeOS*> ManagerMap;
86 ManagerMap managers_;
88 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS);
91 } // namespace policy
93 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEOS_H_