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