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

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
19 namespace content {
20 class BrowserContext;
21 }
22
21 namespace policy { 23 namespace policy {
22 24
23 class UserCloudPolicyManager; 25 class UserCloudPolicyManager;
24 26
25 // BrowserContextKeyedBaseFactory implementation for UserCloudPolicyManager 27 // BrowserContextKeyedBaseFactory implementation for UserCloudPolicyManager
26 // instances that initialize per-profile cloud policy settings on the desktop 28 // instances that initialize per-profile cloud policy settings on the desktop
27 // platforms. 29 // platforms.
28 // 30 //
29 // UserCloudPolicyManager is handled different than other 31 // UserCloudPolicyManager is handled different than other
30 // BrowserContextKeyedServices because it is a dependency of PrefService. 32 // BrowserContextKeyedServices because it is a dependency of PrefService.
31 // Therefore, lifetime of instances is managed by Profile, Profile startup code 33 // Therefore, lifetime of instances is managed by Profile, Profile startup code
32 // invokes CreateForProfile() explicitly, takes ownership, and the instance 34 // invokes CreateForBrowserContext() explicitly, takes ownership, and the
33 // is only deleted after PrefService destruction. 35 // instance is only deleted after PrefService destruction.
34 // 36 //
35 // TODO(mnissler): Remove the special lifetime management in favor of 37 // TODO(mnissler): Remove the special lifetime management in favor of
36 // PrefService directly depending on UserCloudPolicyManager once the former has 38 // PrefService directly depending on UserCloudPolicyManager once the former has
37 // been converted to a BrowserContextKeyedService. 39 // been converted to a BrowserContextKeyedService.
38 // See also http://crbug.com/131843 and http://crbug.com/131844. 40 // See also http://crbug.com/131843 and http://crbug.com/131844.
39 class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory { 41 class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory {
40 public: 42 public:
41 // Returns an instance of the UserCloudPolicyManagerFactory singleton. 43 // Returns an instance of the UserCloudPolicyManagerFactory singleton.
42 static UserCloudPolicyManagerFactory* GetInstance(); 44 static UserCloudPolicyManagerFactory* GetInstance();
43 45
44 // Returns the UserCloudPolicyManager instance associated with |profile|. 46 // Returns the UserCloudPolicyManager instance associated with |context|.
45 static UserCloudPolicyManager* GetForProfile(Profile* profile); 47 static UserCloudPolicyManager* GetForBrowserContext(
48 content::BrowserContext* context);
46 49
47 // 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
48 // managing the lifetime of the instance. Subsequent calls to GetForProfile() 51 // managing the lifetime of the instance. Subsequent calls to
49 // will return the created instance as long as it lives. 52 // GetForBrowserContext() will return the created instance as long as it
53 // lives.
50 // 54 //
51 // If |force_immediate_load| is true, policy is loaded synchronously from 55 // If |force_immediate_load| is true, policy is loaded synchronously from
52 // UserCloudPolicyStore at startup. 56 // UserCloudPolicyStore at startup.
53 static scoped_ptr<UserCloudPolicyManager> CreateForOriginalProfile( 57 static scoped_ptr<UserCloudPolicyManager> CreateForOriginalBrowserContext(
54 Profile* profile, 58 content::BrowserContext* context,
55 bool force_immediate_load, 59 bool force_immediate_load,
56 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 60 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
57 61
58 static UserCloudPolicyManager* RegisterForOffTheRecordProfile( 62 static UserCloudPolicyManager* RegisterForOffTheRecordBrowserContext(
59 Profile* original_profile, 63 content::BrowserContext* original_context,
60 Profile* off_the_record_profile); 64 content::BrowserContext* off_the_record_context);
61 65
62 private: 66 private:
63 friend class UserCloudPolicyManager; 67 friend class UserCloudPolicyManager;
64 friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactory>; 68 friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactory>;
65 69
66 UserCloudPolicyManagerFactory(); 70 UserCloudPolicyManagerFactory();
67 virtual ~UserCloudPolicyManagerFactory(); 71 virtual ~UserCloudPolicyManagerFactory();
68 72
69 // See comments for the static versions above. 73 // See comments for the static versions above.
70 UserCloudPolicyManager* GetManagerForProfile(Profile* profile); 74 UserCloudPolicyManager* GetManagerForBrowserContext(
75 content::BrowserContext* context);
71 76
72 scoped_ptr<UserCloudPolicyManager> CreateManagerForOriginalProfile( 77 scoped_ptr<UserCloudPolicyManager> CreateManagerForOriginalBrowserContext(
73 Profile* profile, 78 content::BrowserContext* context,
74 bool force_immediate_load, 79 bool force_immediate_load,
75 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 80 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
76 81
77 UserCloudPolicyManager* RegisterManagerForOffTheRecordProfile( 82 UserCloudPolicyManager* RegisterManagerForOffTheRecordBrowserContext(
78 Profile* original_profile, 83 content::BrowserContext* original_context,
79 Profile* off_the_record_profile); 84 content::BrowserContext* off_the_record_context);
80 85
81 // BrowserContextKeyedBaseFactory: 86 // BrowserContextKeyedBaseFactory:
82 virtual void BrowserContextShutdown( 87 virtual void BrowserContextShutdown(
83 content::BrowserContext* context) OVERRIDE; 88 content::BrowserContext* context) OVERRIDE;
84 virtual void SetEmptyTestingFactory( 89 virtual void SetEmptyTestingFactory(
85 content::BrowserContext* context) OVERRIDE; 90 content::BrowserContext* context) OVERRIDE;
86 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; 91 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
87 92
88 // Invoked by UserCloudPolicyManager to register/unregister instances. 93 // Invoked by UserCloudPolicyManager to register/unregister instances.
89 void Register(Profile* profile, UserCloudPolicyManager* instance); 94 void Register(content::BrowserContext* context,
90 void Unregister(Profile* profile, UserCloudPolicyManager* instance); 95 UserCloudPolicyManager* instance);
96 void Unregister(content::BrowserContext* context,
97 UserCloudPolicyManager* instance);
91 98
92 typedef std::map<Profile*, UserCloudPolicyManager*> ManagerMap; 99 typedef std::map<content::BrowserContext*, UserCloudPolicyManager*>
100 ManagerMap;
93 101
94 ManagerMap managers_; 102 ManagerMap managers_;
95 103
96 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory); 104 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerFactory);
97 }; 105 };
98 106
99 } // namespace policy 107 } // namespace policy
100 108
101 #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