| OLD | NEW |
| 1 // Copyright (c) 2011 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/configuration_policy_handler_chromeos.h" | 5 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/chromeos/cros/onc_network_parser.h" | 13 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
| 14 #include "chrome/browser/policy/policy_error_map.h" | 14 #include "chrome/browser/policy/policy_error_map.h" |
| 15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 | 17 |
| 18 namespace policy { | 18 namespace policy { |
| 19 | 19 |
| 20 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( | 20 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( |
| 21 ConfigurationPolicyType type, | 21 const char* policy_name, |
| 22 chromeos::NetworkUIData::ONCSource onc_source) | 22 chromeos::NetworkUIData::ONCSource onc_source) |
| 23 : TypeCheckingPolicyHandler(type, Value::TYPE_STRING), | 23 : TypeCheckingPolicyHandler(policy_name, Value::TYPE_STRING), |
| 24 onc_source_(onc_source) {} | 24 onc_source_(onc_source) {} |
| 25 | 25 |
| 26 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {} | 26 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {} |
| 27 | 27 |
| 28 bool NetworkConfigurationPolicyHandler::CheckPolicySettings( | 28 bool NetworkConfigurationPolicyHandler::CheckPolicySettings( |
| 29 const PolicyMap& policies, | 29 const PolicyMap& policies, |
| 30 PolicyErrorMap* errors) { | 30 PolicyErrorMap* errors) { |
| 31 const Value* value; | 31 const Value* value; |
| 32 if (!CheckAndGetValue(policies, errors, &value)) | 32 if (!CheckAndGetValue(policies, errors, &value)) |
| 33 return false; | 33 return false; |
| 34 | 34 |
| 35 if (value) { | 35 if (value) { |
| 36 std::string onc_blob; | 36 std::string onc_blob; |
| 37 value->GetAsString(&onc_blob); | 37 value->GetAsString(&onc_blob); |
| 38 chromeos::OncNetworkParser parser(onc_blob, onc_source_); | 38 chromeos::OncNetworkParser parser(onc_blob, onc_source_); |
| 39 if (!parser.parse_error().empty()) { | 39 if (!parser.parse_error().empty()) { |
| 40 errors->AddError(policy_type(), | 40 errors->AddError(policy_name(), |
| 41 IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR, | 41 IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR, |
| 42 parser.parse_error()); | 42 parser.parse_error()); |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void NetworkConfigurationPolicyHandler::ApplyPolicySettings( | 50 void NetworkConfigurationPolicyHandler::ApplyPolicySettings( |
| 51 const PolicyMap& policies, | 51 const PolicyMap& policies, |
| 52 PrefValueMap* prefs) { | 52 PrefValueMap* prefs) { |
| 53 // Network policy is read directly from the provider and injected into | 53 // Network policy is read directly from the provider and injected into |
| 54 // NetworkLibrary, so no need to convert the policy settings into prefs. | 54 // NetworkLibrary, so no need to convert the policy settings into prefs. |
| 55 } | 55 } |
| 56 | 56 |
| 57 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( | 57 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( |
| 58 PolicyMap* policies) const { | 58 PolicyMap* policies) const { |
| 59 const Value* network_config = policies->Get(policy_type()); | 59 const PolicyMap::Entry* entry = policies->Get(policy_name()); |
| 60 if (!network_config) | 60 if (!entry) |
| 61 return; | 61 return; |
| 62 | 62 Value* sanitized_config = SanitizeNetworkConfig(entry->value); |
| 63 Value* sanitized_config = SanitizeNetworkConfig(network_config); | |
| 64 if (!sanitized_config) | 63 if (!sanitized_config) |
| 65 sanitized_config = Value::CreateNullValue(); | 64 sanitized_config = Value::CreateNullValue(); |
| 66 | 65 |
| 67 policies->Set(policy_type(), sanitized_config); | 66 policies->Set(policy_name(), entry->level, entry->scope, sanitized_config); |
| 68 } | 67 } |
| 69 | 68 |
| 70 // static | 69 // static |
| 71 Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( | 70 Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( |
| 72 const Value* config) { | 71 const Value* config) { |
| 73 std::string json_string; | 72 std::string json_string; |
| 74 if (!config->GetAsString(&json_string)) | 73 if (!config->GetAsString(&json_string)) |
| 75 return NULL; | 74 return NULL; |
| 76 | 75 |
| 77 scoped_ptr<Value> json_value(base::JSONReader::Read(json_string, true)); | 76 scoped_ptr<Value> json_value(base::JSONReader::Read(json_string, true)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 116 |
| 118 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) { | 117 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) { |
| 119 if (network_dict->Remove(kFilteredSettings[i], NULL)) { | 118 if (network_dict->Remove(kFilteredSettings[i], NULL)) { |
| 120 network_dict->Set(kFilteredSettings[i], | 119 network_dict->Set(kFilteredSettings[i], |
| 121 Value::CreateStringValue(kPlaceholder)); | 120 Value::CreateStringValue(kPlaceholder)); |
| 122 } | 121 } |
| 123 } | 122 } |
| 124 } | 123 } |
| 125 | 124 |
| 126 } // namespace policy | 125 } // namespace policy |
| OLD | NEW |