proxy_prefs.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "components/proxy_config/proxy_prefs.h"
  5. #include "base/check.h"
  6. #include "base/notreached.h"
  7. namespace ProxyPrefs {
  8. namespace {
  9. // These names are exposed to the proxy extension API. They must be in sync
  10. // with the constants of ProxyPrefs.
  11. const char* kProxyModeNames[] = { kDirectProxyModeName,
  12. kAutoDetectProxyModeName,
  13. kPacScriptProxyModeName,
  14. kFixedServersProxyModeName,
  15. kSystemProxyModeName };
  16. static_assert(std::size(kProxyModeNames) == kModeCount,
  17. "kProxyModeNames must have kModeCount elements");
  18. } // namespace
  19. const char kDirectProxyModeName[] = "direct";
  20. const char kAutoDetectProxyModeName[] = "auto_detect";
  21. const char kPacScriptProxyModeName[] = "pac_script";
  22. const char kFixedServersProxyModeName[] = "fixed_servers";
  23. const char kSystemProxyModeName[] = "system";
  24. bool IntToProxyMode(int in_value, ProxyMode* out_value) {
  25. DCHECK(out_value);
  26. if (in_value < 0 || in_value >= kModeCount)
  27. return false;
  28. *out_value = static_cast<ProxyMode>(in_value);
  29. return true;
  30. }
  31. bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) {
  32. DCHECK(out_value);
  33. for (int i = 0; i < kModeCount; i++) {
  34. if (in_value == kProxyModeNames[i])
  35. return IntToProxyMode(i, out_value);
  36. }
  37. return false;
  38. }
  39. const char* ProxyModeToString(ProxyMode mode) {
  40. return kProxyModeNames[mode];
  41. }
  42. std::string ConfigStateToDebugString(ConfigState state) {
  43. switch (state) {
  44. case CONFIG_POLICY:
  45. return "config_policy";
  46. case CONFIG_EXTENSION:
  47. return "config_extension";
  48. case CONFIG_OTHER_PRECEDE:
  49. return "config_other_precede";
  50. case CONFIG_SYSTEM:
  51. return "config_system";
  52. case CONFIG_FALLBACK:
  53. return "config_fallback";
  54. case CONFIG_UNSET:
  55. return "config_unset";
  56. }
  57. NOTREACHED();
  58. return "";
  59. }
  60. } // namespace ProxyPrefs