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.h" |
| 14 | 14 |
| 15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "chrome/browser/chromeos/login/user.h" | 18 #include "chrome/browser/chromeos/login/user.h" |
| 19 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
| 20 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 20 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| 21 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" | 21 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" |
| 22 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
|
Joao da Silva
2013/11/04 09:46:52
not needed, include chrome/browser/policy/cloud/cl
pneubeck (no reviews)
2013/11/04 13:11:52
Done.
| |
| 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" | 23 #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" | 24 #include "chrome/browser/policy/policy_service.h" |
| 27 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 28 #include "chromeos/network/network_handler.h" | 26 #include "chromeos/network/network_handler.h" |
| 29 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 27 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
| 30 #else | 28 #else |
| 31 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 29 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
|
Joao da Silva
2013/11/04 09:46:52
not needed
pneubeck (no reviews)
2013/11/04 13:11:52
Done.
| |
| 32 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | |
| 33 #endif | 30 #endif |
| 34 | 31 |
| 35 namespace policy { | 32 namespace policy { |
| 36 | 33 |
| 37 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) | 34 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) |
| 38 : | 35 : |
| 39 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 40 is_primary_user_(false), | 37 is_primary_user_(false), |
| 41 weak_ptr_factory_(this), | 38 weak_ptr_factory_(this), |
| 42 #endif | 39 #endif |
| 43 profile_(profile) {} | 40 profile_(profile) {} |
| 44 | 41 |
| 45 ProfilePolicyConnector::~ProfilePolicyConnector() {} | 42 ProfilePolicyConnector::~ProfilePolicyConnector() {} |
| 46 | 43 |
| 47 void ProfilePolicyConnector::Init(bool force_immediate_load) { | 44 void ProfilePolicyConnector::Init( |
| 45 bool force_immediate_load, | |
| 46 #if defined(OS_CHROMEOS) | |
| 47 const chromeos::User* user, | |
| 48 #endif | |
| 49 CloudPolicyManager* user_cloud_policy_manager) { | |
| 48 BrowserPolicyConnector* connector = | 50 BrowserPolicyConnector* connector = |
| 49 g_browser_process->browser_policy_connector(); | 51 g_browser_process->browser_policy_connector(); |
| 50 // |providers| contains a list of the policy providers available for the | 52 // |providers| contains a list of the policy providers available for the |
| 51 // PolicyService of this connector. | 53 // PolicyService of this connector. |
| 52 std::vector<ConfigurationPolicyProvider*> providers; | 54 std::vector<ConfigurationPolicyProvider*> providers; |
| 53 | 55 |
| 56 if (user_cloud_policy_manager) | |
| 57 providers.push_back(user_cloud_policy_manager); | |
| 58 | |
| 54 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
| 55 UserCloudPolicyManagerChromeOS* cloud_policy_manager = | |
| 56 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile_); | |
| 57 if (cloud_policy_manager) | |
| 58 providers.push_back(cloud_policy_manager); | |
| 59 | |
| 60 bool allow_trusted_certs_from_policy = false; | 60 bool allow_trusted_certs_from_policy = false; |
| 61 chromeos::User* user = NULL; | 61 if (!user) { |
| 62 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) { | 62 // This case occurs for the signin profile. |
| 63 special_user_policy_provider_.reset(new LoginProfilePolicyProvider( | 63 special_user_policy_provider_.reset( |
| 64 connector->GetPolicyService())); | 64 new LoginProfilePolicyProvider(connector->GetPolicyService())); |
| 65 special_user_policy_provider_->Init(); | 65 special_user_policy_provider_->Init(); |
| 66 } else { | 66 } else { |
| 67 // |user| should never be NULL except for the signin profile. | 67 // |user| should never be NULL except for the signin profile. |
| 68 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 68 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) | 69 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) |
| 75 InitializeDeviceLocalAccountPolicyProvider(username); | 70 InitializeDeviceLocalAccountPolicyProvider(user->email()); |
| 76 // Allow trusted certs from policy only for managed regular accounts. | 71 // Allow trusted certs from policy only for managed regular accounts. |
| 77 const bool is_managed = | 72 const bool is_managed = connector->GetUserAffiliation(user->email()) == |
| 78 connector->GetUserAffiliation(username) == USER_AFFILIATION_MANAGED; | 73 USER_AFFILIATION_MANAGED; |
| 79 if (is_managed && user->GetType() == chromeos::User::USER_TYPE_REGULAR) | 74 if (is_managed && user->GetType() == chromeos::User::USER_TYPE_REGULAR) |
| 80 allow_trusted_certs_from_policy = true; | 75 allow_trusted_certs_from_policy = true; |
| 81 } | 76 } |
| 82 if (special_user_policy_provider_) | 77 if (special_user_policy_provider_) |
| 83 providers.push_back(special_user_policy_provider_.get()); | 78 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 | 79 #endif |
| 91 | 80 |
| 92 policy_service_ = connector->CreatePolicyService(providers); | 81 policy_service_ = connector->CreatePolicyService(providers); |
| 93 | 82 |
| 94 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 95 if (is_primary_user_) { | 84 if (is_primary_user_) { |
| 96 if (cloud_policy_manager) | 85 if (user_cloud_policy_manager) |
| 97 connector->SetUserPolicyDelegate(cloud_policy_manager); | 86 connector->SetUserPolicyDelegate(user_cloud_policy_manager); |
| 98 else if (special_user_policy_provider_) | 87 else if (special_user_policy_provider_) |
| 99 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); | 88 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); |
| 100 | 89 |
| 101 // A reference to |user| is stored by the NetworkConfigurationUpdater until | |
| 102 // the Updater is destructed during Shutdown. | |
| 103 network_configuration_updater_ = | 90 network_configuration_updater_ = |
| 104 UserNetworkConfigurationUpdater::CreateForUserPolicy( | 91 UserNetworkConfigurationUpdater::CreateForUserPolicy( |
| 105 allow_trusted_certs_from_policy, | 92 allow_trusted_certs_from_policy, |
| 106 *user, | 93 *user, |
| 107 scoped_ptr<chromeos::onc::CertificateImporter>( | 94 scoped_ptr<chromeos::onc::CertificateImporter>( |
| 108 new chromeos::onc::CertificateImporterImpl), | 95 new chromeos::onc::CertificateImporterImpl), |
| 109 policy_service(), | 96 policy_service(), |
| 110 chromeos::NetworkHandler::Get() | 97 chromeos::NetworkHandler::Get() |
| 111 ->managed_network_configuration_handler()); | 98 ->managed_network_configuration_handler()); |
| 112 } | 99 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 connector->GetDeviceLocalAccountPolicyService(); | 155 connector->GetDeviceLocalAccountPolicyService(); |
| 169 if (!device_local_account_policy_service) | 156 if (!device_local_account_policy_service) |
| 170 return; | 157 return; |
| 171 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( | 158 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( |
| 172 username, device_local_account_policy_service)); | 159 username, device_local_account_policy_service)); |
| 173 special_user_policy_provider_->Init(); | 160 special_user_policy_provider_->Init(); |
| 174 } | 161 } |
| 175 #endif | 162 #endif |
| 176 | 163 |
| 177 } // namespace policy | 164 } // namespace policy |
| OLD | NEW |