| 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.h" | 5 #include "chrome/browser/policy/configuration_policy_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | |
| 9 | 8 |
| 10 #include "base/callback.h" | 9 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 12 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/prefs/pref_value_map.h" | 13 #include "base/prefs/pref_value_map.h" |
| 15 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 16 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, | 111 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, |
| 113 { ProxyPrefs::kPacScriptProxyModeName, | 112 { ProxyPrefs::kPacScriptProxyModeName, |
| 114 true, false, false, IDS_POLICY_PROXY_MODE_PAC_URL_ERROR }, | 113 true, false, false, IDS_POLICY_PROXY_MODE_PAC_URL_ERROR }, |
| 115 { ProxyPrefs::kFixedServersProxyModeName, | 114 { ProxyPrefs::kFixedServersProxyModeName, |
| 116 false, true, true, IDS_POLICY_PROXY_MODE_FIXED_SERVERS_ERROR }, | 115 false, true, true, IDS_POLICY_PROXY_MODE_FIXED_SERVERS_ERROR }, |
| 117 { ProxyPrefs::kSystemProxyModeName, | 116 { ProxyPrefs::kSystemProxyModeName, |
| 118 false, false, false, IDS_POLICY_PROXY_MODE_SYSTEM_ERROR }, | 117 false, false, false, IDS_POLICY_PROXY_MODE_SYSTEM_ERROR }, |
| 119 }; | 118 }; |
| 120 | 119 |
| 121 | 120 |
| 122 // Helper functions ------------------------------------------------------------ | 121 // Helper function ------------------------------------------------------------- |
| 123 | |
| 124 std::string ValueTypeToString(Value::Type type) { | |
| 125 static const char* strings[] = { | |
| 126 "null", | |
| 127 "boolean", | |
| 128 "integer", | |
| 129 "double", | |
| 130 "string", | |
| 131 "binary", | |
| 132 "dictionary", | |
| 133 "list" | |
| 134 }; | |
| 135 CHECK(static_cast<size_t>(type) < arraysize(strings)); | |
| 136 return std::string(strings[type]); | |
| 137 } | |
| 138 | 122 |
| 139 // Utility function that returns a JSON representation of the given |dict| as | 123 // Utility function that returns a JSON representation of the given |dict| as |
| 140 // a StringValue. The caller owns the returned object. | 124 // a StringValue. The caller owns the returned object. |
| 141 base::StringValue* DictionaryToJSONString(const base::DictionaryValue* dict) { | 125 base::StringValue* DictionaryToJSONString(const base::DictionaryValue* dict) { |
| 142 std::string json_string; | 126 std::string json_string; |
| 143 base::JSONWriter::WriteWithOptions( | 127 base::JSONWriter::WriteWithOptions( |
| 144 dict, | 128 dict, |
| 145 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 129 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
| 146 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 130 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 147 &json_string); | 131 &json_string); |
| 148 return Value::CreateStringValue(json_string); | 132 return Value::CreateStringValue(json_string); |
| 149 } | 133 } |
| 150 | 134 |
| 151 | 135 |
| 152 } // namespace | 136 } // namespace |
| 153 | 137 |
| 154 | 138 |
| 155 // ConfigurationPolicyHandler implementation ----------------------------------- | 139 // ConfigurationPolicyHandler implementation ----------------------------------- |
| 156 | 140 |
| 141 // static |
| 142 std::string ConfigurationPolicyHandler::ValueTypeToString(Value::Type type) { |
| 143 static const char* strings[] = { |
| 144 "null", |
| 145 "boolean", |
| 146 "integer", |
| 147 "double", |
| 148 "string", |
| 149 "binary", |
| 150 "dictionary", |
| 151 "list" |
| 152 }; |
| 153 CHECK(static_cast<size_t>(type) < arraysize(strings)); |
| 154 return std::string(strings[type]); |
| 155 } |
| 156 |
| 157 ConfigurationPolicyHandler::ConfigurationPolicyHandler() { | 157 ConfigurationPolicyHandler::ConfigurationPolicyHandler() { |
| 158 } | 158 } |
| 159 | 159 |
| 160 ConfigurationPolicyHandler::~ConfigurationPolicyHandler() { | 160 ConfigurationPolicyHandler::~ConfigurationPolicyHandler() { |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ConfigurationPolicyHandler::PrepareForDisplaying( | 163 void ConfigurationPolicyHandler::PrepareForDisplaying( |
| 164 PolicyMap* policies) const { | 164 PolicyMap* policies) const { |
| 165 // jstemplate can't render DictionaryValues/objects. Convert those values to | 165 // jstemplate can't render DictionaryValues/objects. Convert those values to |
| 166 // a string representation. | 166 // a string representation. |
| (...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 errors->AddError(policy_name(), | 1590 errors->AddError(policy_name(), |
| 1591 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1591 IDS_POLICY_OUT_OF_RANGE_ERROR, |
| 1592 base::IntToString(restore_value)); | 1592 base::IntToString(restore_value)); |
| 1593 } | 1593 } |
| 1594 } | 1594 } |
| 1595 } | 1595 } |
| 1596 return true; | 1596 return true; |
| 1597 } | 1597 } |
| 1598 | 1598 |
| 1599 } // namespace policy | 1599 } // namespace policy |
| OLD | NEW |