OLD | NEW |
---|---|
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 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 5 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" | 10 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
11 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 11 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
12 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" | 12 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
15 #include "content/public/browser/browser_context.h" | |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
17 | 18 |
18 // static | 19 // static |
19 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { | 20 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { |
20 return Singleton<UserCloudPolicyManagerFactory>::get(); | 21 return Singleton<UserCloudPolicyManagerFactory>::get(); |
21 } | 22 } |
22 | 23 |
23 // static | 24 // static |
24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( | 25 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( |
25 Profile* profile) { | 26 Profile* profile) { |
26 return GetInstance()->GetManagerForProfile(profile); | 27 return GetInstance()->GetManagerForProfile(profile); |
27 } | 28 } |
28 | 29 |
29 // static | 30 // static |
30 scoped_ptr<UserCloudPolicyManager> | 31 scoped_ptr<UserCloudPolicyManager> |
31 UserCloudPolicyManagerFactory::CreateForProfile( | 32 UserCloudPolicyManagerFactory::CreateForOriginalProfile( |
32 Profile* profile, | 33 Profile* profile, |
33 bool force_immediate_load, | 34 bool force_immediate_load, |
34 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 35 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
35 return GetInstance()->CreateManagerForProfile( | 36 return GetInstance()->CreateManagerForOriginalProfile( |
36 profile, force_immediate_load, background_task_runner); | 37 profile, force_immediate_load, background_task_runner); |
37 } | 38 } |
38 | 39 |
40 // static | |
41 UserCloudPolicyManager* | |
42 UserCloudPolicyManagerFactory::RegisterForOffTheRecordProfile( | |
43 Profile* original_profile, | |
44 Profile* off_the_record_profile) { | |
45 return GetInstance()->RegisterManagerForOffTheRecordProfile( | |
46 original_profile, off_the_record_profile); | |
47 } | |
48 | |
49 | |
39 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() | 50 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() |
40 : BrowserContextKeyedBaseFactory( | 51 : BrowserContextKeyedBaseFactory( |
41 "UserCloudPolicyManager", | 52 "UserCloudPolicyManager", |
42 BrowserContextDependencyManager::GetInstance()) {} | 53 BrowserContextDependencyManager::GetInstance()) {} |
43 | 54 |
44 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} | 55 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} |
45 | 56 |
46 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( | 57 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( |
47 Profile* profile) { | 58 content::BrowserContext* context) { |
48 // Get the manager for the original profile, since the PolicyService is | 59 // Get the manager for the original profile, since the PolicyService is |
49 // also shared between the incognito Profile and the original Profile. | 60 // also shared between the incognito Profile and the original Profile. |
Joao da Silva
2013/11/04 09:53:38
Update this comment.
pneubeck (no reviews)
2013/11/04 12:38:50
Done.
| |
50 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); | 61 ManagerMap::const_iterator it = managers_.find(context); |
51 return it != managers_.end() ? it->second : NULL; | 62 return it != managers_.end() ? it->second : NULL; |
52 } | 63 } |
53 | 64 |
54 scoped_ptr<UserCloudPolicyManager> | 65 scoped_ptr<UserCloudPolicyManager> |
55 UserCloudPolicyManagerFactory::CreateManagerForProfile( | 66 UserCloudPolicyManagerFactory::CreateManagerForOriginalProfile( |
56 Profile* profile, | 67 Profile* profile, |
57 bool force_immediate_load, | 68 bool force_immediate_load, |
58 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 69 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
59 scoped_ptr<UserCloudPolicyStore> store( | 70 scoped_ptr<UserCloudPolicyStore> store( |
60 UserCloudPolicyStore::Create(profile, background_task_runner)); | 71 UserCloudPolicyStore::Create(profile, background_task_runner)); |
61 if (force_immediate_load) | 72 if (force_immediate_load) |
62 store->LoadImmediately(); | 73 store->LoadImmediately(); |
63 scoped_ptr<UserCloudPolicyManager> manager( | 74 scoped_ptr<UserCloudPolicyManager> manager( |
64 new UserCloudPolicyManager(profile, | 75 new UserCloudPolicyManager(profile, |
65 store.Pass(), | 76 store.Pass(), |
66 scoped_ptr<CloudExternalDataManager>(), | 77 scoped_ptr<CloudExternalDataManager>(), |
67 base::MessageLoopProxy::current())); | 78 base::MessageLoopProxy::current())); |
68 manager->Init(); | 79 manager->Init(); |
69 return manager.Pass(); | 80 return manager.Pass(); |
70 } | 81 } |
71 | 82 |
83 UserCloudPolicyManager* | |
84 UserCloudPolicyManagerFactory::RegisterManagerForOffTheRecordProfile( | |
85 Profile* original_profile, | |
86 Profile* off_the_record_profile) { | |
87 UserCloudPolicyManager* manager = GetManagerForProfile(original_profile); | |
88 Register(off_the_record_profile, manager); | |
89 return manager; | |
90 } | |
91 | |
72 void UserCloudPolicyManagerFactory::BrowserContextShutdown( | 92 void UserCloudPolicyManagerFactory::BrowserContextShutdown( |
73 content::BrowserContext* context) { | 93 content::BrowserContext* context) { |
74 Profile* profile = static_cast<Profile*>(context); | 94 if (context->IsOffTheRecord()) |
75 if (profile->IsOffTheRecord()) | |
76 return; | 95 return; |
77 UserCloudPolicyManager* manager = GetManagerForProfile(profile); | 96 UserCloudPolicyManager* manager = GetManagerForProfile(context); |
78 if (manager) | 97 if (manager) |
79 manager->Shutdown(); | 98 manager->Shutdown(); |
80 } | 99 } |
81 | 100 |
82 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( | 101 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( |
83 content::BrowserContext* profile) { | 102 content::BrowserContext* context) { |
84 } | 103 } |
85 | 104 |
86 void UserCloudPolicyManagerFactory::CreateServiceNow( | 105 void UserCloudPolicyManagerFactory::CreateServiceNow( |
87 content::BrowserContext* profile) { | 106 content::BrowserContext* context) { |
88 } | 107 } |
89 | 108 |
90 void UserCloudPolicyManagerFactory::Register(Profile* profile, | 109 void UserCloudPolicyManagerFactory::Register(content::BrowserContext* context, |
91 UserCloudPolicyManager* instance) { | 110 UserCloudPolicyManager* instance) { |
92 UserCloudPolicyManager*& entry = managers_[profile]; | 111 UserCloudPolicyManager*& entry = managers_[context]; |
93 DCHECK(!entry); | 112 DCHECK(!entry); |
94 entry = instance; | 113 entry = instance; |
95 } | 114 } |
96 | 115 |
97 void UserCloudPolicyManagerFactory::Unregister( | 116 void UserCloudPolicyManagerFactory::Unregister( |
98 Profile* profile, | 117 content::BrowserContext* context, |
99 UserCloudPolicyManager* instance) { | 118 UserCloudPolicyManager* instance) { |
100 ManagerMap::iterator entry = managers_.find(profile); | 119 ManagerMap::iterator entry = managers_.find(context); |
101 if (entry != managers_.end()) { | 120 if (entry != managers_.end()) { |
102 DCHECK_EQ(instance, entry->second); | 121 DCHECK_EQ(instance, entry->second); |
103 managers_.erase(entry); | 122 managers_.erase(entry); |
104 } else { | 123 } else { |
105 NOTREACHED(); | 124 NOTREACHED(); |
106 } | 125 } |
107 } | 126 } |
108 | 127 |
109 } // namespace policy | 128 } // namespace policy |
OLD | NEW |