Home | History | Annotate | Download | only in prefs
      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 
     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 
     20 namespace {
     21 
     22 // These names are exposed to the proxy extension API. They must be in sync
     23 // with the constants of ProxyPrefs.
     24 const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName,
     25                                   ProxyPrefs::kAutoDetectProxyModeName,
     26                                   ProxyPrefs::kPacScriptProxyModeName,
     27                                   ProxyPrefs::kFixedServersProxyModeName,
     28                                   ProxyPrefs::kSystemProxyModeName };
     29 
     30 }  // namespace
     31 
     32 namespace ProxyPrefs {
     33 
     34 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount,
     35                kProxyModeNames_must_have_size_of_NUM_MODES);
     36 
     37 bool 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
     46 bool 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 
     55 const char* ProxyModeToString(ProxyMode mode) {
     56   return kProxyModeNames[mode];
     57 }
     58 
     59 }  // namespace
     60