| 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 "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 global_user_cloud_policy_provider_ = new ProxyPolicyProvider(); | 142 global_user_cloud_policy_provider_ = new ProxyPolicyProvider(); |
| 143 AddPolicyProvider(scoped_ptr<ConfigurationPolicyProvider>( | 143 AddPolicyProvider(scoped_ptr<ConfigurationPolicyProvider>( |
| 144 global_user_cloud_policy_provider_)); | 144 global_user_cloud_policy_provider_)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 BrowserPolicyConnectorChromeOS::~BrowserPolicyConnectorChromeOS() {} | 147 BrowserPolicyConnectorChromeOS::~BrowserPolicyConnectorChromeOS() {} |
| 148 | 148 |
| 149 void BrowserPolicyConnectorChromeOS::Init( | 149 void BrowserPolicyConnectorChromeOS::Init( |
| 150 PrefService* local_state, | 150 PrefService* local_state, |
| 151 scoped_refptr<net::URLRequestContextGetter> request_context) { | 151 scoped_refptr<net::URLRequestContextGetter> request_context) { |
| 152 local_state_ = local_state; |
| 152 ChromeBrowserPolicyConnector::Init(local_state, request_context); | 153 ChromeBrowserPolicyConnector::Init(local_state, request_context); |
| 153 | 154 |
| 154 const base::CommandLine* command_line = | 155 const base::CommandLine* command_line = |
| 155 base::CommandLine::ForCurrentProcess(); | 156 base::CommandLine::ForCurrentProcess(); |
| 156 if (command_line->HasSwitch(chromeos::switches::kEnableConsumerManagement)) { | 157 if (command_line->HasSwitch(chromeos::switches::kEnableConsumerManagement)) { |
| 157 scoped_ptr<DeviceManagementService::Configuration> configuration( | 158 scoped_ptr<DeviceManagementService::Configuration> configuration( |
| 158 new DeviceManagementServiceConfiguration( | 159 new DeviceManagementServiceConfiguration( |
| 159 GetDeviceManagementServerUrlForConsumer())); | 160 GetDeviceManagementServerUrlForConsumer())); |
| 160 consumer_device_management_service_.reset( | 161 consumer_device_management_service_.reset( |
| 161 new DeviceManagementService(configuration.Pass())); | 162 new DeviceManagementService(configuration.Pass())); |
| 162 consumer_device_management_service_->ScheduleInitialization( | 163 consumer_device_management_service_->ScheduleInitialization( |
| 163 kServiceInitializationStartupDelay); | 164 kServiceInitializationStartupDelay); |
| 164 } | 165 } |
| 165 | 166 |
| 166 if (device_cloud_policy_manager_) { | 167 if (device_cloud_policy_manager_) { |
| 167 // Note: for now the |device_cloud_policy_manager_| is using the global | 168 // Note: for now the |device_cloud_policy_manager_| is using the global |
| 168 // schema registry. Eventually it will have its own registry, once device | 169 // schema registry. Eventually it will have its own registry, once device |
| 169 // cloud policy for extensions is introduced. That means it'd have to be | 170 // cloud policy for extensions is introduced. That means it'd have to be |
| 170 // initialized from here instead of BrowserPolicyConnector::Init(). | 171 // initialized from here instead of BrowserPolicyConnector::Init(). |
| 171 | 172 |
| 172 device_cloud_policy_manager_->Initialize(local_state); | 173 device_cloud_policy_manager_->Initialize(local_state); |
| 173 device_cloud_policy_manager_->AddDeviceCloudPolicyManagerObserver(this); | 174 device_cloud_policy_manager_->AddDeviceCloudPolicyManagerObserver(this); |
| 174 | 175 RestartDeviceCloudPolicyInitializer(); |
| 175 device_cloud_policy_initializer_.reset( | |
| 176 new DeviceCloudPolicyInitializer( | |
| 177 local_state, | |
| 178 device_management_service(), | |
| 179 consumer_device_management_service_.get(), | |
| 180 GetBackgroundTaskRunner(), | |
| 181 install_attributes_.get(), | |
| 182 state_keys_broker_.get(), | |
| 183 device_cloud_policy_manager_->device_store(), | |
| 184 device_cloud_policy_manager_)); | |
| 185 device_cloud_policy_initializer_->Init(); | |
| 186 } | 176 } |
| 187 | 177 |
| 188 device_local_account_policy_service_.reset( | 178 device_local_account_policy_service_.reset( |
| 189 new DeviceLocalAccountPolicyService( | 179 new DeviceLocalAccountPolicyService( |
| 190 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | 180 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| 191 chromeos::DeviceSettingsService::Get(), | 181 chromeos::DeviceSettingsService::Get(), |
| 192 chromeos::CrosSettings::Get(), | 182 chromeos::CrosSettings::Get(), |
| 193 GetBackgroundTaskRunner(), | 183 GetBackgroundTaskRunner(), |
| 194 GetBackgroundTaskRunner(), | 184 GetBackgroundTaskRunner(), |
| 195 GetBackgroundTaskRunner(), | 185 GetBackgroundTaskRunner(), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 298 |
| 309 // static | 299 // static |
| 310 void BrowserPolicyConnectorChromeOS::RegisterPrefs( | 300 void BrowserPolicyConnectorChromeOS::RegisterPrefs( |
| 311 PrefRegistrySimple* registry) { | 301 PrefRegistrySimple* registry) { |
| 312 registry->RegisterIntegerPref( | 302 registry->RegisterIntegerPref( |
| 313 prefs::kDevicePolicyRefreshRate, | 303 prefs::kDevicePolicyRefreshRate, |
| 314 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); | 304 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); |
| 315 } | 305 } |
| 316 | 306 |
| 317 void BrowserPolicyConnectorChromeOS::OnDeviceCloudPolicyManagerConnected() { | 307 void BrowserPolicyConnectorChromeOS::OnDeviceCloudPolicyManagerConnected() { |
| 308 CHECK(device_cloud_policy_initializer_); |
| 309 |
| 318 // DeviceCloudPolicyInitializer might still be on the call stack, so we | 310 // DeviceCloudPolicyInitializer might still be on the call stack, so we |
| 319 // should release the initializer after this function returns. | 311 // should release the initializer after this function returns. |
| 320 if (device_cloud_policy_initializer_) { | 312 device_cloud_policy_initializer_->Shutdown(); |
| 321 device_cloud_policy_initializer_->Shutdown(); | 313 base::MessageLoop::current()->DeleteSoon( |
| 322 base::MessageLoop::current()->DeleteSoon( | 314 FROM_HERE, device_cloud_policy_initializer_.release()); |
| 323 FROM_HERE, device_cloud_policy_initializer_.release()); | 315 } |
| 324 } | 316 |
| 317 void BrowserPolicyConnectorChromeOS::OnDeviceCloudPolicyManagerDisconnected() { |
| 318 DCHECK(!device_cloud_policy_initializer_); |
| 319 |
| 320 RestartDeviceCloudPolicyInitializer(); |
| 325 } | 321 } |
| 326 | 322 |
| 327 void BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable() { | 323 void BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable() { |
| 328 typedef chromeos::CrosSettingsProvider Provider; | 324 typedef chromeos::CrosSettingsProvider Provider; |
| 329 Provider::TrustedStatus result = | 325 Provider::TrustedStatus result = |
| 330 chromeos::CrosSettings::Get()->PrepareTrustedValues(base::Bind( | 326 chromeos::CrosSettings::Get()->PrepareTrustedValues(base::Bind( |
| 331 &BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable, | 327 &BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable, |
| 332 weak_ptr_factory_.GetWeakPtr())); | 328 weak_ptr_factory_.GetWeakPtr())); |
| 333 | 329 |
| 334 if (result != Provider::TRUSTED) | 330 if (result != Provider::TRUSTED) |
| 335 return; | 331 return; |
| 336 | 332 |
| 337 std::string timezone; | 333 std::string timezone; |
| 338 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, | 334 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, |
| 339 &timezone) && | 335 &timezone) && |
| 340 !timezone.empty()) { | 336 !timezone.empty()) { |
| 341 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | 337 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 342 base::UTF8ToUTF16(timezone)); | 338 base::UTF8ToUTF16(timezone)); |
| 343 } | 339 } |
| 344 } | 340 } |
| 345 | 341 |
| 342 void BrowserPolicyConnectorChromeOS::RestartDeviceCloudPolicyInitializer() { |
| 343 device_cloud_policy_initializer_.reset( |
| 344 new DeviceCloudPolicyInitializer( |
| 345 local_state_, |
| 346 device_management_service(), |
| 347 consumer_device_management_service_.get(), |
| 348 GetBackgroundTaskRunner(), |
| 349 install_attributes_.get(), |
| 350 state_keys_broker_.get(), |
| 351 device_cloud_policy_manager_->device_store(), |
| 352 device_cloud_policy_manager_)); |
| 353 device_cloud_policy_initializer_->Init(); |
| 354 } |
| 355 |
| 346 } // namespace policy | 356 } // namespace policy |
| OLD | NEW |