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