| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/device_management_policy_provider.h" | 5 #include "chrome/browser/policy/device_management_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/policy/device_management_backend.h" | 13 #include "chrome/browser/policy/device_management_backend.h" |
| 15 #include "chrome/browser/policy/device_management_policy_cache.h" | 14 #include "chrome/browser/policy/device_management_policy_cache.h" |
| 16 #include "chrome/browser/policy/proto/device_management_constants.h" | 15 #include "chrome/browser/policy/proto/device_management_constants.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 | 23 |
| 24 namespace em = enterprise_management; | 24 namespace em = enterprise_management; |
| 25 | 25 |
| 26 const int64 kPolicyRefreshRateInMilliseconds = 3 * 60 * 60 * 1000; // 3 hours | 26 const int64 kPolicyRefreshRateInMilliseconds = 3 * 60 * 60 * 1000; // 3 hours |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} | 111 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} |
| 112 | 112 |
| 113 bool DeviceManagementPolicyProvider::Provide( | 113 bool DeviceManagementPolicyProvider::Provide( |
| 114 ConfigurationPolicyStoreInterface* policy_store) { | 114 ConfigurationPolicyStoreInterface* policy_store) { |
| 115 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); | 115 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); |
| 116 DecodePolicyValueTree(policies.get(), policy_store); | 116 DecodePolicyValueTree(policies.get(), policy_store); |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool DeviceManagementPolicyProvider::IsInitializationComplete() const { |
| 121 return !waiting_for_initial_policies_; |
| 122 } |
| 123 |
| 120 void DeviceManagementPolicyProvider::HandlePolicyResponse( | 124 void DeviceManagementPolicyProvider::HandlePolicyResponse( |
| 121 const em::DevicePolicyResponse& response) { | 125 const em::DevicePolicyResponse& response) { |
| 122 if (cache_->SetPolicy(response)) | 126 if (cache_->SetPolicy(response)) |
| 123 NotifyStoreOfPolicyChange(); | 127 NotifyStoreOfPolicyChange(); |
| 124 policy_request_pending_ = false; | 128 policy_request_pending_ = false; |
| 125 // Reset the error delay since policy fetching succeeded this time. | 129 // Reset the error delay since policy fetching succeeded this time. |
| 126 policy_refresh_error_delay_ms_ = kPolicyRefreshErrorDelayInMilliseconds; | 130 policy_refresh_error_delay_ms_ = kPolicyRefreshErrorDelayInMilliseconds; |
| 127 ScheduleRefreshTask(GetRefreshTaskDelay()); | 131 ScheduleRefreshTask(GetRefreshTaskDelay()); |
| 128 // Update this provider's internal waiting state, but don't notify anyone | 132 // Update this provider's internal waiting state, but don't notify anyone |
| 129 // else yet (that's done by the PrefValueStore that receives the policy). | 133 // else yet (that's done by the PrefValueStore that receives the policy). |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 317 } |
| 314 | 318 |
| 315 void DeviceManagementPolicyProvider::StopWaitingForInitialPolicies() { | 319 void DeviceManagementPolicyProvider::StopWaitingForInitialPolicies() { |
| 316 waiting_for_initial_policies_ = false; | 320 waiting_for_initial_policies_ = false; |
| 317 // Send a CLOUD_POLICY_UPDATE notification to unblock ChromeOS logins that | 321 // Send a CLOUD_POLICY_UPDATE notification to unblock ChromeOS logins that |
| 318 // are waiting for an initial policy fetch to complete. | 322 // are waiting for an initial policy fetch to complete. |
| 319 NotifyCloudPolicyUpdate(); | 323 NotifyCloudPolicyUpdate(); |
| 320 } | 324 } |
| 321 | 325 |
| 322 void DeviceManagementPolicyProvider::NotifyCloudPolicyUpdate() const { | 326 void DeviceManagementPolicyProvider::NotifyCloudPolicyUpdate() const { |
| 323 NotificationService::current()->Notify( | 327 NotificationService::current()->Notify( |
| 324 NotificationType::CLOUD_POLICY_UPDATE, | 328 NotificationType::CLOUD_POLICY_UPDATE, |
| 325 Source<DeviceManagementPolicyProvider>(this), | 329 Source<DeviceManagementPolicyProvider>(this), |
| 326 NotificationService::NoDetails()); | 330 NotificationService::NoDetails()); |
| 327 } | 331 } |
| 328 | 332 |
| 329 // static | 333 // static |
| 330 std::string DeviceManagementPolicyProvider::GetDeviceManagementURL() { | 334 std::string DeviceManagementPolicyProvider::GetDeviceManagementURL() { |
| 331 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 335 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 332 switches::kDeviceManagementUrl); | 336 switches::kDeviceManagementUrl); |
| 333 } | 337 } |
| 334 | 338 |
| 335 // static | 339 // static |
| 336 FilePath DeviceManagementPolicyProvider::GetOrCreateDeviceManagementDir( | 340 FilePath DeviceManagementPolicyProvider::GetOrCreateDeviceManagementDir( |
| 337 const FilePath& user_data_dir) { | 341 const FilePath& user_data_dir) { |
| 338 const FilePath device_management_dir = user_data_dir.Append( | 342 const FilePath device_management_dir = user_data_dir.Append( |
| 339 FILE_PATH_LITERAL("Device Management")); | 343 FILE_PATH_LITERAL("Device Management")); |
| 340 if (!file_util::DirectoryExists(device_management_dir)) { | 344 if (!file_util::DirectoryExists(device_management_dir)) { |
| 341 if (!file_util::CreateDirectory(device_management_dir)) | 345 if (!file_util::CreateDirectory(device_management_dir)) |
| 342 NOTREACHED(); | 346 NOTREACHED(); |
| 343 } | 347 } |
| 344 return device_management_dir; | 348 return device_management_dir; |
| 345 } | 349 } |
| 346 | 350 |
| 347 } // namespace policy | 351 } // namespace policy |
| OLD | NEW |