| 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" | |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 14 #include "content/public/browser/browser_context.h" |
| 15 | 15 |
| 16 namespace policy { | 16 namespace policy { |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { | 19 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { |
| 20 return Singleton<UserCloudPolicyManagerFactory>::get(); | 20 return Singleton<UserCloudPolicyManagerFactory>::get(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( | 24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForBrowserContext( |
| 25 Profile* profile) { | 25 content::BrowserContext* context) { |
| 26 return GetInstance()->GetManagerForProfile(profile); | 26 return GetInstance()->GetManagerForBrowserContext(context); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 scoped_ptr<UserCloudPolicyManager> | 30 scoped_ptr<UserCloudPolicyManager> |
| 31 UserCloudPolicyManagerFactory::CreateForOriginalProfile( | 31 UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext( |
| 32 Profile* profile, | 32 content::BrowserContext* context, |
| 33 bool force_immediate_load, | 33 bool force_immediate_load, |
| 34 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 34 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 35 return GetInstance()->CreateManagerForOriginalProfile( | 35 return GetInstance()->CreateManagerForOriginalBrowserContext( |
| 36 profile, force_immediate_load, background_task_runner); | 36 context, force_immediate_load, background_task_runner); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 UserCloudPolicyManager* | 40 UserCloudPolicyManager* |
| 41 UserCloudPolicyManagerFactory::RegisterForOffTheRecordProfile( | 41 UserCloudPolicyManagerFactory::RegisterForOffTheRecordBrowserContext( |
| 42 Profile* original_profile, | 42 content::BrowserContext* original_context, |
| 43 Profile* off_the_record_profile) { | 43 content::BrowserContext* off_the_record_context) { |
| 44 return GetInstance()->RegisterManagerForOffTheRecordProfile( | 44 return GetInstance()->RegisterManagerForOffTheRecordBrowserContext( |
| 45 original_profile, off_the_record_profile); | 45 original_context, off_the_record_context); |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() | 49 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() |
| 50 : BrowserContextKeyedBaseFactory( | 50 : BrowserContextKeyedBaseFactory( |
| 51 "UserCloudPolicyManager", | 51 "UserCloudPolicyManager", |
| 52 BrowserContextDependencyManager::GetInstance()) {} | 52 BrowserContextDependencyManager::GetInstance()) {} |
| 53 | 53 |
| 54 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} | 54 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} |
| 55 | 55 |
| 56 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( | 56 UserCloudPolicyManager* |
| 57 Profile* profile) { | 57 UserCloudPolicyManagerFactory::GetManagerForBrowserContext( |
| 58 // In case |profile| is an incognito Profile, |manager_| will have a matching | 58 content::BrowserContext* context) { |
| 59 // entry pointing to the PolicyService of the original Profile. | 59 // In case |context| is an incognito Profile/Context, |manager_| will have a |
| 60 ManagerMap::const_iterator it = managers_.find(profile); | 60 // matching entry pointing to the PolicyService of the original context. |
| 61 ManagerMap::const_iterator it = managers_.find(context); |
| 61 return it != managers_.end() ? it->second : NULL; | 62 return it != managers_.end() ? it->second : NULL; |
| 62 } | 63 } |
| 63 | 64 |
| 64 scoped_ptr<UserCloudPolicyManager> | 65 scoped_ptr<UserCloudPolicyManager> |
| 65 UserCloudPolicyManagerFactory::CreateManagerForOriginalProfile( | 66 UserCloudPolicyManagerFactory::CreateManagerForOriginalBrowserContext( |
| 66 Profile* profile, | 67 content::BrowserContext* context, |
| 67 bool force_immediate_load, | 68 bool force_immediate_load, |
| 68 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 69 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 69 scoped_ptr<UserCloudPolicyStore> store( | 70 scoped_ptr<UserCloudPolicyStore> store( |
| 70 UserCloudPolicyStore::Create(profile->GetPath(), background_task_runner)); | 71 UserCloudPolicyStore::Create(context->GetPath(), background_task_runner)); |
| 71 if (force_immediate_load) | 72 if (force_immediate_load) |
| 72 store->LoadImmediately(); | 73 store->LoadImmediately(); |
| 73 scoped_ptr<UserCloudPolicyManager> manager( | 74 scoped_ptr<UserCloudPolicyManager> manager( |
| 74 new UserCloudPolicyManager(profile, | 75 new UserCloudPolicyManager(context, |
| 75 store.Pass(), | 76 store.Pass(), |
| 76 scoped_ptr<CloudExternalDataManager>(), | 77 scoped_ptr<CloudExternalDataManager>(), |
| 77 base::MessageLoopProxy::current())); | 78 base::MessageLoopProxy::current())); |
| 78 manager->Init(); | 79 manager->Init(); |
| 79 return manager.Pass(); | 80 return manager.Pass(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 UserCloudPolicyManager* | 83 UserCloudPolicyManager* |
| 83 UserCloudPolicyManagerFactory::RegisterManagerForOffTheRecordProfile( | 84 UserCloudPolicyManagerFactory::RegisterManagerForOffTheRecordBrowserContext( |
| 84 Profile* original_profile, | 85 content::BrowserContext* original_context, |
| 85 Profile* off_the_record_profile) { | 86 content::BrowserContext* off_the_record_context) { |
| 86 // Register the PolicyService of the original Profile for the respective | 87 // Register the PolicyService of the original context for the respective |
| 87 // incognito Profile. See GetManagerForProfile above. | 88 // incognito context. See also GetManagerForBrowserContext. |
| 88 UserCloudPolicyManager* manager = GetManagerForProfile(original_profile); | 89 UserCloudPolicyManager* manager = |
| 89 Register(off_the_record_profile, manager); | 90 GetManagerForBrowserContext(original_context); |
| 91 Register(off_the_record_context, manager); |
| 90 return manager; | 92 return manager; |
| 91 } | 93 } |
| 92 | 94 |
| 93 void UserCloudPolicyManagerFactory::BrowserContextShutdown( | 95 void UserCloudPolicyManagerFactory::BrowserContextShutdown( |
| 94 content::BrowserContext* context) { | 96 content::BrowserContext* context) { |
| 95 Profile* profile = static_cast<Profile*>(context); | 97 if (context->IsOffTheRecord()) |
| 96 if (profile->IsOffTheRecord()) | |
| 97 return; | 98 return; |
| 98 UserCloudPolicyManager* manager = GetManagerForProfile(profile); | 99 UserCloudPolicyManager* manager = GetManagerForBrowserContext(context); |
| 99 if (manager) | 100 if (manager) |
| 100 manager->Shutdown(); | 101 manager->Shutdown(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( | 104 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( |
| 104 content::BrowserContext* profile) { | 105 content::BrowserContext* context) { |
| 105 } | 106 } |
| 106 | 107 |
| 107 void UserCloudPolicyManagerFactory::CreateServiceNow( | 108 void UserCloudPolicyManagerFactory::CreateServiceNow( |
| 108 content::BrowserContext* profile) { | 109 content::BrowserContext* context) { |
| 109 } | 110 } |
| 110 | 111 |
| 111 void UserCloudPolicyManagerFactory::Register(Profile* profile, | 112 void UserCloudPolicyManagerFactory::Register(content::BrowserContext* context, |
| 112 UserCloudPolicyManager* instance) { | 113 UserCloudPolicyManager* instance) { |
| 113 UserCloudPolicyManager*& entry = managers_[profile]; | 114 UserCloudPolicyManager*& entry = managers_[context]; |
| 114 DCHECK(!entry); | 115 DCHECK(!entry); |
| 115 entry = instance; | 116 entry = instance; |
| 116 } | 117 } |
| 117 | 118 |
| 118 void UserCloudPolicyManagerFactory::Unregister( | 119 void UserCloudPolicyManagerFactory::Unregister( |
| 119 Profile* profile, | 120 content::BrowserContext* context, |
| 120 UserCloudPolicyManager* instance) { | 121 UserCloudPolicyManager* instance) { |
| 121 ManagerMap::iterator entry = managers_.find(profile); | 122 ManagerMap::iterator entry = managers_.find(context); |
| 122 if (entry != managers_.end()) { | 123 if (entry != managers_.end()) { |
| 123 DCHECK_EQ(instance, entry->second); | 124 DCHECK_EQ(instance, entry->second); |
| 124 managers_.erase(entry); | 125 managers_.erase(entry); |
| 125 } else { | 126 } else { |
| 126 NOTREACHED(); | 127 NOTREACHED(); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 } // namespace policy | 131 } // namespace policy |
| OLD | NEW |