proxy_config_dictionary.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2011 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. #ifndef COMPONENTS_PROXY_CONFIG_PROXY_CONFIG_DICTIONARY_H_
  5. #define COMPONENTS_PROXY_CONFIG_PROXY_CONFIG_DICTIONARY_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/values.h"
  9. #include "components/proxy_config/proxy_config_export.h"
  10. #include "components/proxy_config/proxy_prefs.h"
  11. namespace net {
  12. class ProxyServer;
  13. }
  14. // Factory and wrapper for proxy config dictionaries that are stored
  15. // in the user preferences. The dictionary has the following structure:
  16. // {
  17. // mode: string,
  18. // server: string,
  19. // pac_url: string,
  20. // bypass_list: string
  21. // }
  22. // See proxy_config_dictionary.cc for the structure of the respective strings.
  23. class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  24. public:
  25. // Takes ownership of |dict| (|dict| will be moved to |dict_|).
  26. explicit ProxyConfigDictionary(base::Value dict);
  27. ProxyConfigDictionary(ProxyConfigDictionary&& other);
  28. ProxyConfigDictionary(const ProxyConfigDictionary&) = delete;
  29. ProxyConfigDictionary& operator=(const ProxyConfigDictionary&) = delete;
  30. ~ProxyConfigDictionary();
  31. bool GetMode(ProxyPrefs::ProxyMode* out) const;
  32. bool GetPacUrl(std::string* out) const;
  33. bool GetPacMandatory(bool* out) const;
  34. bool GetProxyServer(std::string* out) const;
  35. bool GetBypassList(std::string* out) const;
  36. bool HasBypassList() const;
  37. const base::Value& GetDictionary() const;
  38. static base::Value CreateDirect();
  39. static base::Value CreateAutoDetect();
  40. static base::Value CreatePacScript(const std::string& pac_url,
  41. bool pac_mandatory);
  42. static base::Value CreateFixedServers(const std::string& proxy_server,
  43. const std::string& bypass_list);
  44. static base::Value CreateSystem();
  45. // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>".
  46. // Used to generate the |proxy_server| arg for CreateFixedServers().
  47. static void EncodeAndAppendProxyServer(const std::string& url_scheme,
  48. const net::ProxyServer& server,
  49. std::string* spec);
  50. private:
  51. bool GetString(const char* key, std::string* out) const;
  52. static base::Value CreateDictionary(ProxyPrefs::ProxyMode mode,
  53. const std::string& pac_url,
  54. bool pac_mandatory,
  55. const std::string& proxy_server,
  56. const std::string& bypass_list);
  57. base::Value dict_;
  58. };
  59. #endif // COMPONENTS_PROXY_CONFIG_PROXY_CONFIG_DICTIONARY_H_