Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h

Issue 44083005: policy: Remove UserCloudPolicyManagerFactory's dependency on Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa ctory.h" 13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa ctory.h"
14 14
15 class Profile;
16
17 namespace base { 15 namespace base {
18 class SequencedTaskRunner; 16 class SequencedTaskRunner;
19 } 17 }
20 18
21 namespace content { 19 namespace content {
22 class BrowserContext; 20 class BrowserContext;
23 } 21 }
24 22
25 namespace policy { 23 namespace policy {
26 24
27 class UserCloudPolicyManager; 25 class UserCloudPolicyManager;
28 26
29 // BrowserContextKeyedBaseFactory implementation for UserCloudPolicyManager 27 // BrowserContextKeyedBaseFactory implementation for UserCloudPolicyManager
30 // instances that initialize per-profile cloud policy settings on the desktop 28 // instances that initialize per-profile cloud policy settings on the desktop
31 // platforms. 29 // platforms.
32 // 30 //
33 // UserCloudPolicyManager is handled different than other 31 // UserCloudPolicyManager is handled different than other
34 // BrowserContextKeyedServices because it is a dependency of PrefService. 32 // BrowserContextKeyedServices because it is a dependency of PrefService.
35 // Therefore, lifetime of instances is managed by Profile, Profile startup code 33 // Therefore, lifetime of instances is managed by Profile, Profile startup code
36 // invokes CreateForProfile() explicitly, takes ownership, and the instance 34 // invokes CreateForBrowserContext() explicitly, takes ownership, and the
37 // is only deleted after PrefService destruction. 35 // instance is only deleted after PrefService destruction.
38 // 36 //
39 // TODO(mnissler): Remove the special lifetime management in favor of 37 // TODO(mnissler): Remove the special lifetime management in favor of
40 // PrefService directly depending on UserCloudPolicyManager once the former has 38 // PrefService directly depending on UserCloudPolicyManager once the former has
41 // been converted to a BrowserContextKeyedService. 39 // been converted to a BrowserContextKeyedService.
42 // See also http://crbug.com/131843 and http://crbug.com/131844. 40 // See also http://crbug.com/131843 and http://crbug.com/131844.
43 class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory { 41 class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory {
44 public: 42 public:
45 // Returns an instance of the UserCloudPolicyManagerFactory singleton. 43 // Returns an instance of the UserCloudPolicyManagerFactory singleton.
46 static UserCloudPolicyManagerFactory* GetInstance(); 44 static UserCloudPolicyManagerFactory* GetInstance();
47 45
48 // Returns the UserCloudPolicyManager instance associated with |profile|. 46 // Returns the UserCloudPolicyManager instance associated with |context|.
49 static UserCloudPolicyManager* GetForProfile(Profile* profile); 47 static UserCloudPolicyManager* GetForBrowserContext(
48 content::BrowserContext* context);
50 49
51 // Creates an instance for |profile|. Note that the caller is responsible for 50 // Creates an instance for |context|. Note that the caller is responsible for
52 // managing the lifetime of the instance. Subsequent calls to GetForProfile() 51 // managing the lifetime of the instance. Subsequent calls to
53 // will return the created instance as long as it lives. 52 // GetForBrowserContext() will return the created instance as long as it
53 // lives.
54 // 54 //
55 // If |force_immediate_load| is true, policy is loaded synchronously from 55 // If |force_immediate_load| is true, policy is loaded synchronously from
56 // UserCloudPolicyStore at startup. 56 // UserCloudPolicyStore at startup.
57 static scoped_ptr<UserCloudPolicyManager> CreateForOriginalProfile( 57 static scoped_ptr<UserCloudPolicyManager> CreateForOriginalBrowserContext(
58 Profile* profile, 58 content::BrowserContext* context,
59 bool force_immediate_load, 59 bool force_immediate_load,
60 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 60 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
61 61
62 static UserCloudPolicyManager* RegisterForOffTheRecordProfile( 62 static UserCloudPolicyManager* RegisterForOffTheRecordBrowserContext(
63 Profile* original_profile, 63 content::BrowserContext* original_context,
64 Profile* off_the_record_profile); 64 content::BrowserContext* off_the_record_context);
65 65
66 private: 66 private:
67 friend class UserCloudPolicyManager; 67 friend class UserCloudPolicyManager;
68 friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactory>; 68 friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactory>;
69 69
70 UserCloudPolicyManagerFactory(); 70 UserCloudPolicyManagerFactory();
71 virtual ~UserCloudPolicyManagerFactory(); 71 virtual ~UserCloudPolicyManagerFactory();
72 72
73 // See comments for the static versions above. 73 // See comments for the static versions above.
74 UserCloudPolicyManager* GetManagerForProfile( 74 UserCloudPolicyManager* GetManagerForBrowserContext(
75 content::BrowserContext* context); 75 content::BrowserContext* context);
76 76
77 scoped_ptr<UserCloudPolicyManager> CreateManagerForOriginalProfile( 77 scoped_ptr<UserCloudPolicyManager> CreateManagerForOriginalBrowserContext(
78 Profile* profile, 78 content::BrowserContext* context,
79 bool force_immediate_load, 79 bool force_immediate_load,
80 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 80 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
81 81
82 UserCloudPolicyManager* RegisterManagerForOffTheRecordProfile( 82 UserCloudPolicyManager* RegisterManagerForOffTheRecordBrowserContext(
83 Profile* original_profile, 83 content::BrowserContext* original_context,
84 Profile* off_the_record_profile); 84 content::BrowserContext* off_the_record_context);
85 85
86 // BrowserContextKeyedBaseFactory: 86 // BrowserContextKeyedBaseFactory:
87 virtual void BrowserContextShutdown( 87 virtual void BrowserContextShutdown(
88 content::BrowserContext* context) OVERRIDE; 88 content::BrowserContext* context) OVERRIDE;
89 virtual void SetEmptyTestingFactory( 89 virtual void SetEmptyTestingFactory(
90 content::BrowserContext* context) OVERRIDE; 90 content::BrowserContext* context) OVERRIDE;
91 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; 91 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
92 92
93 // Invoked by UserCloudPolicyManager to register/unregister instances. 93 // Invoked by UserCloudPolicyManager to register/unregister instances.
94 void Register(content::BrowserContext* context, 94 void Register(content::BrowserContext* context,
95 UserCloudPolicyManager* instance); 95 UserCloudPolicyManager* instance);
96 void Unregister(content::BrowserContext* context, 96 void Unregister(content::BrowserContext* context,
97 UserCloudPolicyManager* instance); 97 UserCloudPolicyManager* instance);
98 98
99 typedef std::map<content::BrowserContext*, UserCloudPolicyManager*> 99 typedef std::map<content::BrowserContext*, UserCloudPolicyManager*>
100 ManagerMap; 100 ManagerMap;
101 101
102 ManagerMap managers_; 102 ManagerMap managers_;
103 103
104 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory); 104 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory);
105 }; 105 };
106 106
107 } // namespace policy 107 } // namespace policy
108 108
109 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_ 109 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698