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_
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"
18 class SequencedTaskRunner
;
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
{
46 // Returns an instance of the UserCloudPolicyManagerFactoryChromeOS singleton.
47 static UserCloudPolicyManagerFactoryChromeOS
* GetInstance();
49 // Returns the UserCloudPolicyManagerChromeOS instance associated with
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(
61 bool force_immediate_load
,
62 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
);
65 friend struct DefaultSingletonTraits
<UserCloudPolicyManagerFactoryChromeOS
>;
67 UserCloudPolicyManagerFactoryChromeOS();
68 ~UserCloudPolicyManagerFactoryChromeOS() override
;
70 // See comments for the static versions above.
71 UserCloudPolicyManagerChromeOS
* GetManagerForProfile(Profile
* profile
);
72 scoped_ptr
<UserCloudPolicyManagerChromeOS
> CreateManagerForProfile(
74 bool force_immediate_load
,
75 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
);
77 // BrowserContextKeyedBaseFactory:
78 void BrowserContextShutdown(content::BrowserContext
* context
) override
;
79 void BrowserContextDestroyed(content::BrowserContext
* context
) override
;
80 void SetEmptyTestingFactory(content::BrowserContext
* context
) override
;
81 bool HasTestingFactory(content::BrowserContext
* context
) override
;
82 void CreateServiceNow(content::BrowserContext
* context
) override
;
84 typedef std::map
<Profile
*, UserCloudPolicyManagerChromeOS
*> ManagerMap
;
87 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactoryChromeOS
);
92 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_CHROMEOS_H_