Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_cloud_policy_manager_factory_chromeos.h
blobd746067891ac1cec0085bfd2b3f0c0efc4adb324
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/browser_context_keyed_service/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 // BrowserContextKeyedServices 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 BrowserContextKeyedService.
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 DefaultSingletonTraits<UserCloudPolicyManagerFactoryChromeOS>;
67 UserCloudPolicyManagerFactoryChromeOS();
68 virtual ~UserCloudPolicyManagerFactoryChromeOS();
70 // See comments for the static versions above.
71 UserCloudPolicyManagerChromeOS* GetManagerForProfile(Profile* profile);
72 scoped_ptr<UserCloudPolicyManagerChromeOS> CreateManagerForProfile(
73 Profile* profile,
74 bool force_immediate_load,
75 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
77 // BrowserContextKeyedBaseFactory:
78 virtual void BrowserContextShutdown(
79 content::BrowserContext* context) OVERRIDE;
80 virtual void BrowserContextDestroyed(
81 content::BrowserContext* context) OVERRIDE;
82 virtual void SetEmptyTestingFactory(
83 content::BrowserContext* context) OVERRIDE;
84 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
86 typedef std::map<Profile*, UserCloudPolicyManagerChromeOS*> ManagerMap;
87 ManagerMap managers_;
89 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS);
92 } // namespace policy
94 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEOS_H_