| 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 |
| 12 const char kDirectProxyModeName[] = "direct"; |
| 13 const char kAutoDetectProxyModeName[] = "auto_detect"; |
| 14 const char kPacScriptProxyModeName[] = "pac_script"; |
| 15 const char kFixedServersProxyModeName[] = "fixed_servers"; |
| 16 const char kSystemProxyModeName[] = "system"; |
| 17 |
| 18 } |
| 19 |
| 10 namespace { | 20 namespace { |
| 11 | 21 |
| 12 // These names are exposed to the proxy extension API. They must be in sync | 22 // These names are exposed to the proxy extension API. They must be in sync |
| 13 // with the constants of ProxyPrefs. | 23 // with the constants of ProxyPrefs. |
| 14 const char* kProxyModeNames[] = { "direct", | 24 const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName, |
| 15 "auto_detect", | 25 ProxyPrefs::kAutoDetectProxyModeName, |
| 16 "pac_script", | 26 ProxyPrefs::kPacScriptProxyModeName, |
| 17 "fixed_servers", | 27 ProxyPrefs::kFixedServersProxyModeName, |
| 18 "system" }; | 28 ProxyPrefs::kSystemProxyModeName }; |
| 19 | 29 |
| 20 } // namespace | 30 } // namespace |
| 21 | 31 |
| 22 namespace ProxyPrefs { | 32 namespace ProxyPrefs { |
| 23 | 33 |
| 24 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount, | 34 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount, |
| 25 kProxyModeNames_must_have_size_of_NUM_MODES); | 35 kProxyModeNames_must_have_size_of_NUM_MODES); |
| 26 | 36 |
| 27 bool IntToProxyMode(int in_value, ProxyMode* out_value) { | 37 bool IntToProxyMode(int in_value, ProxyMode* out_value) { |
| 28 DCHECK(out_value); | 38 DCHECK(out_value); |
| 29 if (in_value < 0 || in_value >= kModeCount) | 39 if (in_value < 0 || in_value >= kModeCount) |
| 30 return false; | 40 return false; |
| 31 *out_value = static_cast<ProxyMode>(in_value); | 41 *out_value = static_cast<ProxyMode>(in_value); |
| 32 return true; | 42 return true; |
| 33 } | 43 } |
| 34 | 44 |
| 35 // static | 45 // static |
| 36 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) { | 46 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) { |
| 37 DCHECK(out_value); | 47 DCHECK(out_value); |
| 38 for (int i = 0; i < kModeCount; i++) { | 48 for (int i = 0; i < kModeCount; i++) { |
| 39 if (in_value == kProxyModeNames[i]) | 49 if (in_value == kProxyModeNames[i]) |
| 40 return IntToProxyMode(i, out_value); | 50 return IntToProxyMode(i, out_value); |
| 41 } | 51 } |
| 42 return false; | 52 return false; |
| 43 } | 53 } |
| 44 | 54 |
| 45 } // namespace | 55 } // namespace |
| OLD | NEW |