| 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 12 matching lines...) Expand all Loading... |
| 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 | 32 |
| 33 using google::protobuf::RepeatedField; |
| 33 using google::protobuf::RepeatedPtrField; | 34 using google::protobuf::RepeatedPtrField; |
| 34 | 35 |
| 35 namespace em = enterprise_management; | 36 namespace em = enterprise_management; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Stores policy, updates the owner key if required and reports the status | 40 // Stores policy, updates the owner key if required and reports the status |
| 40 // through a callback. | 41 // through a callback. |
| 41 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { | 42 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { |
| 42 public: | 43 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (value < std::numeric_limits<int>::min() || | 106 if (value < std::numeric_limits<int>::min() || |
| 106 value > std::numeric_limits<int>::max()) { | 107 value > std::numeric_limits<int>::max()) { |
| 107 LOG(WARNING) << "Integer value " << value | 108 LOG(WARNING) << "Integer value " << value |
| 108 << " out of numeric limits, ignoring."; | 109 << " out of numeric limits, ignoring."; |
| 109 return NULL; | 110 return NULL; |
| 110 } | 111 } |
| 111 | 112 |
| 112 return Value::CreateIntegerValue(static_cast<int>(value)); | 113 return Value::CreateIntegerValue(static_cast<int>(value)); |
| 113 } | 114 } |
| 114 | 115 |
| 116 Value* DecodeConnectionType(int value) { |
| 117 static const char* const kConnectionTypes[] = { |
| 118 "ethernet", |
| 119 "wifi", |
| 120 "wimax", |
| 121 "bluetooth", |
| 122 "cellular", |
| 123 }; |
| 124 |
| 125 if (value < 0 || value >= static_cast<int>(arraysize(kConnectionTypes))) |
| 126 return NULL; |
| 127 |
| 128 return Value::CreateStringValue(kConnectionTypes[value]); |
| 129 } |
| 130 |
| 115 } // namespace | 131 } // namespace |
| 116 | 132 |
| 117 namespace policy { | 133 namespace policy { |
| 118 | 134 |
| 119 DevicePolicyCache::DevicePolicyCache( | 135 DevicePolicyCache::DevicePolicyCache( |
| 120 CloudPolicyDataStore* data_store, | 136 CloudPolicyDataStore* data_store, |
| 121 EnterpriseInstallAttributes* install_attributes) | 137 EnterpriseInstallAttributes* install_attributes) |
| 122 : data_store_(data_store), | 138 : data_store_(data_store), |
| 123 install_attributes_(install_attributes), | 139 install_attributes_(install_attributes), |
| 124 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), | 140 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 if (container.has_report_location()) { | 597 if (container.has_report_location()) { |
| 582 policies->Set(key::kReportDeviceLocation, | 598 policies->Set(key::kReportDeviceLocation, |
| 583 POLICY_LEVEL_MANDATORY, | 599 POLICY_LEVEL_MANDATORY, |
| 584 POLICY_SCOPE_MACHINE, | 600 POLICY_SCOPE_MACHINE, |
| 585 Value::CreateBooleanValue(container.report_location())); | 601 Value::CreateBooleanValue(container.report_location())); |
| 586 } | 602 } |
| 587 } | 603 } |
| 588 } | 604 } |
| 589 | 605 |
| 590 // static | 606 // static |
| 591 void DevicePolicyCache::DecodeGenericPolicies( | 607 void DevicePolicyCache::DecodeAutoUpdatePolicies( |
| 592 const em::ChromeDeviceSettingsProto& policy, | 608 const em::ChromeDeviceSettingsProto& policy, |
| 593 PolicyMap* policies) { | 609 PolicyMap* policies) { |
| 594 if (policy.has_device_policy_refresh_rate()) { | |
| 595 const em::DevicePolicyRefreshRateProto& container( | |
| 596 policy.device_policy_refresh_rate()); | |
| 597 if (container.has_device_policy_refresh_rate()) { | |
| 598 policies->Set(key::kDevicePolicyRefreshRate, | |
| 599 POLICY_LEVEL_MANDATORY, | |
| 600 POLICY_SCOPE_MACHINE, | |
| 601 DecodeIntegerValue(container.device_policy_refresh_rate())); | |
| 602 } | |
| 603 } | |
| 604 | |
| 605 if (policy.has_metrics_enabled()) { | |
| 606 const em::MetricsEnabledProto& container(policy.metrics_enabled()); | |
| 607 if (container.has_metrics_enabled()) { | |
| 608 policies->Set(key::kDeviceMetricsReportingEnabled, | |
| 609 POLICY_LEVEL_MANDATORY, | |
| 610 POLICY_SCOPE_MACHINE, | |
| 611 Value::CreateBooleanValue(container.metrics_enabled())); | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 if (policy.has_release_channel()) { | 610 if (policy.has_release_channel()) { |
| 616 const em::ReleaseChannelProto& container(policy.release_channel()); | 611 const em::ReleaseChannelProto& container(policy.release_channel()); |
| 617 if (container.has_release_channel()) { | 612 if (container.has_release_channel()) { |
| 618 std::string channel(container.release_channel()); | 613 std::string channel(container.release_channel()); |
| 619 policies->Set(key::kChromeOsReleaseChannel, | 614 policies->Set(key::kChromeOsReleaseChannel, |
| 620 POLICY_LEVEL_MANDATORY, | 615 POLICY_LEVEL_MANDATORY, |
| 621 POLICY_SCOPE_MACHINE, | 616 POLICY_SCOPE_MACHINE, |
| 622 Value::CreateStringValue(channel)); | 617 Value::CreateStringValue(channel)); |
| 623 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't | 618 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't |
| 624 // have to pass the channel in here, only ping the update engine to tell | 619 // have to pass the channel in here, only ping the update engine to tell |
| (...skipping 19 matching lines...) Expand all Loading... |
| 644 Value::CreateBooleanValue(container.update_disabled())); | 639 Value::CreateBooleanValue(container.update_disabled())); |
| 645 } | 640 } |
| 646 | 641 |
| 647 if (container.has_target_version_prefix()) { | 642 if (container.has_target_version_prefix()) { |
| 648 policies->Set(key::kDeviceTargetVersionPrefix, | 643 policies->Set(key::kDeviceTargetVersionPrefix, |
| 649 POLICY_LEVEL_MANDATORY, | 644 POLICY_LEVEL_MANDATORY, |
| 650 POLICY_SCOPE_MACHINE, | 645 POLICY_SCOPE_MACHINE, |
| 651 Value::CreateStringValue( | 646 Value::CreateStringValue( |
| 652 container.target_version_prefix())); | 647 container.target_version_prefix())); |
| 653 } | 648 } |
| 649 |
| 650 // target_version_display_name is not actually a policy, but a display |
| 651 // string for target_version_prefix, so we ignore it. |
| 652 |
| 653 if (container.has_scatter_factor_in_seconds()) { |
| 654 policies->Set(key::kDeviceUpdateScatterFactor, |
| 655 POLICY_LEVEL_MANDATORY, |
| 656 POLICY_SCOPE_MACHINE, |
| 657 Value::CreateIntegerValue( |
| 658 container.scatter_factor_in_seconds())); |
| 659 } |
| 660 |
| 661 if (container.allowed_connection_types_size()) { |
| 662 ListValue* allowed_connection_types = new ListValue(); |
| 663 RepeatedField<int>::const_iterator entry; |
| 664 for (entry = container.allowed_connection_types().begin(); |
| 665 entry != container.allowed_connection_types().end(); |
| 666 ++entry) { |
| 667 base::Value* value = DecodeConnectionType(*entry); |
| 668 if (!value) |
| 669 allowed_connection_types->Append(value); |
| 670 } |
| 671 policies->Set(key::kDeviceUpdateAllowedConnectionTypes, |
| 672 POLICY_LEVEL_MANDATORY, |
| 673 POLICY_SCOPE_MACHINE, |
| 674 allowed_connection_types); |
| 675 } |
| 676 } |
| 677 } |
| 678 |
| 679 // static |
| 680 void DevicePolicyCache::DecodeGenericPolicies( |
| 681 const em::ChromeDeviceSettingsProto& policy, |
| 682 PolicyMap* policies) { |
| 683 if (policy.has_device_policy_refresh_rate()) { |
| 684 const em::DevicePolicyRefreshRateProto& container( |
| 685 policy.device_policy_refresh_rate()); |
| 686 if (container.has_device_policy_refresh_rate()) { |
| 687 policies->Set(key::kDevicePolicyRefreshRate, |
| 688 POLICY_LEVEL_MANDATORY, |
| 689 POLICY_SCOPE_MACHINE, |
| 690 DecodeIntegerValue(container.device_policy_refresh_rate())); |
| 691 } |
| 692 } |
| 693 |
| 694 if (policy.has_metrics_enabled()) { |
| 695 const em::MetricsEnabledProto& container(policy.metrics_enabled()); |
| 696 if (container.has_metrics_enabled()) { |
| 697 policies->Set(key::kDeviceMetricsReportingEnabled, |
| 698 POLICY_LEVEL_MANDATORY, |
| 699 POLICY_SCOPE_MACHINE, |
| 700 Value::CreateBooleanValue(container.metrics_enabled())); |
| 701 } |
| 654 } | 702 } |
| 655 | 703 |
| 656 if (policy.has_start_up_urls()) { | 704 if (policy.has_start_up_urls()) { |
| 657 const em::StartUpUrlsProto& container(policy.start_up_urls()); | 705 const em::StartUpUrlsProto& container(policy.start_up_urls()); |
| 658 if (container.start_up_urls_size()) { | 706 if (container.start_up_urls_size()) { |
| 659 ListValue* urls = new ListValue(); | 707 ListValue* urls = new ListValue(); |
| 660 RepeatedPtrField<std::string>::const_iterator entry; | 708 RepeatedPtrField<std::string>::const_iterator entry; |
| 661 for (entry = container.start_up_urls().begin(); | 709 for (entry = container.start_up_urls().begin(); |
| 662 entry != container.start_up_urls().end(); | 710 entry != container.start_up_urls().end(); |
| 663 ++entry) { | 711 ++entry) { |
| 664 urls->Append(Value::CreateStringValue(*entry)); | 712 urls->Append(Value::CreateStringValue(*entry)); |
| 665 } | 713 } |
| 666 policies->Set(key::kDeviceStartUpUrls, | 714 policies->Set(key::kDeviceStartUpUrls, |
| 667 POLICY_LEVEL_MANDATORY, | 715 POLICY_LEVEL_MANDATORY, |
| 668 POLICY_SCOPE_MACHINE, | 716 POLICY_SCOPE_MACHINE, |
| 669 urls); | 717 urls); |
| 670 } | 718 } |
| 671 } | 719 } |
| 672 } | 720 } |
| 673 | 721 |
| 674 } // namespace policy | 722 } // namespace policy |
| OLD | NEW |