Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/profile_policy_connector_factory.h" | 5 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/singleton.h" | |
| 8 #include "chrome/browser/policy/profile_policy_connector.h" | 9 #include "chrome/browser/policy/profile_policy_connector.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 12 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 12 #include "components/user_prefs/pref_registry_syncable.h" | 13 #include "components/user_prefs/pref_registry_syncable.h" |
| 13 | 14 |
| 14 #if defined(ENABLE_CONFIGURATION_POLICY) | 15 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/login/user.h" | |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 18 #include "chrome/browser/chromeos/login/user_manager.h" |
| 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | |
| 17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" | 20 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 18 #else | 22 #else |
| 23 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | |
| 19 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 24 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 20 #endif | 25 #endif |
| 21 #endif | 26 #endif |
| 22 | 27 |
| 23 namespace policy { | 28 namespace policy { |
| 24 | 29 |
| 25 // static | 30 // static |
| 26 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { | 31 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { |
| 27 return Singleton<ProfilePolicyConnectorFactory>::get(); | 32 return Singleton<ProfilePolicyConnectorFactory>::get(); |
| 28 } | 33 } |
| 29 | 34 |
| 30 // static | 35 // static |
| 31 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( | 36 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( |
| 32 Profile* profile) { | 37 Profile* profile) { |
| 33 return GetInstance()->GetForProfileInternal(profile); | 38 return GetInstance()->GetForProfileInternal(profile); |
| 34 } | 39 } |
| 35 | 40 |
| 36 // static | 41 // static |
| 37 scoped_ptr<ProfilePolicyConnector> | 42 scoped_ptr<ProfilePolicyConnector> |
| 38 ProfilePolicyConnectorFactory::CreateForProfile( | 43 ProfilePolicyConnectorFactory::CreateForProfile(Profile* profile, |
| 39 Profile* profile, | 44 bool force_immediate_load) { |
| 40 bool force_immediate_load) { | |
| 41 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load); | 45 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void ProfilePolicyConnectorFactory::SetServiceForTesting( | 48 void ProfilePolicyConnectorFactory::SetServiceForTesting( |
| 45 Profile* profile, | 49 Profile* profile, |
| 46 ProfilePolicyConnector* connector) { | 50 ProfilePolicyConnector* connector) { |
| 47 ProfilePolicyConnector*& map_entry = connectors_[profile]; | 51 ProfilePolicyConnector*& map_entry = connectors_[profile]; |
| 48 CHECK(!map_entry); | 52 CHECK(!map_entry); |
| 49 map_entry = connector; | 53 map_entry = connector; |
| 50 } | 54 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 70 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { | 74 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { |
| 71 // Get the connector for the original Profile, so that the incognito Profile | 75 // Get the connector for the original Profile, so that the incognito Profile |
| 72 // gets managed settings from the same PolicyService. | 76 // gets managed settings from the same PolicyService. |
| 73 ConnectorMap::const_iterator it = | 77 ConnectorMap::const_iterator it = |
| 74 connectors_.find(profile->GetOriginalProfile()); | 78 connectors_.find(profile->GetOriginalProfile()); |
| 75 CHECK(it != connectors_.end()); | 79 CHECK(it != connectors_.end()); |
| 76 return it->second; | 80 return it->second; |
| 77 } | 81 } |
| 78 | 82 |
| 79 scoped_ptr<ProfilePolicyConnector> | 83 scoped_ptr<ProfilePolicyConnector> |
| 80 ProfilePolicyConnectorFactory::CreateForProfileInternal( | 84 ProfilePolicyConnectorFactory::CreateForProfileInternal( |
| 81 Profile* profile, | 85 Profile* profile, |
| 82 bool force_immediate_load) { | 86 bool force_immediate_load) { |
| 83 DCHECK(connectors_.find(profile) == connectors_.end()); | 87 DCHECK(connectors_.find(profile) == connectors_.end()); |
| 88 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) | |
| 89 chromeos::User* user = NULL; | |
| 90 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { | |
| 91 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
| 92 user = user_manager->GetUserByProfile(profile); | |
| 93 CHECK(user); | |
| 94 } | |
| 95 CloudPolicyManager* user_cloud_policy_manager = | |
| 96 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | |
| 97 #else | |
|
Joao da Silva
2013/11/04 09:46:52
This else breaks when ENABLE_CONFIGURATION_POLICY
pneubeck (no reviews)
2013/11/04 13:11:52
Done.
| |
| 98 CloudPolicyManager* user_cloud_policy_manager = | |
| 99 UserCloudPolicyManagerFactory::GetForProfile(profile); | |
| 100 #endif | |
| 84 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); | 101 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); |
| 85 connector->Init(force_immediate_load); | 102 connector->Init(force_immediate_load, |
| 103 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) | |
| 104 user, | |
| 105 #endif | |
| 106 user_cloud_policy_manager); | |
| 86 connectors_[profile] = connector; | 107 connectors_[profile] = connector; |
| 87 return scoped_ptr<ProfilePolicyConnector>(connector); | 108 return make_scoped_ptr(connector); |
| 88 } | 109 } |
| 89 | 110 |
| 90 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 111 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
| 91 content::BrowserContext* context) { | 112 content::BrowserContext* context) { |
| 92 Profile* profile = static_cast<Profile*>(context); | 113 Profile* profile = static_cast<Profile*>(context); |
| 93 if (profile->IsOffTheRecord()) | 114 if (profile->IsOffTheRecord()) |
| 94 return; | 115 return; |
| 95 ConnectorMap::iterator it = connectors_.find(profile); | 116 ConnectorMap::iterator it = connectors_.find(profile); |
| 96 if (it != connectors_.end()) | 117 if (it != connectors_.end()) |
| 97 it->second->Shutdown(); | 118 it->second->Shutdown(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 120 #endif | 141 #endif |
| 121 } | 142 } |
| 122 | 143 |
| 123 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( | 144 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( |
| 124 content::BrowserContext* context) {} | 145 content::BrowserContext* context) {} |
| 125 | 146 |
| 126 void ProfilePolicyConnectorFactory::CreateServiceNow( | 147 void ProfilePolicyConnectorFactory::CreateServiceNow( |
| 127 content::BrowserContext* context) {} | 148 content::BrowserContext* context) {} |
| 128 | 149 |
| 129 } // namespace policy | 150 } // namespace policy |
| OLD | NEW |