| 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/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 // Policy-based ONC blobs cannot have a passphrase. | 38 // Policy-based ONC blobs cannot have a passphrase. |
| 39 chromeos::OncNetworkParser parser(onc_blob, "", onc_source_); | 39 chromeos::OncNetworkParser parser(onc_blob, "", onc_source_); |
| 40 if (!parser.parse_error().empty()) { | 40 if (!parser.parse_error().empty()) { |
| 41 errors->AddError(policy_type(), | 41 errors->AddError(policy_name(), |
| 42 IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR, | 42 IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR, |
| 43 parser.parse_error()); | 43 parser.parse_error()); |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void NetworkConfigurationPolicyHandler::ApplyPolicySettings( | 51 void NetworkConfigurationPolicyHandler::ApplyPolicySettings( |
| 52 const PolicyMap& policies, | 52 const PolicyMap& policies, |
| 53 PrefValueMap* prefs) { | 53 PrefValueMap* prefs) { |
| 54 // Network policy is read directly from the provider and injected into | 54 // Network policy is read directly from the provider and injected into |
| 55 // NetworkLibrary, so no need to convert the policy settings into prefs. | 55 // NetworkLibrary, so no need to convert the policy settings into prefs. |
| 56 } | 56 } |
| 57 | 57 |
| 58 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( | 58 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( |
| 59 PolicyMap* policies) const { | 59 PolicyMap* policies) const { |
| 60 const Value* network_config = policies->Get(policy_type()); | 60 const PolicyMap::Entry* entry = policies->Get(policy_name()); |
| 61 if (!network_config) | 61 if (!entry) |
| 62 return; | 62 return; |
| 63 | 63 Value* sanitized_config = SanitizeNetworkConfig(entry->value); |
| 64 Value* sanitized_config = SanitizeNetworkConfig(network_config); | |
| 65 if (!sanitized_config) | 64 if (!sanitized_config) |
| 66 sanitized_config = Value::CreateNullValue(); | 65 sanitized_config = Value::CreateNullValue(); |
| 67 | 66 |
| 68 policies->Set(policy_type(), sanitized_config); | 67 policies->Set(policy_name(), entry->level, entry->scope, sanitized_config); |
| 69 } | 68 } |
| 70 | 69 |
| 71 // static | 70 // static |
| 72 Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( | 71 Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( |
| 73 const Value* config) { | 72 const Value* config) { |
| 74 std::string json_string; | 73 std::string json_string; |
| 75 if (!config->GetAsString(&json_string)) | 74 if (!config->GetAsString(&json_string)) |
| 76 return NULL; | 75 return NULL; |
| 77 | 76 |
| 78 scoped_ptr<Value> json_value(base::JSONReader::Read(json_string, true)); | 77 scoped_ptr<Value> json_value(base::JSONReader::Read(json_string, true)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 117 |
| 119 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) { | 118 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) { |
| 120 if (network_dict->Remove(kFilteredSettings[i], NULL)) { | 119 if (network_dict->Remove(kFilteredSettings[i], NULL)) { |
| 121 network_dict->Set(kFilteredSettings[i], | 120 network_dict->Set(kFilteredSettings[i], |
| 122 Value::CreateStringValue(kPlaceholder)); | 121 Value::CreateStringValue(kPlaceholder)); |
| 123 } | 122 } |
| 124 } | 123 } |
| 125 } | 124 } |
| 126 | 125 |
| 127 } // namespace policy | 126 } // namespace policy |
| OLD | NEW |