| 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.h" | 5 #include "chrome/browser/policy/profile_policy_connector.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | 12 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 13 #include "chrome/browser/policy/policy_service_impl.h" | 13 #include "chrome/browser/policy/policy_service.h" |
| 14 | 14 |
| 15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 16 #include "base/bind.h" | |
| 17 #include "base/prefs/pref_service.h" | |
| 18 #include "chrome/browser/chromeos/login/user.h" | 16 #include "chrome/browser/chromeos/login/user.h" |
| 19 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 20 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 18 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| 21 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" | 19 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" |
| 22 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 23 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | |
| 24 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | |
| 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 26 #include "chrome/browser/policy/policy_service.h" | |
| 27 #include "chrome/common/pref_names.h" | |
| 28 #include "chromeos/network/network_handler.h" | |
| 29 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | |
| 30 #else | 21 #else |
| 31 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 22 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
| 32 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | |
| 33 #endif | 23 #endif |
| 34 | 24 |
| 35 namespace policy { | 25 namespace policy { |
| 36 | 26 |
| 37 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) | 27 ProfilePolicyConnector::ProfilePolicyConnector() |
| 38 : | |
| 39 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 40 is_primary_user_(false), | 29 : is_primary_user_(false) |
| 41 weak_ptr_factory_(this), | |
| 42 #endif | 30 #endif |
| 43 profile_(profile) {} | 31 {} |
| 44 | 32 |
| 45 ProfilePolicyConnector::~ProfilePolicyConnector() {} | 33 ProfilePolicyConnector::~ProfilePolicyConnector() {} |
| 46 | 34 |
| 47 void ProfilePolicyConnector::Init(bool force_immediate_load) { | 35 void ProfilePolicyConnector::Init( |
| 36 bool force_immediate_load, |
| 37 #if defined(OS_CHROMEOS) |
| 38 const chromeos::User* user, |
| 39 #endif |
| 40 CloudPolicyManager* user_cloud_policy_manager) { |
| 48 BrowserPolicyConnector* connector = | 41 BrowserPolicyConnector* connector = |
| 49 g_browser_process->browser_policy_connector(); | 42 g_browser_process->browser_policy_connector(); |
| 50 // |providers| contains a list of the policy providers available for the | 43 // |providers| contains a list of the policy providers available for the |
| 51 // PolicyService of this connector. | 44 // PolicyService of this connector. |
| 52 std::vector<ConfigurationPolicyProvider*> providers; | 45 std::vector<ConfigurationPolicyProvider*> providers; |
| 53 | 46 |
| 47 if (user_cloud_policy_manager) |
| 48 providers.push_back(user_cloud_policy_manager); |
| 49 |
| 54 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 55 UserCloudPolicyManagerChromeOS* cloud_policy_manager = | 51 if (!user) { |
| 56 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile_); | 52 // This case occurs for the signin profile. |
| 57 if (cloud_policy_manager) | 53 special_user_policy_provider_.reset( |
| 58 providers.push_back(cloud_policy_manager); | 54 new LoginProfilePolicyProvider(connector->GetPolicyService())); |
| 59 | |
| 60 bool allow_trusted_certs_from_policy = false; | |
| 61 chromeos::User* user = NULL; | |
| 62 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) { | |
| 63 special_user_policy_provider_.reset(new LoginProfilePolicyProvider( | |
| 64 connector->GetPolicyService())); | |
| 65 special_user_policy_provider_->Init(); | 55 special_user_policy_provider_->Init(); |
| 66 } else { | 56 } else { |
| 67 // |user| should never be NULL except for the signin profile. | 57 // |user| should never be NULL except for the signin profile. |
| 68 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 58 is_primary_user_ = user == chromeos::UserManager::Get()->GetPrimaryUser(); |
| 69 user = user_manager->GetUserByProfile(profile_); | |
| 70 CHECK(user); | |
| 71 std::string username = user->email(); | |
| 72 is_primary_user_ = | |
| 73 chromeos::UserManager::Get()->GetLoggedInUsers().size() == 1; | |
| 74 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) | 59 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) |
| 75 InitializeDeviceLocalAccountPolicyProvider(username); | 60 InitializeDeviceLocalAccountPolicyProvider(user->email()); |
| 76 // Allow trusted certs from policy only for managed regular accounts. | |
| 77 const bool is_managed = | |
| 78 connector->GetUserAffiliation(username) == USER_AFFILIATION_MANAGED; | |
| 79 if (is_managed && user->GetType() == chromeos::User::USER_TYPE_REGULAR) | |
| 80 allow_trusted_certs_from_policy = true; | |
| 81 } | 61 } |
| 82 if (special_user_policy_provider_) | 62 if (special_user_policy_provider_) |
| 83 providers.push_back(special_user_policy_provider_.get()); | 63 providers.push_back(special_user_policy_provider_.get()); |
| 84 | |
| 85 #else | |
| 86 UserCloudPolicyManager* cloud_policy_manager = | |
| 87 UserCloudPolicyManagerFactory::GetForProfile(profile_); | |
| 88 if (cloud_policy_manager) | |
| 89 providers.push_back(cloud_policy_manager); | |
| 90 #endif | 64 #endif |
| 91 | 65 |
| 92 policy_service_ = connector->CreatePolicyService(providers); | 66 policy_service_ = connector->CreatePolicyService(providers); |
| 93 | 67 |
| 94 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
| 95 if (is_primary_user_) { | 69 if (is_primary_user_) { |
| 96 if (cloud_policy_manager) | 70 if (user_cloud_policy_manager) |
| 97 connector->SetUserPolicyDelegate(cloud_policy_manager); | 71 connector->SetUserPolicyDelegate(user_cloud_policy_manager); |
| 98 else if (special_user_policy_provider_) | 72 else if (special_user_policy_provider_) |
| 99 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); | 73 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); |
| 100 | |
| 101 // A reference to |user| is stored by the NetworkConfigurationUpdater until | |
| 102 // the Updater is destructed during Shutdown. | |
| 103 network_configuration_updater_ = | |
| 104 UserNetworkConfigurationUpdater::CreateForUserPolicy( | |
| 105 allow_trusted_certs_from_policy, | |
| 106 *user, | |
| 107 scoped_ptr<chromeos::onc::CertificateImporter>( | |
| 108 new chromeos::onc::CertificateImporterImpl), | |
| 109 policy_service(), | |
| 110 chromeos::NetworkHandler::Get() | |
| 111 ->managed_network_configuration_handler()); | |
| 112 } | 74 } |
| 113 #endif | 75 #endif |
| 114 } | 76 } |
| 115 | 77 |
| 116 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { | 78 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { |
| 117 policy_service_ = service.Pass(); | 79 policy_service_ = service.Pass(); |
| 118 } | 80 } |
| 119 | 81 |
| 120 void ProfilePolicyConnector::Shutdown() { | 82 void ProfilePolicyConnector::Shutdown() { |
| 121 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 122 if (is_primary_user_) | 84 if (is_primary_user_) |
| 123 g_browser_process->browser_policy_connector()->SetUserPolicyDelegate(NULL); | 85 g_browser_process->browser_policy_connector()->SetUserPolicyDelegate(NULL); |
| 124 network_configuration_updater_.reset(); | |
| 125 if (special_user_policy_provider_) | 86 if (special_user_policy_provider_) |
| 126 special_user_policy_provider_->Shutdown(); | 87 special_user_policy_provider_->Shutdown(); |
| 127 #endif | 88 #endif |
| 128 } | 89 } |
| 129 | 90 |
| 130 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 131 void ProfilePolicyConnector::SetPolicyCertVerifier( | |
| 132 PolicyCertVerifier* cert_verifier) { | |
| 133 if (network_configuration_updater_) | |
| 134 network_configuration_updater_->SetPolicyCertVerifier(cert_verifier); | |
| 135 } | |
| 136 | |
| 137 base::Closure ProfilePolicyConnector::GetPolicyCertTrustedCallback() { | |
| 138 return base::Bind(&ProfilePolicyConnector::SetUsedPolicyCertificatesOnce, | |
| 139 weak_ptr_factory_.GetWeakPtr()); | |
| 140 } | |
| 141 | |
| 142 void ProfilePolicyConnector::GetWebTrustedCertificates( | |
| 143 net::CertificateList* certs) const { | |
| 144 certs->clear(); | |
| 145 if (network_configuration_updater_) | |
| 146 network_configuration_updater_->GetWebTrustedCertificates(certs); | |
| 147 } | |
| 148 #endif | |
| 149 | |
| 150 bool ProfilePolicyConnector::UsedPolicyCertificates() { | |
| 151 #if defined(OS_CHROMEOS) | |
| 152 return profile_->GetPrefs()->GetBoolean(prefs::kUsedPolicyCertificatesOnce); | |
| 153 #else | |
| 154 return false; | |
| 155 #endif | |
| 156 } | |
| 157 | |
| 158 #if defined(OS_CHROMEOS) | |
| 159 void ProfilePolicyConnector::SetUsedPolicyCertificatesOnce() { | |
| 160 profile_->GetPrefs()->SetBoolean(prefs::kUsedPolicyCertificatesOnce, true); | |
| 161 } | |
| 162 | |
| 163 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( | 92 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( |
| 164 const std::string& username) { | 93 const std::string& username) { |
| 165 BrowserPolicyConnector* connector = | 94 BrowserPolicyConnector* connector = |
| 166 g_browser_process->browser_policy_connector(); | 95 g_browser_process->browser_policy_connector(); |
| 167 DeviceLocalAccountPolicyService* device_local_account_policy_service = | 96 DeviceLocalAccountPolicyService* device_local_account_policy_service = |
| 168 connector->GetDeviceLocalAccountPolicyService(); | 97 connector->GetDeviceLocalAccountPolicyService(); |
| 169 if (!device_local_account_policy_service) | 98 if (!device_local_account_policy_service) |
| 170 return; | 99 return; |
| 171 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( | 100 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( |
| 172 username, device_local_account_policy_service)); | 101 username, device_local_account_policy_service)); |
| 173 special_user_policy_provider_->Init(); | 102 special_user_policy_provider_->Init(); |
| 174 } | 103 } |
| 175 #endif | 104 #endif |
| 176 | 105 |
| 177 } // namespace policy | 106 } // namespace policy |
| OLD | NEW |