Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 "net/proxy/proxy_config.h" | 5 #include "net/proxy/proxy_config.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_tokenizer.h" | 8 #include "base/string_tokenizer.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "net/proxy/proxy_info.h" | 11 #include "net/proxy/proxy_info.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 DCHECK_EQ(TYPE_PROXY_PER_SCHEME, type); | 151 DCHECK_EQ(TYPE_PROXY_PER_SCHEME, type); |
| 152 if (scheme == "http") | 152 if (scheme == "http") |
| 153 return &proxy_for_http; | 153 return &proxy_for_http; |
| 154 if (scheme == "https") | 154 if (scheme == "https") |
| 155 return &proxy_for_https; | 155 return &proxy_for_https; |
| 156 if (scheme == "ftp") | 156 if (scheme == "ftp") |
| 157 return &proxy_for_ftp; | 157 return &proxy_for_ftp; |
| 158 return NULL; // No mapping for this scheme. | 158 return NULL; // No mapping for this scheme. |
| 159 } | 159 } |
| 160 | 160 |
| 161 ProxyConfig::ProxyConfig() : auto_detect_(false), id_(INVALID_ID) { | 161 ProxyConfig::ProxyConfig() |
| 162 : auto_detect_(false), pac_mandatory_(false), id_(INVALID_ID) { | |
| 162 } | 163 } |
| 163 | 164 |
| 164 ProxyConfig::ProxyConfig(const ProxyConfig& config) | 165 ProxyConfig::ProxyConfig(const ProxyConfig& config) |
| 165 : auto_detect_(config.auto_detect_), | 166 : auto_detect_(config.auto_detect_), |
| 166 pac_url_(config.pac_url_), | 167 pac_url_(config.pac_url_), |
| 168 pac_mandatory_(config.pac_mandatory_), | |
| 167 proxy_rules_(config.proxy_rules_), | 169 proxy_rules_(config.proxy_rules_), |
| 168 id_(config.id_) { | 170 id_(config.id_) { |
| 169 } | 171 } |
| 170 | 172 |
| 171 ProxyConfig::~ProxyConfig() { | 173 ProxyConfig::~ProxyConfig() { |
| 172 } | 174 } |
| 173 | 175 |
| 174 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { | 176 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { |
| 175 auto_detect_ = config.auto_detect_; | 177 auto_detect_ = config.auto_detect_; |
| 176 pac_url_ = config.pac_url_; | 178 pac_url_ = config.pac_url_; |
| 179 pac_mandatory_ = config.pac_mandatory_; | |
| 177 proxy_rules_ = config.proxy_rules_; | 180 proxy_rules_ = config.proxy_rules_; |
| 178 id_ = config.id_; | 181 id_ = config.id_; |
| 179 return *this; | 182 return *this; |
| 180 } | 183 } |
| 181 | 184 |
| 182 bool ProxyConfig::Equals(const ProxyConfig& other) const { | 185 bool ProxyConfig::Equals(const ProxyConfig& other) const { |
| 183 // The two configs can have different IDs. We are just interested in if they | 186 // The two configs can have different IDs. We are just interested in if they |
| 184 // have the same settings. | 187 // have the same settings. |
| 185 return auto_detect_ == other.auto_detect_ && | 188 return auto_detect_ == other.auto_detect_ && |
| 186 pac_url_ == other.pac_url_ && | 189 pac_url_ == other.pac_url_ && |
| 190 pac_mandatory_ == other.pac_mandatory_ && | |
| 187 proxy_rules_.Equals(other.proxy_rules()); | 191 proxy_rules_.Equals(other.proxy_rules()); |
| 188 } | 192 } |
| 189 | 193 |
| 190 bool ProxyConfig::HasAutomaticSettings() const { | 194 bool ProxyConfig::HasAutomaticSettings() const { |
| 191 return auto_detect_ || has_pac_url(); | 195 return auto_detect_ || has_pac_url(); |
| 192 } | 196 } |
| 193 | 197 |
| 194 void ProxyConfig::ClearAutomaticSettings() { | 198 void ProxyConfig::ClearAutomaticSettings() { |
| 195 auto_detect_ = false; | 199 auto_detect_ = false; |
| 196 pac_url_ = GURL(); | 200 pac_url_ = GURL(); |
| 197 } | 201 } |
| 198 | 202 |
| 199 Value* ProxyConfig::ToValue() const { | 203 Value* ProxyConfig::ToValue() const { |
| 200 DictionaryValue* dict = new DictionaryValue(); | 204 DictionaryValue* dict = new DictionaryValue(); |
| 201 | 205 |
| 202 // Output the automatic settings. | 206 // Output the automatic settings. |
| 203 if (auto_detect_) | 207 if (auto_detect_) |
| 204 dict->SetBoolean("auto_detect", auto_detect_); | 208 dict->SetBoolean("auto_detect", auto_detect_); |
| 205 if (has_pac_url()) | 209 if (has_pac_url()) |
| 206 dict->SetString("pac_url", pac_url_.possibly_invalid_spec()); | 210 dict->SetString("pac_url", pac_url_.possibly_invalid_spec()); |
| 211 if (pac_mandatory_) | |
|
eroman
2011/05/03 09:45:24
can you add this within the "has_pac_url()" case a
battre
2011/05/03 09:55:14
Done.
| |
| 212 dict->SetBoolean("pac_mandatory", pac_mandatory_); | |
| 207 | 213 |
| 208 // Output the manual settings. | 214 // Output the manual settings. |
| 209 if (proxy_rules_.type != ProxyRules::TYPE_NO_RULES) { | 215 if (proxy_rules_.type != ProxyRules::TYPE_NO_RULES) { |
| 210 switch (proxy_rules_.type) { | 216 switch (proxy_rules_.type) { |
| 211 case ProxyRules::TYPE_SINGLE_PROXY: | 217 case ProxyRules::TYPE_SINGLE_PROXY: |
| 212 AddProxyToValue("single_proxy", proxy_rules_.single_proxy, dict); | 218 AddProxyToValue("single_proxy", proxy_rules_.single_proxy, dict); |
| 213 break; | 219 break; |
| 214 case ProxyRules::TYPE_PROXY_PER_SCHEME: { | 220 case ProxyRules::TYPE_PROXY_PER_SCHEME: { |
| 215 DictionaryValue* dict2 = new DictionaryValue(); | 221 DictionaryValue* dict2 = new DictionaryValue(); |
| 216 AddProxyToValue("http", proxy_rules_.proxy_for_http, dict2); | 222 AddProxyToValue("http", proxy_rules_.proxy_for_http, dict2); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 239 } | 245 } |
| 240 | 246 |
| 241 dict->Set("bypass_list", list); | 247 dict->Set("bypass_list", list); |
| 242 } | 248 } |
| 243 } | 249 } |
| 244 | 250 |
| 245 return dict; | 251 return dict; |
| 246 } | 252 } |
| 247 | 253 |
| 248 } // namespace net | 254 } // namespace net |
| 249 | |
| OLD | NEW |