| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/policy/browser_policy_connector_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "chrome/browser/chromeos/policy/affiliated_cloud_policy_invalidator.h" | 21 #include "chrome/browser/chromeos/policy/affiliated_cloud_policy_invalidator.h" |
| 22 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r.h" | 22 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r.h" |
| 23 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r_impl.h" | 23 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r_impl.h" |
| 24 #include "chrome/browser/chromeos/policy/bluetooth_policy_handler.h" | 24 #include "chrome/browser/chromeos/policy/bluetooth_policy_handler.h" |
| 25 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 26 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 25 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 27 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 26 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 28 #include "chrome/browser/chromeos/policy/device_local_account.h" | 27 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 29 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 28 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 30 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" | 29 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" |
| 31 #include "chrome/browser/chromeos/policy/enrollment_config.h" | 30 #include "chrome/browser/chromeos/policy/enrollment_config.h" |
| 32 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 31 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 33 #include "chrome/browser/chromeos/policy/remote_commands/affiliated_remote_comma
nds_invalidator.h" | 32 #include "chrome/browser/chromeos/policy/remote_commands/affiliated_remote_comma
nds_invalidator.h" |
| 34 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 33 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
| 35 #include "chrome/browser/chromeos/settings/cros_settings.h" | 34 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 #include "google_apis/gaia/gaia_auth_util.h" | 53 #include "google_apis/gaia/gaia_auth_util.h" |
| 55 #include "net/url_request/url_request_context_getter.h" | 54 #include "net/url_request/url_request_context_getter.h" |
| 56 #include "policy/proto/device_management_backend.pb.h" | 55 #include "policy/proto/device_management_backend.pb.h" |
| 57 | 56 |
| 58 using content::BrowserThread; | 57 using content::BrowserThread; |
| 59 | 58 |
| 60 namespace policy { | 59 namespace policy { |
| 61 | 60 |
| 62 namespace { | 61 namespace { |
| 63 | 62 |
| 64 // TODO(davidyu): Update the URL to the real one once it is ready. | |
| 65 // http://crbug.com/366491. | |
| 66 // | |
| 67 // The URL for the consumer device management server. | |
| 68 const char kDefaultConsumerDeviceManagementServerUrl[] = | |
| 69 "https://m.google.com/devicemanagement/data/api"; | |
| 70 | |
| 71 // Install attributes for tests. | 63 // Install attributes for tests. |
| 72 EnterpriseInstallAttributes* g_testing_install_attributes = NULL; | 64 EnterpriseInstallAttributes* g_testing_install_attributes = NULL; |
| 73 | 65 |
| 74 // Helper that returns a new SequencedTaskRunner backed by the blocking pool. | 66 // Helper that returns a new SequencedTaskRunner backed by the blocking pool. |
| 75 // Each SequencedTaskRunner returned is independent from the others. | 67 // Each SequencedTaskRunner returned is independent from the others. |
| 76 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { | 68 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { |
| 77 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 69 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 78 CHECK(pool); | 70 CHECK(pool); |
| 79 return pool->GetSequencedTaskRunnerWithShutdownBehavior( | 71 return pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 80 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 72 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 81 } | 73 } |
| 82 | 74 |
| 83 std::string GetDeviceManagementServerUrlForConsumer() { | |
| 84 const base::CommandLine* command_line = | |
| 85 base::CommandLine::ForCurrentProcess(); | |
| 86 if (command_line->HasSwitch( | |
| 87 chromeos::switches::kConsumerDeviceManagementUrl)) { | |
| 88 return command_line->GetSwitchValueASCII( | |
| 89 chromeos::switches::kConsumerDeviceManagementUrl); | |
| 90 } | |
| 91 return kDefaultConsumerDeviceManagementServerUrl; | |
| 92 } | |
| 93 | |
| 94 } // namespace | 75 } // namespace |
| 95 | 76 |
| 96 BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS() | 77 BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS() |
| 97 : device_cloud_policy_manager_(NULL), | 78 : device_cloud_policy_manager_(NULL), |
| 98 global_user_cloud_policy_provider_(NULL), | 79 global_user_cloud_policy_provider_(NULL), |
| 99 weak_ptr_factory_(this) { | 80 weak_ptr_factory_(this) { |
| 100 if (g_testing_install_attributes) { | 81 if (g_testing_install_attributes) { |
| 101 install_attributes_.reset(g_testing_install_attributes); | 82 install_attributes_.reset(g_testing_install_attributes); |
| 102 g_testing_install_attributes = NULL; | 83 g_testing_install_attributes = NULL; |
| 103 } | 84 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 119 // been injected. | 100 // been injected. |
| 120 if (!install_attributes_) { | 101 if (!install_attributes_) { |
| 121 install_attributes_.reset( | 102 install_attributes_.reset( |
| 122 new EnterpriseInstallAttributes(cryptohome_client)); | 103 new EnterpriseInstallAttributes(cryptohome_client)); |
| 123 base::FilePath install_attrs_file; | 104 base::FilePath install_attrs_file; |
| 124 CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, | 105 CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, |
| 125 &install_attrs_file)); | 106 &install_attrs_file)); |
| 126 install_attributes_->Init(install_attrs_file); | 107 install_attributes_->Init(install_attrs_file); |
| 127 } | 108 } |
| 128 | 109 |
| 129 const base::CommandLine* command_line = | |
| 130 base::CommandLine::ForCurrentProcess(); | |
| 131 if (command_line->HasSwitch( | |
| 132 chromeos::switches::kEnableConsumerManagement)) { | |
| 133 consumer_management_service_.reset( | |
| 134 new ConsumerManagementService( | |
| 135 cryptohome_client, | |
| 136 chromeos::DeviceSettingsService::Get())); | |
| 137 } | |
| 138 | |
| 139 std::unique_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store( | 110 std::unique_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store( |
| 140 new DeviceCloudPolicyStoreChromeOS( | 111 new DeviceCloudPolicyStoreChromeOS( |
| 141 chromeos::DeviceSettingsService::Get(), install_attributes_.get(), | 112 chromeos::DeviceSettingsService::Get(), install_attributes_.get(), |
| 142 GetBackgroundTaskRunner())); | 113 GetBackgroundTaskRunner())); |
| 143 device_cloud_policy_manager_ = new DeviceCloudPolicyManagerChromeOS( | 114 device_cloud_policy_manager_ = new DeviceCloudPolicyManagerChromeOS( |
| 144 std::move(device_cloud_policy_store), | 115 std::move(device_cloud_policy_store), |
| 145 base::ThreadTaskRunnerHandle::Get(), state_keys_broker_.get()); | 116 base::ThreadTaskRunnerHandle::Get(), state_keys_broker_.get()); |
| 146 AddPolicyProvider(std::unique_ptr<ConfigurationPolicyProvider>( | 117 AddPolicyProvider(std::unique_ptr<ConfigurationPolicyProvider>( |
| 147 device_cloud_policy_manager_)); | 118 device_cloud_policy_manager_)); |
| 148 } | 119 } |
| 149 | 120 |
| 150 global_user_cloud_policy_provider_ = new ProxyPolicyProvider(); | 121 global_user_cloud_policy_provider_ = new ProxyPolicyProvider(); |
| 151 AddPolicyProvider(std::unique_ptr<ConfigurationPolicyProvider>( | 122 AddPolicyProvider(std::unique_ptr<ConfigurationPolicyProvider>( |
| 152 global_user_cloud_policy_provider_)); | 123 global_user_cloud_policy_provider_)); |
| 153 } | 124 } |
| 154 | 125 |
| 155 BrowserPolicyConnectorChromeOS::~BrowserPolicyConnectorChromeOS() {} | 126 BrowserPolicyConnectorChromeOS::~BrowserPolicyConnectorChromeOS() {} |
| 156 | 127 |
| 157 void BrowserPolicyConnectorChromeOS::Init( | 128 void BrowserPolicyConnectorChromeOS::Init( |
| 158 PrefService* local_state, | 129 PrefService* local_state, |
| 159 scoped_refptr<net::URLRequestContextGetter> request_context) { | 130 scoped_refptr<net::URLRequestContextGetter> request_context) { |
| 160 local_state_ = local_state; | 131 local_state_ = local_state; |
| 161 ChromeBrowserPolicyConnector::Init(local_state, request_context); | 132 ChromeBrowserPolicyConnector::Init(local_state, request_context); |
| 162 | 133 |
| 163 affiliated_invalidation_service_provider_.reset( | 134 affiliated_invalidation_service_provider_.reset( |
| 164 new AffiliatedInvalidationServiceProviderImpl); | 135 new AffiliatedInvalidationServiceProviderImpl); |
| 165 | 136 |
| 166 const base::CommandLine* command_line = | |
| 167 base::CommandLine::ForCurrentProcess(); | |
| 168 if (command_line->HasSwitch(chromeos::switches::kEnableConsumerManagement)) { | |
| 169 std::unique_ptr<DeviceManagementService::Configuration> configuration( | |
| 170 new DeviceManagementServiceConfiguration( | |
| 171 GetDeviceManagementServerUrlForConsumer())); | |
| 172 consumer_device_management_service_.reset( | |
| 173 new DeviceManagementService(std::move(configuration))); | |
| 174 consumer_device_management_service_->ScheduleInitialization( | |
| 175 kServiceInitializationStartupDelay); | |
| 176 } | |
| 177 | |
| 178 if (device_cloud_policy_manager_) { | 137 if (device_cloud_policy_manager_) { |
| 179 // Note: for now the |device_cloud_policy_manager_| is using the global | 138 // Note: for now the |device_cloud_policy_manager_| is using the global |
| 180 // schema registry. Eventually it will have its own registry, once device | 139 // schema registry. Eventually it will have its own registry, once device |
| 181 // cloud policy for extensions is introduced. That means it'd have to be | 140 // cloud policy for extensions is introduced. That means it'd have to be |
| 182 // initialized from here instead of BrowserPolicyConnector::Init(). | 141 // initialized from here instead of BrowserPolicyConnector::Init(). |
| 183 | 142 |
| 184 device_cloud_policy_manager_->Initialize(local_state); | 143 device_cloud_policy_manager_->Initialize(local_state); |
| 185 device_cloud_policy_manager_->AddDeviceCloudPolicyManagerObserver(this); | 144 device_cloud_policy_manager_->AddDeviceCloudPolicyManagerObserver(this); |
| 186 RestartDeviceCloudPolicyInitializer(); | 145 RestartDeviceCloudPolicyInitializer(); |
| 187 } | 146 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return device_cloud_policy_initializer_->GetPrescribedEnrollmentConfig(); | 244 return device_cloud_policy_initializer_->GetPrescribedEnrollmentConfig(); |
| 286 | 245 |
| 287 return EnrollmentConfig(); | 246 return EnrollmentConfig(); |
| 288 } | 247 } |
| 289 | 248 |
| 290 void BrowserPolicyConnectorChromeOS::SetUserPolicyDelegate( | 249 void BrowserPolicyConnectorChromeOS::SetUserPolicyDelegate( |
| 291 ConfigurationPolicyProvider* user_policy_provider) { | 250 ConfigurationPolicyProvider* user_policy_provider) { |
| 292 global_user_cloud_policy_provider_->SetDelegate(user_policy_provider); | 251 global_user_cloud_policy_provider_->SetDelegate(user_policy_provider); |
| 293 } | 252 } |
| 294 | 253 |
| 295 void BrowserPolicyConnectorChromeOS::SetConsumerManagementServiceForTesting( | |
| 296 std::unique_ptr<ConsumerManagementService> service) { | |
| 297 consumer_management_service_ = std::move(service); | |
| 298 } | |
| 299 | |
| 300 void BrowserPolicyConnectorChromeOS::SetDeviceCloudPolicyInitializerForTesting( | 254 void BrowserPolicyConnectorChromeOS::SetDeviceCloudPolicyInitializerForTesting( |
| 301 std::unique_ptr<DeviceCloudPolicyInitializer> initializer) { | 255 std::unique_ptr<DeviceCloudPolicyInitializer> initializer) { |
| 302 device_cloud_policy_initializer_ = std::move(initializer); | 256 device_cloud_policy_initializer_ = std::move(initializer); |
| 303 } | 257 } |
| 304 | 258 |
| 305 // static | 259 // static |
| 306 void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( | 260 void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( |
| 307 EnterpriseInstallAttributes* attributes) { | 261 EnterpriseInstallAttributes* attributes) { |
| 308 DCHECK(!g_testing_install_attributes); | 262 DCHECK(!g_testing_install_attributes); |
| 309 g_testing_install_attributes = attributes; | 263 g_testing_install_attributes = attributes; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | 312 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 359 base::UTF8ToUTF16(timezone)); | 313 base::UTF8ToUTF16(timezone)); |
| 360 } | 314 } |
| 361 } | 315 } |
| 362 | 316 |
| 363 void BrowserPolicyConnectorChromeOS::RestartDeviceCloudPolicyInitializer() { | 317 void BrowserPolicyConnectorChromeOS::RestartDeviceCloudPolicyInitializer() { |
| 364 device_cloud_policy_initializer_.reset( | 318 device_cloud_policy_initializer_.reset( |
| 365 new DeviceCloudPolicyInitializer( | 319 new DeviceCloudPolicyInitializer( |
| 366 local_state_, | 320 local_state_, |
| 367 device_management_service(), | 321 device_management_service(), |
| 368 consumer_device_management_service_.get(), | |
| 369 GetBackgroundTaskRunner(), | 322 GetBackgroundTaskRunner(), |
| 370 install_attributes_.get(), | 323 install_attributes_.get(), |
| 371 state_keys_broker_.get(), | 324 state_keys_broker_.get(), |
| 372 device_cloud_policy_manager_->device_store(), | 325 device_cloud_policy_manager_->device_store(), |
| 373 device_cloud_policy_manager_)); | 326 device_cloud_policy_manager_)); |
| 374 device_cloud_policy_initializer_->Init(); | 327 device_cloud_policy_initializer_->Init(); |
| 375 } | 328 } |
| 376 | 329 |
| 377 chromeos::AffiliationIDSet | 330 chromeos::AffiliationIDSet |
| 378 BrowserPolicyConnectorChromeOS::GetDeviceAffiliationIDs() const { | 331 BrowserPolicyConnectorChromeOS::GetDeviceAffiliationIDs() const { |
| 379 chromeos::AffiliationIDSet affiliation_ids; | 332 chromeos::AffiliationIDSet affiliation_ids; |
| 380 if (device_cloud_policy_manager_) { | 333 if (device_cloud_policy_manager_) { |
| 381 const enterprise_management::PolicyData* const policy_data = | 334 const enterprise_management::PolicyData* const policy_data = |
| 382 device_cloud_policy_manager_->device_store()->policy(); | 335 device_cloud_policy_manager_->device_store()->policy(); |
| 383 if (policy_data) { | 336 if (policy_data) { |
| 384 affiliation_ids.insert(policy_data->device_affiliation_ids().begin(), | 337 affiliation_ids.insert(policy_data->device_affiliation_ids().begin(), |
| 385 policy_data->device_affiliation_ids().end()); | 338 policy_data->device_affiliation_ids().end()); |
| 386 } | 339 } |
| 387 } | 340 } |
| 388 return affiliation_ids; | 341 return affiliation_ids; |
| 389 } | 342 } |
| 390 | 343 |
| 391 } // namespace policy | 344 } // namespace policy |
| OLD | NEW |