| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_policy_cache.h" | 5 #include "chrome/browser/policy/device_policy_cache.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/cros_settings.h" | 18 #include "chrome/browser/chromeos/cros_settings.h" |
| 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chrome/browser/chromeos/dbus/update_engine_client.h" | 20 #include "chrome/browser/chromeos/dbus/update_engine_client.h" |
| 21 #include "chrome/browser/chromeos/login/ownership_service.h" | 21 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 22 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | 22 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
| 23 #include "chrome/browser/policy/cloud_policy_data_store.h" | 23 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 24 #include "chrome/browser/policy/enterprise_install_attributes.h" | 24 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 25 #include "chrome/browser/policy/enterprise_metrics.h" | 25 #include "chrome/browser/policy/enterprise_metrics.h" |
| 26 #include "chrome/browser/policy/policy_map.h" | 26 #include "chrome/browser/policy/policy_map.h" |
| 27 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 27 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 28 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 28 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
| 29 #include "policy/configuration_policy_type.h" | |
| 30 | 29 |
| 31 namespace em = enterprise_management; | 30 namespace em = enterprise_management; |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 // Stores policy, updates the owner key if required and reports the status | 34 // Stores policy, updates the owner key if required and reports the status |
| 36 // through a callback. | 35 // through a callback. |
| 37 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { | 36 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { |
| 38 public: | 37 public: |
| 39 typedef base::Callback<void(chromeos::SignedSettings::ReturnCode)> Callback; | 38 typedef base::Callback<void(chromeos::SignedSettings::ReturnCode)> Callback; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 217 } |
| 219 bool ok = SetPolicyInternal(policy, NULL, false); | 218 bool ok = SetPolicyInternal(policy, NULL, false); |
| 220 if (ok) { | 219 if (ok) { |
| 221 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK, | 220 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK, |
| 222 kMetricPolicySize); | 221 kMetricPolicySize); |
| 223 } | 222 } |
| 224 } | 223 } |
| 225 } | 224 } |
| 226 | 225 |
| 227 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, | 226 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, |
| 228 PolicyMap* mandatory, | 227 PolicyMap* policies) { |
| 229 PolicyMap* recommended) { | |
| 230 em::ChromeDeviceSettingsProto policy; | 228 em::ChromeDeviceSettingsProto policy; |
| 231 if (!policy.ParseFromString(policy_data.policy_value())) { | 229 if (!policy.ParseFromString(policy_data.policy_value())) { |
| 232 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; | 230 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; |
| 233 return false; | 231 return false; |
| 234 } | 232 } |
| 235 DecodeDevicePolicy(policy, mandatory, recommended); | 233 DecodeDevicePolicy(policy, policies); |
| 236 return true; | 234 return true; |
| 237 } | 235 } |
| 238 | 236 |
| 239 void DevicePolicyCache::PolicyStoreOpCompleted( | 237 void DevicePolicyCache::PolicyStoreOpCompleted( |
| 240 chromeos::SignedSettings::ReturnCode code) { | 238 chromeos::SignedSettings::ReturnCode code) { |
| 241 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
| 242 if (code != chromeos::SignedSettings::SUCCESS) { | 240 if (code != chromeos::SignedSettings::SUCCESS) { |
| 243 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed, | 241 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed, |
| 244 kMetricPolicySize); | 242 kMetricPolicySize); |
| 245 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { | 243 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 data_store_->set_device_id(policy_data.device_id()); | 303 data_store_->set_device_id(policy_data.device_id()); |
| 306 *device_token = policy_data.request_token(); | 304 *device_token = policy_data.request_token(); |
| 307 base::Time timestamp; | 305 base::Time timestamp; |
| 308 if (SetPolicyInternal(policy, ×tamp, true)) | 306 if (SetPolicyInternal(policy, ×tamp, true)) |
| 309 set_last_policy_refresh_time(timestamp); | 307 set_last_policy_refresh_time(timestamp); |
| 310 } | 308 } |
| 311 | 309 |
| 312 // static | 310 // static |
| 313 void DevicePolicyCache::DecodeDevicePolicy( | 311 void DevicePolicyCache::DecodeDevicePolicy( |
| 314 const em::ChromeDeviceSettingsProto& policy, | 312 const em::ChromeDeviceSettingsProto& policy, |
| 315 PolicyMap* mandatory, | 313 PolicyMap* policies) { |
| 316 PolicyMap* recommended) { | |
| 317 if (policy.has_device_policy_refresh_rate()) { | 314 if (policy.has_device_policy_refresh_rate()) { |
| 318 const em::DevicePolicyRefreshRateProto container = | 315 const em::DevicePolicyRefreshRateProto container = |
| 319 policy.device_policy_refresh_rate(); | 316 policy.device_policy_refresh_rate(); |
| 320 if (container.has_device_policy_refresh_rate()) { | 317 if (container.has_device_policy_refresh_rate()) { |
| 321 mandatory->Set(kPolicyDevicePolicyRefreshRate, | 318 policies->Set(key::kDevicePolicyRefreshRate, |
| 322 DecodeIntegerValue( | 319 POLICY_LEVEL_MANDATORY, |
| 323 container.device_policy_refresh_rate())); | 320 POLICY_SCOPE_DEVICE, |
| 321 DecodeIntegerValue(container.device_policy_refresh_rate())); |
| 324 } | 322 } |
| 325 } | 323 } |
| 326 | 324 |
| 327 if (policy.has_device_proxy_settings()) { | 325 if (policy.has_device_proxy_settings()) { |
| 328 const em::DeviceProxySettingsProto container = | 326 const em::DeviceProxySettingsProto container = |
| 329 policy.device_proxy_settings(); | 327 policy.device_proxy_settings(); |
| 330 if (container.has_proxy_mode()) { | 328 if (container.has_proxy_mode()) { |
| 331 recommended->Set(kPolicyProxyMode, | 329 policies->Set(key::kProxyMode, |
| 332 Value::CreateStringValue(container.proxy_mode())); | 330 POLICY_LEVEL_RECOMMENDED, |
| 331 POLICY_SCOPE_DEVICE, |
| 332 Value::CreateStringValue(container.proxy_mode())); |
| 333 } | 333 } |
| 334 if (container.has_proxy_server()) { | 334 if (container.has_proxy_server()) { |
| 335 recommended->Set(kPolicyProxyServer, | 335 policies->Set(key::kProxyServer, |
| 336 Value::CreateStringValue(container.proxy_server())); | 336 POLICY_LEVEL_RECOMMENDED, |
| 337 POLICY_SCOPE_DEVICE, |
| 338 Value::CreateStringValue(container.proxy_server())); |
| 337 } | 339 } |
| 338 if (container.has_proxy_pac_url()) { | 340 if (container.has_proxy_pac_url()) { |
| 339 recommended->Set(kPolicyProxyPacUrl, | 341 policies->Set(key::kProxyPacUrl, |
| 340 Value::CreateStringValue(container.proxy_pac_url())); | 342 POLICY_LEVEL_RECOMMENDED, |
| 343 POLICY_SCOPE_DEVICE, |
| 344 Value::CreateStringValue(container.proxy_pac_url())); |
| 341 } | 345 } |
| 342 if (container.has_proxy_bypass_list()) { | 346 if (container.has_proxy_bypass_list()) { |
| 343 recommended->Set(kPolicyProxyBypassList, | 347 policies->Set(key::kProxyBypassList, |
| 344 Value::CreateStringValue(container.proxy_bypass_list())); | 348 POLICY_LEVEL_RECOMMENDED, |
| 349 POLICY_SCOPE_DEVICE, |
| 350 Value::CreateStringValue(container.proxy_bypass_list())); |
| 345 } | 351 } |
| 346 } | 352 } |
| 347 | 353 |
| 348 if (policy.has_release_channel() && | 354 if (policy.has_release_channel() && |
| 349 policy.release_channel().has_release_channel()) { | 355 policy.release_channel().has_release_channel()) { |
| 350 std::string channel(policy.release_channel().release_channel()); | 356 std::string channel(policy.release_channel().release_channel()); |
| 351 mandatory->Set(kPolicyChromeOsReleaseChannel, | 357 policies->Set(key::kChromeOsReleaseChannel, |
| 352 Value::CreateStringValue(channel)); | 358 POLICY_LEVEL_MANDATORY, |
| 359 POLICY_SCOPE_DEVICE, |
| 360 Value::CreateStringValue(channel)); |
| 353 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't | 361 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't |
| 354 // have to pass the channel in here, only ping the update engine to tell | 362 // have to pass the channel in here, only ping the update engine to tell |
| 355 // it to fetch the channel from the policy. | 363 // it to fetch the channel from the policy. |
| 356 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient() | 364 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient() |
| 357 ->SetReleaseTrack(channel); | 365 ->SetReleaseTrack(channel); |
| 358 } | 366 } |
| 359 | 367 |
| 360 if (policy.has_open_network_configuration() && | 368 if (policy.has_open_network_configuration() && |
| 361 policy.open_network_configuration().has_open_network_configuration()) { | 369 policy.open_network_configuration().has_open_network_configuration()) { |
| 362 std::string config( | 370 std::string config( |
| 363 policy.open_network_configuration().open_network_configuration()); | 371 policy.open_network_configuration().open_network_configuration()); |
| 364 mandatory->Set(kPolicyDeviceOpenNetworkConfiguration, | 372 policies->Set(key::kDeviceOpenNetworkConfiguration, |
| 365 Value::CreateStringValue(config)); | 373 POLICY_LEVEL_MANDATORY, |
| 374 POLICY_SCOPE_DEVICE, |
| 375 Value::CreateStringValue(config)); |
| 366 } | 376 } |
| 367 } | 377 } |
| 368 | 378 |
| 369 } // namespace policy | 379 } // namespace policy |
| OLD | NEW |