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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/policy/app_pack_updater.h" | 22 #include "chrome/browser/policy/app_pack_updater.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 "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
30 #include "chromeos/dbus/update_engine_client.h" | 30 #include "chromeos/dbus/update_engine_client.h" |
31 #include "policy/policy_constants.h" | 31 #include "policy/policy_constants.h" |
| 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
32 | 33 |
| 34 using google::protobuf::RepeatedField; |
33 using google::protobuf::RepeatedPtrField; | 35 using google::protobuf::RepeatedPtrField; |
34 | 36 |
35 namespace em = enterprise_management; | 37 namespace em = enterprise_management; |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 // Stores policy, updates the owner key if required and reports the status | 41 // Stores policy, updates the owner key if required and reports the status |
40 // through a callback. | 42 // through a callback. |
41 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { | 43 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { |
42 public: | 44 public: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if (value < std::numeric_limits<int>::min() || | 107 if (value < std::numeric_limits<int>::min() || |
106 value > std::numeric_limits<int>::max()) { | 108 value > std::numeric_limits<int>::max()) { |
107 LOG(WARNING) << "Integer value " << value | 109 LOG(WARNING) << "Integer value " << value |
108 << " out of numeric limits, ignoring."; | 110 << " out of numeric limits, ignoring."; |
109 return NULL; | 111 return NULL; |
110 } | 112 } |
111 | 113 |
112 return Value::CreateIntegerValue(static_cast<int>(value)); | 114 return Value::CreateIntegerValue(static_cast<int>(value)); |
113 } | 115 } |
114 | 116 |
| 117 Value* DecodeConnectionType(int value) { |
| 118 static const char* const kConnectionTypes[] = { |
| 119 flimflam::kTypeEthernet, |
| 120 flimflam::kTypeWifi, |
| 121 flimflam::kTypeWimax, |
| 122 flimflam::kTypeBluetooth, |
| 123 flimflam::kTypeCellular, |
| 124 }; |
| 125 |
| 126 if (value < 0 || value >= static_cast<int>(arraysize(kConnectionTypes))) |
| 127 return NULL; |
| 128 |
| 129 return Value::CreateStringValue(kConnectionTypes[value]); |
| 130 } |
| 131 |
115 } // namespace | 132 } // namespace |
116 | 133 |
117 namespace policy { | 134 namespace policy { |
118 | 135 |
119 DevicePolicyCache::DevicePolicyCache( | 136 DevicePolicyCache::DevicePolicyCache( |
120 CloudPolicyDataStore* data_store, | 137 CloudPolicyDataStore* data_store, |
121 EnterpriseInstallAttributes* install_attributes) | 138 EnterpriseInstallAttributes* install_attributes) |
122 : data_store_(data_store), | 139 : data_store_(data_store), |
123 install_attributes_(install_attributes), | 140 install_attributes_(install_attributes), |
124 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), | 141 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 366 } |
350 | 367 |
351 void DevicePolicyCache::DecodeDevicePolicy( | 368 void DevicePolicyCache::DecodeDevicePolicy( |
352 const em::ChromeDeviceSettingsProto& policy, | 369 const em::ChromeDeviceSettingsProto& policy, |
353 PolicyMap* policies) { | 370 PolicyMap* policies) { |
354 // Decode the various groups of policies. | 371 // Decode the various groups of policies. |
355 DecodeLoginPolicies(policy, policies); | 372 DecodeLoginPolicies(policy, policies); |
356 DecodeKioskPolicies(policy, policies, install_attributes_); | 373 DecodeKioskPolicies(policy, policies, install_attributes_); |
357 DecodeNetworkPolicies(policy, policies, install_attributes_); | 374 DecodeNetworkPolicies(policy, policies, install_attributes_); |
358 DecodeReportingPolicies(policy, policies); | 375 DecodeReportingPolicies(policy, policies); |
| 376 DecodeAutoUpdatePolicies(policy, policies); |
359 DecodeGenericPolicies(policy, policies); | 377 DecodeGenericPolicies(policy, policies); |
360 } | 378 } |
361 | 379 |
362 // static | 380 // static |
363 void DevicePolicyCache::DecodeLoginPolicies( | 381 void DevicePolicyCache::DecodeLoginPolicies( |
364 const em::ChromeDeviceSettingsProto& policy, | 382 const em::ChromeDeviceSettingsProto& policy, |
365 PolicyMap* policies) { | 383 PolicyMap* policies) { |
366 if (policy.has_guest_mode_enabled()) { | 384 if (policy.has_guest_mode_enabled()) { |
367 const em::GuestModeEnabledProto& container(policy.guest_mode_enabled()); | 385 const em::GuestModeEnabledProto& container(policy.guest_mode_enabled()); |
368 if (container.has_guest_mode_enabled()) { | 386 if (container.has_guest_mode_enabled()) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (container.has_report_location()) { | 600 if (container.has_report_location()) { |
583 policies->Set(key::kReportDeviceLocation, | 601 policies->Set(key::kReportDeviceLocation, |
584 POLICY_LEVEL_MANDATORY, | 602 POLICY_LEVEL_MANDATORY, |
585 POLICY_SCOPE_MACHINE, | 603 POLICY_SCOPE_MACHINE, |
586 Value::CreateBooleanValue(container.report_location())); | 604 Value::CreateBooleanValue(container.report_location())); |
587 } | 605 } |
588 } | 606 } |
589 } | 607 } |
590 | 608 |
591 // static | 609 // static |
592 void DevicePolicyCache::DecodeGenericPolicies( | 610 void DevicePolicyCache::DecodeAutoUpdatePolicies( |
593 const em::ChromeDeviceSettingsProto& policy, | 611 const em::ChromeDeviceSettingsProto& policy, |
594 PolicyMap* policies) { | 612 PolicyMap* policies) { |
595 if (policy.has_device_policy_refresh_rate()) { | |
596 const em::DevicePolicyRefreshRateProto& container( | |
597 policy.device_policy_refresh_rate()); | |
598 if (container.has_device_policy_refresh_rate()) { | |
599 policies->Set(key::kDevicePolicyRefreshRate, | |
600 POLICY_LEVEL_MANDATORY, | |
601 POLICY_SCOPE_MACHINE, | |
602 DecodeIntegerValue(container.device_policy_refresh_rate())); | |
603 } | |
604 } | |
605 | |
606 if (policy.has_metrics_enabled()) { | |
607 const em::MetricsEnabledProto& container(policy.metrics_enabled()); | |
608 if (container.has_metrics_enabled()) { | |
609 policies->Set(key::kDeviceMetricsReportingEnabled, | |
610 POLICY_LEVEL_MANDATORY, | |
611 POLICY_SCOPE_MACHINE, | |
612 Value::CreateBooleanValue(container.metrics_enabled())); | |
613 } | |
614 } | |
615 | |
616 if (policy.has_release_channel()) { | 613 if (policy.has_release_channel()) { |
617 const em::ReleaseChannelProto& container(policy.release_channel()); | 614 const em::ReleaseChannelProto& container(policy.release_channel()); |
618 if (container.has_release_channel()) { | 615 if (container.has_release_channel()) { |
619 std::string channel(container.release_channel()); | 616 std::string channel(container.release_channel()); |
620 policies->Set(key::kChromeOsReleaseChannel, | 617 policies->Set(key::kChromeOsReleaseChannel, |
621 POLICY_LEVEL_MANDATORY, | 618 POLICY_LEVEL_MANDATORY, |
622 POLICY_SCOPE_MACHINE, | 619 POLICY_SCOPE_MACHINE, |
623 Value::CreateStringValue(channel)); | 620 Value::CreateStringValue(channel)); |
624 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't | 621 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't |
625 // have to pass the channel in here, only ping the update engine to tell | 622 // have to pass the channel in here, only ping the update engine to tell |
(...skipping 19 matching lines...) Expand all Loading... |
645 Value::CreateBooleanValue(container.update_disabled())); | 642 Value::CreateBooleanValue(container.update_disabled())); |
646 } | 643 } |
647 | 644 |
648 if (container.has_target_version_prefix()) { | 645 if (container.has_target_version_prefix()) { |
649 policies->Set(key::kDeviceTargetVersionPrefix, | 646 policies->Set(key::kDeviceTargetVersionPrefix, |
650 POLICY_LEVEL_MANDATORY, | 647 POLICY_LEVEL_MANDATORY, |
651 POLICY_SCOPE_MACHINE, | 648 POLICY_SCOPE_MACHINE, |
652 Value::CreateStringValue( | 649 Value::CreateStringValue( |
653 container.target_version_prefix())); | 650 container.target_version_prefix())); |
654 } | 651 } |
| 652 |
| 653 // target_version_display_name is not actually a policy, but a display |
| 654 // string for target_version_prefix, so we ignore it. |
| 655 |
| 656 if (container.has_scatter_factor_in_seconds()) { |
| 657 policies->Set(key::kDeviceUpdateScatterFactor, |
| 658 POLICY_LEVEL_MANDATORY, |
| 659 POLICY_SCOPE_MACHINE, |
| 660 Value::CreateIntegerValue( |
| 661 container.scatter_factor_in_seconds())); |
| 662 } |
| 663 |
| 664 if (container.allowed_connection_types_size()) { |
| 665 ListValue* allowed_connection_types = new ListValue(); |
| 666 RepeatedField<int>::const_iterator entry; |
| 667 for (entry = container.allowed_connection_types().begin(); |
| 668 entry != container.allowed_connection_types().end(); |
| 669 ++entry) { |
| 670 base::Value* value = DecodeConnectionType(*entry); |
| 671 if (value) |
| 672 allowed_connection_types->Append(value); |
| 673 } |
| 674 policies->Set(key::kDeviceUpdateAllowedConnectionTypes, |
| 675 POLICY_LEVEL_MANDATORY, |
| 676 POLICY_SCOPE_MACHINE, |
| 677 allowed_connection_types); |
| 678 } |
| 679 } |
| 680 } |
| 681 |
| 682 // static |
| 683 void DevicePolicyCache::DecodeGenericPolicies( |
| 684 const em::ChromeDeviceSettingsProto& policy, |
| 685 PolicyMap* policies) { |
| 686 if (policy.has_device_policy_refresh_rate()) { |
| 687 const em::DevicePolicyRefreshRateProto& container( |
| 688 policy.device_policy_refresh_rate()); |
| 689 if (container.has_device_policy_refresh_rate()) { |
| 690 policies->Set(key::kDevicePolicyRefreshRate, |
| 691 POLICY_LEVEL_MANDATORY, |
| 692 POLICY_SCOPE_MACHINE, |
| 693 DecodeIntegerValue(container.device_policy_refresh_rate())); |
| 694 } |
| 695 } |
| 696 |
| 697 if (policy.has_metrics_enabled()) { |
| 698 const em::MetricsEnabledProto& container(policy.metrics_enabled()); |
| 699 if (container.has_metrics_enabled()) { |
| 700 policies->Set(key::kDeviceMetricsReportingEnabled, |
| 701 POLICY_LEVEL_MANDATORY, |
| 702 POLICY_SCOPE_MACHINE, |
| 703 Value::CreateBooleanValue(container.metrics_enabled())); |
| 704 } |
655 } | 705 } |
656 | 706 |
657 if (policy.has_start_up_urls()) { | 707 if (policy.has_start_up_urls()) { |
658 const em::StartUpUrlsProto& container(policy.start_up_urls()); | 708 const em::StartUpUrlsProto& container(policy.start_up_urls()); |
659 if (container.start_up_urls_size()) { | 709 if (container.start_up_urls_size()) { |
660 ListValue* urls = new ListValue(); | 710 ListValue* urls = new ListValue(); |
661 RepeatedPtrField<std::string>::const_iterator entry; | 711 RepeatedPtrField<std::string>::const_iterator entry; |
662 for (entry = container.start_up_urls().begin(); | 712 for (entry = container.start_up_urls().begin(); |
663 entry != container.start_up_urls().end(); | 713 entry != container.start_up_urls().end(); |
664 ++entry) { | 714 ++entry) { |
665 urls->Append(Value::CreateStringValue(*entry)); | 715 urls->Append(Value::CreateStringValue(*entry)); |
666 } | 716 } |
667 policies->Set(key::kDeviceStartUpUrls, | 717 policies->Set(key::kDeviceStartUpUrls, |
668 POLICY_LEVEL_MANDATORY, | 718 POLICY_LEVEL_MANDATORY, |
669 POLICY_SCOPE_MACHINE, | 719 POLICY_SCOPE_MACHINE, |
670 urls); | 720 urls); |
671 } | 721 } |
672 } | 722 } |
673 } | 723 } |
674 | 724 |
675 } // namespace policy | 725 } // namespace policy |
OLD | NEW |