| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/prefs/proxy_prefs.h" | 5 #include "chrome/browser/prefs/proxy_prefs.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace ProxyPrefs { |
| 11 |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 // These names are exposed to the proxy extension API. They must be in sync | 14 // These names are exposed to the proxy extension API. They must be in sync |
| 13 // with the constants of ProxyPrefs. | 15 // with the constants of ProxyPrefs. |
| 14 const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName, | 16 const char* kProxyModeNames[] = { kDirectProxyModeName, |
| 15 ProxyPrefs::kAutoDetectProxyModeName, | 17 kAutoDetectProxyModeName, |
| 16 ProxyPrefs::kPacScriptProxyModeName, | 18 kPacScriptProxyModeName, |
| 17 ProxyPrefs::kFixedServersProxyModeName, | 19 kFixedServersProxyModeName, |
| 18 ProxyPrefs::kSystemProxyModeName }; | 20 kSystemProxyModeName }; |
| 19 | 21 |
| 20 COMPILE_ASSERT(arraysize(kProxyModeNames) == ProxyPrefs::kModeCount, | 22 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount, |
| 21 kProxyModeNames_must_have_size_of_NUM_MODES); | 23 kProxyModeNames_must_have_size_of_NUM_MODES); |
| 22 | 24 |
| 23 } // namespace | 25 } // namespace |
| 24 | 26 |
| 25 namespace ProxyPrefs { | |
| 26 | |
| 27 const char kDirectProxyModeName[] = "direct"; | 27 const char kDirectProxyModeName[] = "direct"; |
| 28 const char kAutoDetectProxyModeName[] = "auto_detect"; | 28 const char kAutoDetectProxyModeName[] = "auto_detect"; |
| 29 const char kPacScriptProxyModeName[] = "pac_script"; | 29 const char kPacScriptProxyModeName[] = "pac_script"; |
| 30 const char kFixedServersProxyModeName[] = "fixed_servers"; | 30 const char kFixedServersProxyModeName[] = "fixed_servers"; |
| 31 const char kSystemProxyModeName[] = "system"; | 31 const char kSystemProxyModeName[] = "system"; |
| 32 | 32 |
| 33 bool IntToProxyMode(int in_value, ProxyMode* out_value) { | 33 bool IntToProxyMode(int in_value, ProxyMode* out_value) { |
| 34 DCHECK(out_value); | 34 DCHECK(out_value); |
| 35 if (in_value < 0 || in_value >= kModeCount) | 35 if (in_value < 0 || in_value >= kModeCount) |
| 36 return false; | 36 return false; |
| 37 *out_value = static_cast<ProxyMode>(in_value); | 37 *out_value = static_cast<ProxyMode>(in_value); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) { | 41 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) { |
| 42 DCHECK(out_value); | 42 DCHECK(out_value); |
| 43 for (int i = 0; i < kModeCount; i++) { | 43 for (int i = 0; i < kModeCount; i++) { |
| 44 if (in_value == kProxyModeNames[i]) | 44 if (in_value == kProxyModeNames[i]) |
| 45 return IntToProxyMode(i, out_value); | 45 return IntToProxyMode(i, out_value); |
| 46 } | 46 } |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 const char* ProxyModeToString(ProxyMode mode) { | 50 const char* ProxyModeToString(ProxyMode mode) { |
| 51 return kProxyModeNames[mode]; | 51 return kProxyModeNames[mode]; |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string ConfigStateToString(ConfigState state) { |
| 55 switch (state) { |
| 56 case CONFIG_POLICY: |
| 57 return "config_policy"; |
| 58 case CONFIG_EXTENSION: |
| 59 return "config_extension"; |
| 60 case CONFIG_OTHER_PRECEDE: |
| 61 return "config_other_precede"; |
| 62 case CONFIG_SYSTEM: |
| 63 return "config_system"; |
| 64 case CONFIG_FALLBACK: |
| 65 return "config_fallback"; |
| 66 case CONFIG_UNSET: |
| 67 return "config_unset"; |
| 68 } |
| 69 NOTREACHED(); |
| 70 return ""; |
| 71 } |
| 72 |
| 54 } // namespace ProxyPrefs | 73 } // namespace ProxyPrefs |
| OLD | NEW |