OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | |
6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/singleton.h" | |
12 #include "chrome/browser/profiles/profile_keyed_base_factory.h" | |
13 | |
14 class Profile; | |
15 | |
16 namespace policy { | |
17 | |
18 class UserCloudPolicyManager; | |
19 | |
20 // ProfileKeyedBaseFactory implementation for UserCloudPolicyManager | |
21 // instances that initialize per-profile cloud policy settings on the desktop | |
22 // platforms. | |
23 // | |
24 // UserCloudPolicyManager is handled different than other ProfileKeyedServices | |
25 // because it is a dependency of PrefService. Therefore, lifetime of instances | |
26 // is managed by Profile, Profile startup code invokes CreateForProfile() | |
27 // explicitly, takes ownership, and the instance is only deleted after | |
28 // PrefService destruction. | |
29 // | |
30 // TODO(mnissler): Remove the special lifetime management in favor of | |
31 // PrefService directly depending on UserCloudPolicyManager once the former has | |
32 // been converted to a ProfileKeyedService. See also http://crbug.com/131843 and | |
33 // http://crbug.com/131844. | |
34 class UserCloudPolicyManagerFactory : public ProfileKeyedBaseFactory { | |
35 public: | |
36 // Returns an instance of the UserCloudPolicyManagerFactory singleton. | |
37 static UserCloudPolicyManagerFactory* GetInstance(); | |
38 | |
39 // Returns the UserCloudPolicyManager instance associated with |profile|. | |
40 static UserCloudPolicyManager* GetForProfile(Profile* profile); | |
41 | |
42 // Creates an instance for |profile|. Note that the caller is responsible for | |
43 // managing the lifetime of the instance. Subsequent calls to GetForProfile() | |
44 // will return the created instance as long as it lives. | |
45 // | |
46 // If |force_immediate_load| is true, policy is loaded synchronously from | |
47 // UserCloudPolicyStore at startup. | |
48 static scoped_ptr<UserCloudPolicyManager> CreateForProfile( | |
49 Profile* profile, | |
50 bool force_immediate_load); | |
51 | |
52 private: | |
53 friend class UserCloudPolicyManager; | |
54 friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactory>; | |
55 | |
56 UserCloudPolicyManagerFactory(); | |
57 virtual ~UserCloudPolicyManagerFactory(); | |
58 | |
59 // See comments for the static versions above. | |
60 UserCloudPolicyManager* GetManagerForProfile(Profile* profile); | |
61 scoped_ptr<UserCloudPolicyManager> CreateManagerForProfile( | |
62 Profile* profile, | |
63 bool force_immediate_load); | |
64 | |
65 // ProfileKeyedBaseFactory: | |
66 virtual void ProfileShutdown(Profile* profile) OVERRIDE; | |
67 virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE; | |
68 virtual void CreateServiceNow(Profile* profile) OVERRIDE; | |
69 | |
70 // Invoked by UserCloudPolicyManager to register/unregister instances. | |
71 void Register(Profile* profile, UserCloudPolicyManager* instance); | |
72 void Unregister(Profile* profile, UserCloudPolicyManager* instance); | |
73 | |
74 typedef std::map<Profile*, UserCloudPolicyManager*> ManagerMap; | |
75 ManagerMap managers_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory); | |
78 }; | |
79 | |
80 } // namespace policy | |
81 | |
82 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ | |
OLD | NEW |