| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 9 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
| 10 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" | 10 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 scoped_ptr<UserCloudPolicyManager> | 29 scoped_ptr<UserCloudPolicyManager> |
| 30 UserCloudPolicyManagerFactory::CreateForProfile(Profile* profile, | 30 UserCloudPolicyManagerFactory::CreateForProfile(Profile* profile, |
| 31 bool force_immediate_load) { | 31 bool force_immediate_load) { |
| 32 return GetInstance()->CreateManagerForProfile(profile, force_immediate_load); | 32 return GetInstance()->CreateManagerForProfile(profile, force_immediate_load); |
| 33 } | 33 } |
| 34 | 34 |
| 35 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() | 35 UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory() |
| 36 : ProfileKeyedBaseFactory("UserCloudPolicyManager", | 36 : BrowserContextKeyedBaseFactory( |
| 37 ProfileDependencyManager::GetInstance()) {} | 37 "UserCloudPolicyManager", |
| 38 BrowserContextDependencyManager::GetInstance()) {} |
| 38 | 39 |
| 39 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} | 40 UserCloudPolicyManagerFactory::~UserCloudPolicyManagerFactory() {} |
| 40 | 41 |
| 41 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( | 42 UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile( |
| 42 Profile* profile) { | 43 Profile* profile) { |
| 43 // Get the manager for the original profile, since the PolicyService is | 44 // Get the manager for the original profile, since the PolicyService is |
| 44 // also shared between the incognito Profile and the original Profile. | 45 // also shared between the incognito Profile and the original Profile. |
| 45 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); | 46 ManagerMap::const_iterator it = managers_.find(profile->GetOriginalProfile()); |
| 46 return it != managers_.end() ? it->second : NULL; | 47 return it != managers_.end() ? it->second : NULL; |
| 47 } | 48 } |
| 48 | 49 |
| 49 scoped_ptr<UserCloudPolicyManager> | 50 scoped_ptr<UserCloudPolicyManager> |
| 50 UserCloudPolicyManagerFactory::CreateManagerForProfile( | 51 UserCloudPolicyManagerFactory::CreateManagerForProfile( |
| 51 Profile* profile, | 52 Profile* profile, |
| 52 bool force_immediate_load) { | 53 bool force_immediate_load) { |
| 53 if (CommandLine::ForCurrentProcess()->HasSwitch( | 54 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 54 switches::kDisableCloudPolicyOnSignin)) { | 55 switches::kDisableCloudPolicyOnSignin)) { |
| 55 return scoped_ptr<UserCloudPolicyManager>(); | 56 return scoped_ptr<UserCloudPolicyManager>(); |
| 56 } | 57 } |
| 57 scoped_ptr<UserCloudPolicyStore> store(UserCloudPolicyStore::Create(profile)); | 58 scoped_ptr<UserCloudPolicyStore> store(UserCloudPolicyStore::Create(profile)); |
| 58 if (force_immediate_load) | 59 if (force_immediate_load) |
| 59 store->LoadImmediately(); | 60 store->LoadImmediately(); |
| 60 scoped_ptr<UserCloudPolicyManager> manager( | 61 scoped_ptr<UserCloudPolicyManager> manager( |
| 61 new UserCloudPolicyManager(profile, store.Pass())); | 62 new UserCloudPolicyManager(profile, store.Pass())); |
| 62 manager->Init(); | 63 manager->Init(); |
| 63 return manager.Pass(); | 64 return manager.Pass(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void UserCloudPolicyManagerFactory::ProfileShutdown( | 67 void UserCloudPolicyManagerFactory::BrowserContextShutdown( |
| 67 content::BrowserContext* context) { | 68 content::BrowserContext* context) { |
| 68 Profile* profile = static_cast<Profile*>(context); | 69 Profile* profile = static_cast<Profile*>(context); |
| 69 if (profile->IsOffTheRecord()) | 70 if (profile->IsOffTheRecord()) |
| 70 return; | 71 return; |
| 71 UserCloudPolicyManager* manager = GetManagerForProfile(profile); | 72 UserCloudPolicyManager* manager = GetManagerForProfile(profile); |
| 72 if (manager) { | 73 if (manager) { |
| 73 manager->CloudPolicyManager::Shutdown(); | 74 manager->CloudPolicyManager::Shutdown(); |
| 74 manager->ProfileKeyedService::Shutdown(); | 75 manager->BrowserContextKeyedService::Shutdown(); |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 78 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( | 79 void UserCloudPolicyManagerFactory::SetEmptyTestingFactory( |
| 79 content::BrowserContext* profile) { | 80 content::BrowserContext* profile) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 void UserCloudPolicyManagerFactory::CreateServiceNow( | 83 void UserCloudPolicyManagerFactory::CreateServiceNow( |
| 83 content::BrowserContext* profile) { | 84 content::BrowserContext* profile) { |
| 84 } | 85 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 ManagerMap::iterator entry = managers_.find(profile); | 97 ManagerMap::iterator entry = managers_.find(profile); |
| 97 if (entry != managers_.end()) { | 98 if (entry != managers_.end()) { |
| 98 DCHECK_EQ(instance, entry->second); | 99 DCHECK_EQ(instance, entry->second); |
| 99 managers_.erase(entry); | 100 managers_.erase(entry); |
| 100 } else { | 101 } else { |
| 101 NOTREACHED(); | 102 NOTREACHED(); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 } // namespace policy | 106 } // namespace policy |
| OLD | NEW |