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
3 // found in the LICENSE file.
5 #include "chrome/browser/prefs/proxy_prefs.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
12 // These names are exposed to the proxy extension API. They must be in sync
13 // with the constants of ProxyPrefs.
14 const char* kProxyModeNames
[] = { ProxyPrefs::kDirectProxyModeName
,
15 ProxyPrefs::kAutoDetectProxyModeName
,
16 ProxyPrefs::kPacScriptProxyModeName
,
17 ProxyPrefs::kFixedServersProxyModeName
,
18 ProxyPrefs::kSystemProxyModeName
};
20 COMPILE_ASSERT(arraysize(kProxyModeNames
) == ProxyPrefs::kModeCount
,
21 kProxyModeNames_must_have_size_of_NUM_MODES
);
25 namespace ProxyPrefs
{
27 const char kDirectProxyModeName
[] = "direct";
28 const char kAutoDetectProxyModeName
[] = "auto_detect";
29 const char kPacScriptProxyModeName
[] = "pac_script";
30 const char kFixedServersProxyModeName
[] = "fixed_servers";
31 const char kSystemProxyModeName
[] = "system";
33 bool IntToProxyMode(int in_value
, ProxyMode
* out_value
) {
35 if (in_value
< 0 || in_value
>= kModeCount
)
37 *out_value
= static_cast<ProxyMode
>(in_value
);
41 bool StringToProxyMode(const std::string
& in_value
, ProxyMode
* out_value
) {
43 for (int i
= 0; i
< kModeCount
; i
++) {
44 if (in_value
== kProxyModeNames
[i
])
45 return IntToProxyMode(i
, out_value
);
50 const char* ProxyModeToString(ProxyMode mode
) {
51 return kProxyModeNames
[mode
];
54 } // namespace ProxyPrefs