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