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