| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( | 24 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile( |
| 25 Profile* profile) { | 25 Profile* profile) { |
| 26 return GetInstance()->GetManagerForProfile(profile); | 26 return GetInstance()->GetManagerForProfile(profile); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 scoped_ptr<UserCloudPolicyManager> | 30 scoped_ptr<UserCloudPolicyManager> |
| 31 UserCloudPolicyManagerFactory::CreateForProfile( | 31 UserCloudPolicyManagerFactory::CreateForOriginalProfile( |
| 32 Profile* profile, | 32 Profile* profile, |
| 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()->CreateManagerForProfile( | 35 return GetInstance()->CreateManagerForOriginalProfile( |
| 36 profile, force_immediate_load, background_task_runner); | 36 profile, force_immediate_load, background_task_runner); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static |
| 40 UserCloudPolicyManager* |
| 41 UserCloudPolicyManagerFactory::RegisterForOffTheRecordProfile( |
| 42 Profile* original_profile, |
| 43 Profile* off_the_record_profile) { |
| 44 return GetInstance()->RegisterManagerForOffTheRecordProfile( |
| 45 original_profile, off_the_record_profile); |
| 46 } |
| 47 |
| 48 |
| 39 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() | 49 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() |
| 40 : BrowserContextKeyedBaseFactory( | 50 : BrowserContextKeyedBaseFactory( |
| 41 "UserCloudPolicyManager", | 51 "UserCloudPolicyManager", |
| 42 BrowserContextDependencyManager::GetInstance()) {} | 52 BrowserContextDependencyManager::GetInstance()) {} |
| 43 | 53 |
| 44 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} | 54 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} |
| 45 | 55 |
| 46 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( | 56 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( |
| 47 Profile* profile) { | 57 Profile* profile) { |
| 48 // Get the manager for the original profile, since the PolicyService is | 58 // In case |profile| is an incognito Profile, |manager_| will have a matching |
| 49 // also shared between the incognito Profile and the original Profile. | 59 // entry pointing to the PolicyService of the original Profile. |
| 50 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); | 60 ManagerMap::const_iterator it = managers_.find(profile); |
| 51 return it != managers_.end() ? it->second : NULL; | 61 return it != managers_.end() ? it->second : NULL; |
| 52 } | 62 } |
| 53 | 63 |
| 54 scoped_ptr<UserCloudPolicyManager> | 64 scoped_ptr<UserCloudPolicyManager> |
| 55 UserCloudPolicyManagerFactory::CreateManagerForProfile( | 65 UserCloudPolicyManagerFactory::CreateManagerForOriginalProfile( |
| 56 Profile* profile, | 66 Profile* profile, |
| 57 bool force_immediate_load, | 67 bool force_immediate_load, |
| 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 68 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 59 scoped_ptr<UserCloudPolicyStore> store( | 69 scoped_ptr<UserCloudPolicyStore> store( |
| 60 UserCloudPolicyStore::Create(profile, background_task_runner)); | 70 UserCloudPolicyStore::Create(profile, background_task_runner)); |
| 61 if (force_immediate_load) | 71 if (force_immediate_load) |
| 62 store->LoadImmediately(); | 72 store->LoadImmediately(); |
| 63 scoped_ptr<UserCloudPolicyManager> manager( | 73 scoped_ptr<UserCloudPolicyManager> manager( |
| 64 new UserCloudPolicyManager(profile, | 74 new UserCloudPolicyManager(profile, |
| 65 store.Pass(), | 75 store.Pass(), |
| 66 scoped_ptr<CloudExternalDataManager>(), | 76 scoped_ptr<CloudExternalDataManager>(), |
| 67 base::MessageLoopProxy::current())); | 77 base::MessageLoopProxy::current())); |
| 68 manager->Init(); | 78 manager->Init(); |
| 69 return manager.Pass(); | 79 return manager.Pass(); |
| 70 } | 80 } |
| 71 | 81 |
| 82 UserCloudPolicyManager* |
| 83 UserCloudPolicyManagerFactory::RegisterManagerForOffTheRecordProfile( |
| 84 Profile* original_profile, |
| 85 Profile* off_the_record_profile) { |
| 86 // Register the PolicyService of the original Profile for the respective |
| 87 // incognito Profile. See GetManagerForProfile above. |
| 88 UserCloudPolicyManager* manager = GetManagerForProfile(original_profile); |
| 89 Register(off_the_record_profile, manager); |
| 90 return manager; |
| 91 } |
| 92 |
| 72 void UserCloudPolicyManagerFactory::BrowserContextShutdown( | 93 void UserCloudPolicyManagerFactory::BrowserContextShutdown( |
| 73 content::BrowserContext* context) { | 94 content::BrowserContext* context) { |
| 74 Profile* profile = static_cast<Profile*>(context); | 95 Profile* profile = static_cast<Profile*>(context); |
| 75 if (profile->IsOffTheRecord()) | 96 if (profile->IsOffTheRecord()) |
| 76 return; | 97 return; |
| 77 UserCloudPolicyManager* manager = GetManagerForProfile(profile); | 98 UserCloudPolicyManager* manager = GetManagerForProfile(profile); |
| 78 if (manager) | 99 if (manager) |
| 79 manager->Shutdown(); | 100 manager->Shutdown(); |
| 80 } | 101 } |
| 81 | 102 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 100 ManagerMap::iterator entry = managers_.find(profile); | 121 ManagerMap::iterator entry = managers_.find(profile); |
| 101 if (entry != managers_.end()) { | 122 if (entry != managers_.end()) { |
| 102 DCHECK_EQ(instance, entry->second); | 123 DCHECK_EQ(instance, entry->second); |
| 103 managers_.erase(entry); | 124 managers_.erase(entry); |
| 104 } else { | 125 } else { |
| 105 NOTREACHED(); | 126 NOTREACHED(); |
| 106 } | 127 } |
| 107 } | 128 } |
| 108 | 129 |
| 109 } // namespace policy | 130 } // namespace policy |
| OLD | NEW |