Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/policy/device_policy_cache.cc

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed builds, rebased Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 29 #include "policy/policy_constants.h"
30 30
31 namespace em = enterprise_management; 31 namespace em = enterprise_management;
32 32
33 namespace { 33 namespace {
34 34
35 // Stores policy, updates the owner key if required and reports the status 35 // Stores policy, updates the owner key if required and reports the status
36 // through a callback. 36 // through a callback.
37 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { 37 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate {
38 public: 38 public:
39 typedef base::Callback<void(chromeos::SignedSettings::ReturnCode)> Callback; 39 typedef base::Callback<void(chromeos::SignedSettings::ReturnCode)> Callback;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 bool ok = SetPolicyInternal(policy, NULL, false); 219 bool ok = SetPolicyInternal(policy, NULL, false);
220 if (ok) { 220 if (ok) {
221 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK, 221 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK,
222 kMetricPolicySize); 222 kMetricPolicySize);
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, 227 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data,
228 PolicyMap* mandatory, 228 PolicyMap* policies) {
229 PolicyMap* recommended) {
230 em::ChromeDeviceSettingsProto policy; 229 em::ChromeDeviceSettingsProto policy;
231 if (!policy.ParseFromString(policy_data.policy_value())) { 230 if (!policy.ParseFromString(policy_data.policy_value())) {
232 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; 231 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto.";
233 return false; 232 return false;
234 } 233 }
235 DecodeDevicePolicy(policy, mandatory, recommended); 234 DecodeDevicePolicy(policy, policies);
236 return true; 235 return true;
237 } 236 }
238 237
239 void DevicePolicyCache::PolicyStoreOpCompleted( 238 void DevicePolicyCache::PolicyStoreOpCompleted(
240 chromeos::SignedSettings::ReturnCode code) { 239 chromeos::SignedSettings::ReturnCode code) {
241 DCHECK(CalledOnValidThread()); 240 DCHECK(CalledOnValidThread());
242 if (code != chromeos::SignedSettings::SUCCESS) { 241 if (code != chromeos::SignedSettings::SUCCESS) {
243 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed, 242 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed,
244 kMetricPolicySize); 243 kMetricPolicySize);
245 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { 244 if (code == chromeos::SignedSettings::BAD_SIGNATURE) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 data_store_->set_device_id(policy_data.device_id()); 304 data_store_->set_device_id(policy_data.device_id());
306 *device_token = policy_data.request_token(); 305 *device_token = policy_data.request_token();
307 base::Time timestamp; 306 base::Time timestamp;
308 if (SetPolicyInternal(policy, &timestamp, true)) 307 if (SetPolicyInternal(policy, &timestamp, true))
309 set_last_policy_refresh_time(timestamp); 308 set_last_policy_refresh_time(timestamp);
310 } 309 }
311 310
312 // static 311 // static
313 void DevicePolicyCache::DecodeDevicePolicy( 312 void DevicePolicyCache::DecodeDevicePolicy(
314 const em::ChromeDeviceSettingsProto& policy, 313 const em::ChromeDeviceSettingsProto& policy,
315 PolicyMap* mandatory, 314 PolicyMap* policies) {
316 PolicyMap* recommended) {
317 if (policy.has_device_policy_refresh_rate()) { 315 if (policy.has_device_policy_refresh_rate()) {
318 const em::DevicePolicyRefreshRateProto container = 316 const em::DevicePolicyRefreshRateProto container =
319 policy.device_policy_refresh_rate(); 317 policy.device_policy_refresh_rate();
320 if (container.has_device_policy_refresh_rate()) { 318 if (container.has_device_policy_refresh_rate()) {
321 mandatory->Set(kPolicyDevicePolicyRefreshRate, 319 policies->Set(key::kDevicePolicyRefreshRate,
322 DecodeIntegerValue( 320 POLICY_LEVEL_MANDATORY,
323 container.device_policy_refresh_rate())); 321 POLICY_SCOPE_DEVICE,
322 DecodeIntegerValue(container.device_policy_refresh_rate()));
324 } 323 }
325 } 324 }
326 325
327 if (policy.has_device_proxy_settings()) { 326 if (policy.has_device_proxy_settings()) {
328 const em::DeviceProxySettingsProto container = 327 const em::DeviceProxySettingsProto container =
329 policy.device_proxy_settings(); 328 policy.device_proxy_settings();
330 if (container.has_proxy_mode()) { 329 if (container.has_proxy_mode()) {
331 recommended->Set(kPolicyProxyMode, 330 policies->Set(key::kProxyMode,
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 maybe we should create a proper proxy config dicti
Joao da Silva 2012/01/17 13:09:29 Done. The keys for the dictionary are the old pol
332 Value::CreateStringValue(container.proxy_mode())); 331 POLICY_LEVEL_RECOMMENDED,
332 POLICY_SCOPE_DEVICE,
333 Value::CreateStringValue(container.proxy_mode()));
333 } 334 }
334 if (container.has_proxy_server()) { 335 if (container.has_proxy_server()) {
335 recommended->Set(kPolicyProxyServer, 336 policies->Set(key::kProxyServer,
336 Value::CreateStringValue(container.proxy_server())); 337 POLICY_LEVEL_RECOMMENDED,
338 POLICY_SCOPE_DEVICE,
339 Value::CreateStringValue(container.proxy_server()));
337 } 340 }
338 if (container.has_proxy_pac_url()) { 341 if (container.has_proxy_pac_url()) {
339 recommended->Set(kPolicyProxyPacUrl, 342 policies->Set(key::kProxyPacUrl,
340 Value::CreateStringValue(container.proxy_pac_url())); 343 POLICY_LEVEL_RECOMMENDED,
344 POLICY_SCOPE_DEVICE,
345 Value::CreateStringValue(container.proxy_pac_url()));
341 } 346 }
342 if (container.has_proxy_bypass_list()) { 347 if (container.has_proxy_bypass_list()) {
343 recommended->Set(kPolicyProxyBypassList, 348 policies->Set(key::kProxyBypassList,
344 Value::CreateStringValue(container.proxy_bypass_list())); 349 POLICY_LEVEL_RECOMMENDED,
350 POLICY_SCOPE_DEVICE,
351 Value::CreateStringValue(container.proxy_bypass_list()));
345 } 352 }
346 } 353 }
347 354
348 if (policy.has_release_channel() && 355 if (policy.has_release_channel() &&
349 policy.release_channel().has_release_channel()) { 356 policy.release_channel().has_release_channel()) {
350 std::string channel(policy.release_channel().release_channel()); 357 std::string channel(policy.release_channel().release_channel());
351 mandatory->Set(kPolicyChromeOsReleaseChannel, 358 policies->Set(key::kChromeOsReleaseChannel,
352 Value::CreateStringValue(channel)); 359 POLICY_LEVEL_MANDATORY,
360 POLICY_SCOPE_DEVICE,
361 Value::CreateStringValue(channel));
353 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't 362 // 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 363 // have to pass the channel in here, only ping the update engine to tell
355 // it to fetch the channel from the policy. 364 // it to fetch the channel from the policy.
356 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient() 365 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()
357 ->SetReleaseTrack(channel); 366 ->SetReleaseTrack(channel);
358 } 367 }
359 368
360 if (policy.has_open_network_configuration() && 369 if (policy.has_open_network_configuration() &&
361 policy.open_network_configuration().has_open_network_configuration()) { 370 policy.open_network_configuration().has_open_network_configuration()) {
362 std::string config( 371 std::string config(
363 policy.open_network_configuration().open_network_configuration()); 372 policy.open_network_configuration().open_network_configuration());
364 mandatory->Set(kPolicyDeviceOpenNetworkConfiguration, 373 policies->Set(key::kDeviceOpenNetworkConfiguration,
365 Value::CreateStringValue(config)); 374 POLICY_LEVEL_MANDATORY,
375 POLICY_SCOPE_DEVICE,
376 Value::CreateStringValue(config));
366 } 377 }
367 } 378 }
368 379
369 } // namespace policy 380 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698