OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 5 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Optional boolean flag indicating whether a valid PAC script is mandatory. | 22 // Optional boolean flag indicating whether a valid PAC script is mandatory. |
23 // If true, network traffic does not fall back to direct connections in case the | 23 // If true, network traffic does not fall back to direct connections in case the |
24 // PAC script is not available. | 24 // PAC script is not available. |
25 const char kProxyPacMandatory[] = "pac_mandatory"; | 25 const char kProxyPacMandatory[] = "pac_mandatory"; |
26 // String containing proxy bypass rules. For a specification of the | 26 // String containing proxy bypass rules. For a specification of the |
27 // expected syntax see net::ProxyBypassRules::ParseFromString(). | 27 // expected syntax see net::ProxyBypassRules::ParseFromString(). |
28 const char kProxyBypassList[] = "bypass_list"; | 28 const char kProxyBypassList[] = "bypass_list"; |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 ProxyConfigDictionary::ProxyConfigDictionary(const DictionaryValue* dict) | 32 ProxyConfigDictionary::ProxyConfigDictionary(const base::DictionaryValue* dict) |
33 : dict_(dict->DeepCopy()) { | 33 : dict_(dict->DeepCopy()) { |
34 } | 34 } |
35 | 35 |
36 ProxyConfigDictionary::~ProxyConfigDictionary() {} | 36 ProxyConfigDictionary::~ProxyConfigDictionary() {} |
37 | 37 |
38 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { | 38 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { |
39 std::string mode_str; | 39 std::string mode_str; |
40 return dict_->GetString(kProxyMode, &mode_str) | 40 return dict_->GetString(kProxyMode, &mode_str) |
41 && StringToProxyMode(mode_str, out); | 41 && StringToProxyMode(mode_str, out); |
42 } | 42 } |
(...skipping 15 matching lines...) Expand all Loading... |
58 } | 58 } |
59 | 59 |
60 bool ProxyConfigDictionary::GetBypassList(std::string* out) const { | 60 bool ProxyConfigDictionary::GetBypassList(std::string* out) const { |
61 return dict_->GetString(kProxyBypassList, out); | 61 return dict_->GetString(kProxyBypassList, out); |
62 } | 62 } |
63 | 63 |
64 bool ProxyConfigDictionary::HasBypassList() const { | 64 bool ProxyConfigDictionary::HasBypassList() const { |
65 return dict_->HasKey(kProxyBypassList); | 65 return dict_->HasKey(kProxyBypassList); |
66 } | 66 } |
67 | 67 |
68 const DictionaryValue& ProxyConfigDictionary::GetDictionary() const { | 68 const base::DictionaryValue& ProxyConfigDictionary::GetDictionary() const { |
69 return *dict_; | 69 return *dict_; |
70 } | 70 } |
71 | 71 |
72 // static | 72 // static |
73 DictionaryValue* ProxyConfigDictionary::CreateDirect() { | 73 base::DictionaryValue* ProxyConfigDictionary::CreateDirect() { |
74 return CreateDictionary(ProxyPrefs::MODE_DIRECT, | 74 return CreateDictionary(ProxyPrefs::MODE_DIRECT, |
75 std::string(), | 75 std::string(), |
76 false, | 76 false, |
77 std::string(), | 77 std::string(), |
78 std::string()); | 78 std::string()); |
79 } | 79 } |
80 | 80 |
81 // static | 81 // static |
82 DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { | 82 base::DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { |
83 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, | 83 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, |
84 std::string(), | 84 std::string(), |
85 false, | 85 false, |
86 std::string(), | 86 std::string(), |
87 std::string()); | 87 std::string()); |
88 } | 88 } |
89 | 89 |
90 // static | 90 // static |
91 DictionaryValue* ProxyConfigDictionary::CreatePacScript( | 91 base::DictionaryValue* ProxyConfigDictionary::CreatePacScript( |
92 const std::string& pac_url, | 92 const std::string& pac_url, |
93 bool pac_mandatory) { | 93 bool pac_mandatory) { |
94 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, | 94 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, |
95 pac_url, | 95 pac_url, |
96 pac_mandatory, | 96 pac_mandatory, |
97 std::string(), | 97 std::string(), |
98 std::string()); | 98 std::string()); |
99 } | 99 } |
100 | 100 |
101 // static | 101 // static |
102 DictionaryValue* ProxyConfigDictionary::CreateFixedServers( | 102 base::DictionaryValue* ProxyConfigDictionary::CreateFixedServers( |
103 const std::string& proxy_server, | 103 const std::string& proxy_server, |
104 const std::string& bypass_list) { | 104 const std::string& bypass_list) { |
105 if (!proxy_server.empty()) { | 105 if (!proxy_server.empty()) { |
106 return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, | 106 return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, |
107 std::string(), | 107 std::string(), |
108 false, | 108 false, |
109 proxy_server, | 109 proxy_server, |
110 bypass_list); | 110 bypass_list); |
111 } else { | 111 } else { |
112 return CreateDirect(); | 112 return CreateDirect(); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 DictionaryValue* ProxyConfigDictionary::CreateSystem() { | 117 base::DictionaryValue* ProxyConfigDictionary::CreateSystem() { |
118 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, | 118 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, |
119 std::string(), | 119 std::string(), |
120 false, | 120 false, |
121 std::string(), | 121 std::string(), |
122 std::string()); | 122 std::string()); |
123 } | 123 } |
124 | 124 |
125 // static | 125 // static |
126 DictionaryValue* ProxyConfigDictionary::CreateDictionary( | 126 base::DictionaryValue* ProxyConfigDictionary::CreateDictionary( |
127 ProxyPrefs::ProxyMode mode, | 127 ProxyPrefs::ProxyMode mode, |
128 const std::string& pac_url, | 128 const std::string& pac_url, |
129 bool pac_mandatory, | 129 bool pac_mandatory, |
130 const std::string& proxy_server, | 130 const std::string& proxy_server, |
131 const std::string& bypass_list) { | 131 const std::string& bypass_list) { |
132 DictionaryValue* dict = new DictionaryValue(); | 132 base::DictionaryValue* dict = new base::DictionaryValue(); |
133 dict->SetString(kProxyMode, ProxyModeToString(mode)); | 133 dict->SetString(kProxyMode, ProxyModeToString(mode)); |
134 if (!pac_url.empty()) { | 134 if (!pac_url.empty()) { |
135 dict->SetString(kProxyPacUrl, pac_url); | 135 dict->SetString(kProxyPacUrl, pac_url); |
136 dict->SetBoolean(kProxyPacMandatory, pac_mandatory); | 136 dict->SetBoolean(kProxyPacMandatory, pac_mandatory); |
137 } | 137 } |
138 if (!proxy_server.empty()) | 138 if (!proxy_server.empty()) |
139 dict->SetString(kProxyServer, proxy_server); | 139 dict->SetString(kProxyServer, proxy_server); |
140 if (!bypass_list.empty()) | 140 if (!bypass_list.empty()) |
141 dict->SetString(kProxyBypassList, bypass_list); | 141 dict->SetString(kProxyBypassList, bypass_list); |
142 return dict; | 142 return dict; |
143 } | 143 } |
OLD | NEW |