| 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/policy/schema_registry_service.h" |
| 14 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 16 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 15 | 17 |
| 16 namespace policy { | 18 namespace policy { |
| 17 | 19 |
| 18 // static | 20 // static |
| 19 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { | 21 UserCloudPolicyManagerFactory* UserCloudPolicyManagerFactory::GetInstance() { |
| 20 return Singleton<UserCloudPolicyManagerFactory>::get(); | 22 return Singleton<UserCloudPolicyManagerFactory>::get(); |
| 21 } | 23 } |
| 22 | 24 |
| 23 // static | 25 // static |
| 24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( | 26 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( |
| 25 Profile* profile) { | 27 Profile* profile) { |
| 26 return GetInstance()->GetManagerForProfile(profile); | 28 return GetInstance()->GetManagerForProfile(profile); |
| 27 } | 29 } |
| 28 | 30 |
| 29 // static | 31 // static |
| 30 scoped_ptr<UserCloudPolicyManager> | 32 scoped_ptr<UserCloudPolicyManager> |
| 31 UserCloudPolicyManagerFactory::CreateForProfile( | 33 UserCloudPolicyManagerFactory::CreateForProfile( |
| 32 Profile* profile, | 34 Profile* profile, |
| 33 bool force_immediate_load, | 35 bool force_immediate_load, |
| 34 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 36 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 35 return GetInstance()->CreateManagerForProfile( | 37 return GetInstance()->CreateManagerForProfile( |
| 36 profile, force_immediate_load, background_task_runner); | 38 profile, force_immediate_load, background_task_runner); |
| 37 } | 39 } |
| 38 | 40 |
| 39 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() | 41 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() |
| 40 : BrowserContextKeyedBaseFactory( | 42 : BrowserContextKeyedBaseFactory( |
| 41 "UserCloudPolicyManager", | 43 "UserCloudPolicyManager", |
| 42 BrowserContextDependencyManager::GetInstance()) {} | 44 BrowserContextDependencyManager::GetInstance()) { |
| 45 DependsOn(SchemaRegistryServiceFactory::GetInstance()); |
| 46 } |
| 43 | 47 |
| 44 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} | 48 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} |
| 45 | 49 |
| 46 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( | 50 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( |
| 47 Profile* profile) { | 51 Profile* profile) { |
| 48 // Get the manager for the original profile, since the PolicyService is | 52 // Get the manager for the original profile, since the PolicyService is |
| 49 // also shared between the incognito Profile and the original Profile. | 53 // also shared between the incognito Profile and the original Profile. |
| 50 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); | 54 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); |
| 51 return it != managers_.end() ? it->second : NULL; | 55 return it != managers_.end() ? it->second : NULL; |
| 52 } | 56 } |
| 53 | 57 |
| 54 scoped_ptr<UserCloudPolicyManager> | 58 scoped_ptr<UserCloudPolicyManager> |
| 55 UserCloudPolicyManagerFactory::CreateManagerForProfile( | 59 UserCloudPolicyManagerFactory::CreateManagerForProfile( |
| 56 Profile* profile, | 60 Profile* profile, |
| 57 bool force_immediate_load, | 61 bool force_immediate_load, |
| 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 62 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 59 scoped_ptr<UserCloudPolicyStore> store( | 63 scoped_ptr<UserCloudPolicyStore> store( |
| 60 UserCloudPolicyStore::Create(profile, background_task_runner)); | 64 UserCloudPolicyStore::Create(profile, background_task_runner)); |
| 61 if (force_immediate_load) | 65 if (force_immediate_load) |
| 62 store->LoadImmediately(); | 66 store->LoadImmediately(); |
| 63 scoped_ptr<UserCloudPolicyManager> manager( | 67 scoped_ptr<UserCloudPolicyManager> manager( |
| 64 new UserCloudPolicyManager(profile, | 68 new UserCloudPolicyManager(profile, |
| 65 store.Pass(), | 69 store.Pass(), |
| 66 scoped_ptr<CloudExternalDataManager>(), | 70 scoped_ptr<CloudExternalDataManager>(), |
| 67 base::MessageLoopProxy::current())); | 71 base::MessageLoopProxy::current())); |
| 68 manager->Init(); | 72 manager->Init(SchemaRegistryServiceFactory::GetForContext(profile)); |
| 69 return manager.Pass(); | 73 return manager.Pass(); |
| 70 } | 74 } |
| 71 | 75 |
| 72 void UserCloudPolicyManagerFactory::BrowserContextShutdown( | 76 void UserCloudPolicyManagerFactory::BrowserContextShutdown( |
| 73 content::BrowserContext* context) { | 77 content::BrowserContext* context) { |
| 74 Profile* profile = static_cast<Profile*>(context); | 78 Profile* profile = static_cast<Profile*>(context); |
| 75 if (profile->IsOffTheRecord()) | 79 if (profile->IsOffTheRecord()) |
| 76 return; | 80 return; |
| 77 UserCloudPolicyManager* manager = GetManagerForProfile(profile); | 81 UserCloudPolicyManager* manager = GetManagerForProfile(profile); |
| 78 if (manager) | 82 if (manager) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 100 ManagerMap::iterator entry = managers_.find(profile); | 104 ManagerMap::iterator entry = managers_.find(profile); |
| 101 if (entry != managers_.end()) { | 105 if (entry != managers_.end()) { |
| 102 DCHECK_EQ(instance, entry->second); | 106 DCHECK_EQ(instance, entry->second); |
| 103 managers_.erase(entry); | 107 managers_.erase(entry); |
| 104 } else { | 108 } else { |
| 105 NOTREACHED(); | 109 NOTREACHED(); |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 | 112 |
| 109 } // namespace policy | 113 } // namespace policy |
| OLD | NEW |