Chromium Code Reviews| 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 "net/proxy/init_proxy_resolver.h" | 5 #include "net/proxy/proxy_script_decider.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | |
| 11 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
| 12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 13 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 14 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 14 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" | 15 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" |
| 15 #include "net/proxy/proxy_config.h" | |
| 16 #include "net/proxy/proxy_resolver.h" | |
| 17 #include "net/proxy/proxy_script_fetcher.h" | 16 #include "net/proxy/proxy_script_fetcher.h" |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 20 namespace { | |
| 21 bool LooksLikePacScript(const string16& script) { | |
| 22 // Note: this is only an approximation! It may not always work correctly, | |
| 23 // however it is very likely that legitimate scripts have this exact string, | |
| 24 // since they must minimally define a function of this name. Conversely, a | |
| 25 // file not containing the string is not likely to be a PAC script. | |
| 26 // | |
| 27 // An exact test would have to load the script in a javascript evaluator. | |
| 28 return script.find(ASCIIToUTF16("FindProxyForURL")) != string16::npos; | |
| 29 } | |
| 30 } | |
| 31 | |
| 21 // This is the hard-coded location used by the DNS portion of web proxy | 32 // This is the hard-coded location used by the DNS portion of web proxy |
| 22 // auto-discovery. | 33 // auto-discovery. |
| 23 // | 34 // |
| 24 // Note that we not use DNS devolution to find the WPAD host, since that could | 35 // Note that we not use DNS devolution to find the WPAD host, since that could |
| 25 // be dangerous should our top level domain registry become out of date. | 36 // be dangerous should our top level domain registry become out of date. |
| 26 // | 37 // |
| 27 // Instead we directly resolve "wpad", and let the operating system apply the | 38 // Instead we directly resolve "wpad", and let the operating system apply the |
| 28 // DNS suffix search paths. This is the same approach taken by Firefox, and | 39 // DNS suffix search paths. This is the same approach taken by Firefox, and |
| 29 // compatibility hasn't been an issue. | 40 // compatibility hasn't been an issue. |
| 30 // | 41 // |
| 31 // For more details, also check out this comment: | 42 // For more details, also check out this comment: |
| 32 // http://code.google.com/p/chromium/issues/detail?id=18575#c20 | 43 // http://code.google.com/p/chromium/issues/detail?id=18575#c20 |
| 33 static const char kWpadUrl[] = "http://wpad/wpad.dat"; | 44 static const char kWpadUrl[] = "http://wpad/wpad.dat"; |
| 34 | 45 |
| 35 InitProxyResolver::InitProxyResolver( | 46 ProxyScriptDecider::ProxyScriptDecider( |
| 36 ProxyResolver* resolver, | |
| 37 ProxyScriptFetcher* proxy_script_fetcher, | 47 ProxyScriptFetcher* proxy_script_fetcher, |
| 38 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | 48 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, |
| 39 NetLog* net_log) | 49 NetLog* net_log) |
| 40 : resolver_(resolver), | 50 : proxy_script_fetcher_(proxy_script_fetcher), |
| 41 proxy_script_fetcher_(proxy_script_fetcher), | |
| 42 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), | 51 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), |
| 43 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | 52 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( |
| 44 this, &InitProxyResolver::OnIOCompletion)), | 53 this, &ProxyScriptDecider::OnIOCompletion)), |
| 45 user_callback_(NULL), | 54 user_callback_(NULL), |
| 46 current_pac_source_index_(0u), | 55 current_pac_source_index_(0u), |
| 47 pac_mandatory_(false), | 56 pac_mandatory_(false), |
| 48 next_state_(STATE_NONE), | 57 next_state_(STATE_NONE), |
| 49 net_log_(BoundNetLog::Make( | 58 net_log_(BoundNetLog::Make( |
| 50 net_log, NetLog::SOURCE_INIT_PROXY_RESOLVER)), | 59 net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)), |
| 51 effective_config_(NULL) { | 60 fetch_pac_bytes_(false) { |
| 52 } | 61 } |
| 53 | 62 |
| 54 InitProxyResolver::~InitProxyResolver() { | 63 ProxyScriptDecider::~ProxyScriptDecider() { |
| 55 if (next_state_ != STATE_NONE) | 64 if (next_state_ != STATE_NONE) |
| 56 Cancel(); | 65 Cancel(); |
| 57 } | 66 } |
| 58 | 67 |
| 59 int InitProxyResolver::Init(const ProxyConfig& config, | 68 int ProxyScriptDecider::Start(const ProxyConfig& config, |
| 60 const base::TimeDelta wait_delay, | 69 const base::TimeDelta wait_delay, |
| 61 ProxyConfig* effective_config, | 70 bool fetch_pac_bytes, |
| 62 OldCompletionCallback* callback) { | 71 OldCompletionCallback* callback) { |
| 63 DCHECK_EQ(STATE_NONE, next_state_); | 72 DCHECK_EQ(STATE_NONE, next_state_); |
| 64 DCHECK(callback); | 73 DCHECK(callback); |
| 65 DCHECK(config.HasAutomaticSettings()); | 74 DCHECK(config.HasAutomaticSettings()); |
| 66 | 75 |
| 67 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); | 76 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER, NULL); |
| 77 | |
| 78 fetch_pac_bytes_ = fetch_pac_bytes; | |
| 68 | 79 |
| 69 // Save the |wait_delay| as a non-negative value. | 80 // Save the |wait_delay| as a non-negative value. |
| 70 wait_delay_ = wait_delay; | 81 wait_delay_ = wait_delay; |
| 71 if (wait_delay_ < base::TimeDelta()) | 82 if (wait_delay_ < base::TimeDelta()) |
| 72 wait_delay_ = base::TimeDelta(); | 83 wait_delay_ = base::TimeDelta(); |
| 73 | 84 |
| 74 effective_config_ = effective_config; | |
| 75 | |
| 76 pac_mandatory_ = config.pac_mandatory(); | 85 pac_mandatory_ = config.pac_mandatory(); |
| 77 | 86 |
| 78 pac_sources_ = BuildPacSourcesFallbackList(config); | 87 pac_sources_ = BuildPacSourcesFallbackList(config); |
| 79 DCHECK(!pac_sources_.empty()); | 88 DCHECK(!pac_sources_.empty()); |
| 80 | 89 |
| 81 next_state_ = STATE_WAIT; | 90 next_state_ = STATE_WAIT; |
| 82 | 91 |
| 83 int rv = DoLoop(OK); | 92 int rv = DoLoop(OK); |
| 84 if (rv == ERR_IO_PENDING) | 93 if (rv == ERR_IO_PENDING) |
| 85 user_callback_ = callback; | 94 user_callback_ = callback; |
| 86 else | 95 else |
| 87 DidCompleteInit(); | 96 DidComplete(); |
| 88 | 97 |
| 89 return rv; | 98 return rv; |
| 90 } | 99 } |
| 91 | 100 |
| 92 // Initialize the fallback rules. | 101 // Initialize the fallback rules. |
| 93 // (1) WPAD (DHCP). | 102 // (1) WPAD (DHCP). |
| 94 // (2) WPAD (DNS). | 103 // (2) WPAD (DNS). |
| 95 // (3) Custom PAC URL. | 104 // (3) Custom PAC URL. |
| 96 InitProxyResolver::PacSourceList InitProxyResolver::BuildPacSourcesFallbackList( | 105 ProxyScriptDecider::PacSourceList ProxyScriptDecider:: |
| 106 BuildPacSourcesFallbackList( | |
| 97 const ProxyConfig& config) const { | 107 const ProxyConfig& config) const { |
| 98 PacSourceList pac_sources; | 108 PacSourceList pac_sources; |
| 99 if (config.auto_detect()) { | 109 if (config.auto_detect()) { |
| 100 pac_sources.push_back(PacSource(PacSource::WPAD_DHCP, GURL())); | 110 pac_sources.push_back(PacSource(PacSource::WPAD_DHCP, GURL())); |
| 101 pac_sources.push_back(PacSource(PacSource::WPAD_DNS, GURL())); | 111 pac_sources.push_back(PacSource(PacSource::WPAD_DNS, GURL())); |
| 102 } | 112 } |
| 103 if (config.has_pac_url()) | 113 if (config.has_pac_url()) |
| 104 pac_sources.push_back(PacSource(PacSource::CUSTOM, config.pac_url())); | 114 pac_sources.push_back(PacSource(PacSource::CUSTOM, config.pac_url())); |
| 105 return pac_sources; | 115 return pac_sources; |
| 106 } | 116 } |
| 107 | 117 |
| 108 void InitProxyResolver::OnIOCompletion(int result) { | 118 void ProxyScriptDecider::OnIOCompletion(int result) { |
| 109 DCHECK_NE(STATE_NONE, next_state_); | 119 DCHECK_NE(STATE_NONE, next_state_); |
| 110 int rv = DoLoop(result); | 120 int rv = DoLoop(result); |
| 111 if (rv != ERR_IO_PENDING) { | 121 if (rv != ERR_IO_PENDING) { |
| 112 DidCompleteInit(); | 122 DidComplete(); |
| 113 DoCallback(rv); | 123 DoCallback(rv); |
| 114 } | 124 } |
| 115 } | 125 } |
| 116 | 126 |
| 117 int InitProxyResolver::DoLoop(int result) { | 127 int ProxyScriptDecider::DoLoop(int result) { |
| 118 DCHECK_NE(next_state_, STATE_NONE); | 128 DCHECK_NE(next_state_, STATE_NONE); |
| 119 int rv = result; | 129 int rv = result; |
| 120 do { | 130 do { |
| 121 State state = next_state_; | 131 State state = next_state_; |
| 122 next_state_ = STATE_NONE; | 132 next_state_ = STATE_NONE; |
| 123 switch (state) { | 133 switch (state) { |
| 124 case STATE_WAIT: | 134 case STATE_WAIT: |
| 125 DCHECK_EQ(OK, rv); | 135 DCHECK_EQ(OK, rv); |
| 126 rv = DoWait(); | 136 rv = DoWait(); |
| 127 break; | 137 break; |
| 128 case STATE_WAIT_COMPLETE: | 138 case STATE_WAIT_COMPLETE: |
| 129 rv = DoWaitComplete(rv); | 139 rv = DoWaitComplete(rv); |
| 130 break; | 140 break; |
| 131 case STATE_FETCH_PAC_SCRIPT: | 141 case STATE_FETCH_PAC_SCRIPT: |
| 132 DCHECK_EQ(OK, rv); | 142 DCHECK_EQ(OK, rv); |
| 133 rv = DoFetchPacScript(); | 143 rv = DoFetchPacScript(); |
| 134 break; | 144 break; |
| 135 case STATE_FETCH_PAC_SCRIPT_COMPLETE: | 145 case STATE_FETCH_PAC_SCRIPT_COMPLETE: |
| 136 rv = DoFetchPacScriptComplete(rv); | 146 rv = DoFetchPacScriptComplete(rv); |
| 137 break; | 147 break; |
| 138 case STATE_SET_PAC_SCRIPT: | 148 case STATE_VERIFY_PAC_SCRIPT: |
| 139 DCHECK_EQ(OK, rv); | 149 DCHECK_EQ(OK, rv); |
| 140 rv = DoSetPacScript(); | 150 rv = DoVerifyPacScript(); |
| 141 break; | |
| 142 case STATE_SET_PAC_SCRIPT_COMPLETE: | |
| 143 rv = DoSetPacScriptComplete(rv); | |
| 144 break; | 151 break; |
| 145 default: | 152 default: |
| 146 NOTREACHED() << "bad state"; | 153 NOTREACHED() << "bad state"; |
| 147 rv = ERR_UNEXPECTED; | 154 rv = ERR_UNEXPECTED; |
| 148 break; | 155 break; |
| 149 } | 156 } |
| 150 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 157 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 151 return rv; | 158 return rv; |
| 152 } | 159 } |
| 153 | 160 |
| 154 void InitProxyResolver::DoCallback(int result) { | 161 void ProxyScriptDecider::DoCallback(int result) { |
| 155 DCHECK_NE(ERR_IO_PENDING, result); | 162 DCHECK_NE(ERR_IO_PENDING, result); |
| 156 DCHECK(user_callback_); | 163 DCHECK(user_callback_); |
| 157 user_callback_->Run(result); | 164 user_callback_->Run(result); |
| 158 } | 165 } |
| 159 | 166 |
| 160 int InitProxyResolver::DoWait() { | 167 int ProxyScriptDecider::DoWait() { |
| 161 next_state_ = STATE_WAIT_COMPLETE; | 168 next_state_ = STATE_WAIT_COMPLETE; |
| 162 | 169 |
| 163 // If no waiting is required, continue on to the next state. | 170 // If no waiting is required, continue on to the next state. |
| 164 if (wait_delay_.ToInternalValue() == 0) | 171 if (wait_delay_.ToInternalValue() == 0) |
| 165 return OK; | 172 return OK; |
| 166 | 173 |
| 167 // Otherwise wait the specified amount of time. | 174 // Otherwise wait the specified amount of time. |
| 168 wait_timer_.Start(FROM_HERE, wait_delay_, this, | 175 wait_timer_.Start(FROM_HERE, wait_delay_, this, |
| 169 &InitProxyResolver::OnWaitTimerFired); | 176 &ProxyScriptDecider::OnWaitTimerFired); |
| 170 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT, NULL); | 177 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT, NULL); |
| 171 return ERR_IO_PENDING; | 178 return ERR_IO_PENDING; |
| 172 } | 179 } |
| 173 | 180 |
| 174 int InitProxyResolver::DoWaitComplete(int result) { | 181 int ProxyScriptDecider::DoWaitComplete(int result) { |
| 175 DCHECK_EQ(OK, result); | 182 DCHECK_EQ(OK, result); |
| 176 if (wait_delay_.ToInternalValue() != 0) { | 183 if (wait_delay_.ToInternalValue() != 0) { |
| 177 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT, | 184 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT, |
| 178 result); | 185 result); |
| 179 } | 186 } |
| 180 next_state_ = GetStartState(); | 187 next_state_ = GetStartState(); |
| 181 return OK; | 188 return OK; |
| 182 } | 189 } |
| 183 | 190 |
| 184 int InitProxyResolver::DoFetchPacScript() { | 191 int ProxyScriptDecider::DoFetchPacScript() { |
| 185 DCHECK(resolver_->expects_pac_bytes()); | 192 DCHECK(fetch_pac_bytes_); |
| 186 | 193 |
| 187 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; | 194 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; |
| 188 | 195 |
| 189 const PacSource& pac_source = current_pac_source(); | 196 const PacSource& pac_source = current_pac_source(); |
| 190 | 197 |
| 191 GURL effective_pac_url; | 198 GURL effective_pac_url; |
| 192 NetLogStringParameter* log_parameter = | 199 NetLogStringParameter* log_parameter = |
| 193 CreateNetLogParameterAndDetermineURL(pac_source, &effective_pac_url); | 200 CreateNetLogParameterAndDetermineURL(pac_source, &effective_pac_url); |
| 194 | 201 |
| 195 net_log_.BeginEvent( | 202 net_log_.BeginEvent( |
| 196 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, | 203 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, |
| 197 make_scoped_refptr(log_parameter)); | 204 make_scoped_refptr(log_parameter)); |
| 198 | 205 |
| 199 if (pac_source.type == PacSource::WPAD_DHCP) { | 206 if (pac_source.type == PacSource::WPAD_DHCP) { |
| 200 if (!dhcp_proxy_script_fetcher_) { | 207 if (!dhcp_proxy_script_fetcher_) { |
| 201 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); | 208 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER, NULL); |
| 202 return ERR_UNEXPECTED; | 209 return ERR_UNEXPECTED; |
| 203 } | 210 } |
| 204 | 211 |
| 205 return dhcp_proxy_script_fetcher_->Fetch(&pac_script_, &io_callback_); | 212 return dhcp_proxy_script_fetcher_->Fetch(&pac_script_, &io_callback_); |
| 206 } | 213 } |
| 207 | 214 |
| 208 if (!proxy_script_fetcher_) { | 215 if (!proxy_script_fetcher_) { |
| 209 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); | 216 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER, NULL); |
| 210 return ERR_UNEXPECTED; | 217 return ERR_UNEXPECTED; |
| 211 } | 218 } |
| 212 | 219 |
| 213 return proxy_script_fetcher_->Fetch( | 220 return proxy_script_fetcher_->Fetch( |
| 214 effective_pac_url, &pac_script_, &io_callback_); | 221 effective_pac_url, &pac_script_, &io_callback_); |
| 215 } | 222 } |
| 216 | 223 |
| 217 int InitProxyResolver::DoFetchPacScriptComplete(int result) { | 224 int ProxyScriptDecider::DoFetchPacScriptComplete(int result) { |
| 218 DCHECK(resolver_->expects_pac_bytes()); | 225 DCHECK(fetch_pac_bytes_); |
| 219 | 226 |
| 220 net_log_.EndEventWithNetErrorCode( | 227 net_log_.EndEventWithNetErrorCode( |
| 221 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, result); | 228 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, result); |
| 222 if (result != OK) | 229 if (result != OK) |
| 223 return TryToFallbackPacSource(result); | 230 return TryToFallbackPacSource(result); |
| 224 | 231 |
| 225 next_state_ = STATE_SET_PAC_SCRIPT; | 232 next_state_ = STATE_VERIFY_PAC_SCRIPT; |
|
willchan no longer on Chromium
2011/12/12 23:53:47
Can you just move the DoVerifyPacScript() code in
eroman
2011/12/13 00:10:26
There are situations where we start at STATE_VERIF
willchan no longer on Chromium
2011/12/13 01:17:09
OIC, ok this makes sense.
| |
| 226 return result; | 233 return result; |
| 227 } | 234 } |
| 228 | 235 |
| 229 int InitProxyResolver::DoSetPacScript() { | 236 int ProxyScriptDecider::DoVerifyPacScript() { |
| 230 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, NULL); | |
| 231 | |
| 232 const PacSource& pac_source = current_pac_source(); | 237 const PacSource& pac_source = current_pac_source(); |
| 233 | 238 |
| 234 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 239 // Make sure the script data is for a PAC script. If it isn't, then keep |
| 240 // looking through the fallback list for a candidate. | |
| 241 if (fetch_pac_bytes_ && !LooksLikePacScript(pac_script_)) | |
| 242 return TryToFallbackPacSource(ERR_PAC_SCRIPT_FAILED); | |
| 235 | 243 |
| 236 scoped_refptr<ProxyResolverScriptData> script_data; | 244 // Extract the current script data. |
| 237 | 245 if (fetch_pac_bytes_) { |
| 238 if (resolver_->expects_pac_bytes()) { | 246 script_data_ = ProxyResolverScriptData::FromUTF16(pac_script_); |
| 239 script_data = ProxyResolverScriptData::FromUTF16(pac_script_); | |
| 240 } else { | 247 } else { |
| 241 script_data = pac_source.type == PacSource::CUSTOM ? | 248 script_data_ = pac_source.type == PacSource::CUSTOM ? |
| 242 ProxyResolverScriptData::FromURL(pac_source.url) : | 249 ProxyResolverScriptData::FromURL(pac_source.url) : |
| 243 ProxyResolverScriptData::ForAutoDetect(); | 250 ProxyResolverScriptData::ForAutoDetect(); |
| 244 } | 251 } |
| 245 | 252 |
| 246 return resolver_->SetPacScript(script_data, &io_callback_); | |
| 247 } | |
| 248 | |
| 249 int InitProxyResolver::DoSetPacScriptComplete(int result) { | |
| 250 net_log_.EndEventWithNetErrorCode( | |
| 251 NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, result); | |
| 252 if (result != OK) | |
| 253 return TryToFallbackPacSource(result); | |
| 254 | |
| 255 // Let the caller know which automatic setting we ended up initializing the | 253 // Let the caller know which automatic setting we ended up initializing the |
| 256 // resolver for (there may have been multiple fallbacks to choose from.) | 254 // resolver for (there may have been multiple fallbacks to choose from.) |
| 257 if (effective_config_) { | 255 if (current_pac_source().type == PacSource::CUSTOM) { |
| 258 if (current_pac_source().type == PacSource::CUSTOM) { | 256 effective_config_ = |
| 259 *effective_config_ = | 257 ProxyConfig::CreateFromCustomPacURL(current_pac_source().url); |
| 260 ProxyConfig::CreateFromCustomPacURL(current_pac_source().url); | 258 effective_config_.set_pac_mandatory(pac_mandatory_); |
| 261 effective_config_->set_pac_mandatory(pac_mandatory_); | 259 } else { |
| 260 if (fetch_pac_bytes_) { | |
| 261 GURL auto_detected_url; | |
| 262 | |
| 263 switch (current_pac_source().type) { | |
| 264 case PacSource::WPAD_DHCP: | |
| 265 auto_detected_url = dhcp_proxy_script_fetcher_->GetPacURL(); | |
| 266 break; | |
| 267 | |
| 268 case PacSource::WPAD_DNS: | |
| 269 auto_detected_url = GURL(kWpadUrl); | |
| 270 break; | |
| 271 | |
| 272 default: | |
| 273 NOTREACHED(); | |
| 274 } | |
| 275 | |
| 276 effective_config_ = | |
| 277 ProxyConfig::CreateFromCustomPacURL(auto_detected_url); | |
| 262 } else { | 278 } else { |
| 263 if (resolver_->expects_pac_bytes()) { | 279 // The resolver does its own resolution so we cannot know the |
| 264 GURL auto_detected_url; | 280 // URL. Just do the best we can and state that the configuration |
| 265 | 281 // is to auto-detect proxy settings. |
| 266 switch (current_pac_source().type) { | 282 effective_config_ = ProxyConfig::CreateAutoDetect(); |
| 267 case PacSource::WPAD_DHCP: | |
| 268 auto_detected_url = dhcp_proxy_script_fetcher_->GetPacURL(); | |
| 269 break; | |
| 270 | |
| 271 case PacSource::WPAD_DNS: | |
| 272 auto_detected_url = GURL(kWpadUrl); | |
| 273 break; | |
| 274 | |
| 275 default: | |
| 276 NOTREACHED(); | |
| 277 } | |
| 278 | |
| 279 *effective_config_ = | |
| 280 ProxyConfig::CreateFromCustomPacURL(auto_detected_url); | |
| 281 } else { | |
| 282 // The resolver does its own resolution so we cannot know the | |
| 283 // URL. Just do the best we can and state that the configuration | |
| 284 // is to auto-detect proxy settings. | |
| 285 *effective_config_ = ProxyConfig::CreateAutoDetect(); | |
| 286 } | |
| 287 } | 283 } |
| 288 } | 284 } |
| 289 | 285 |
| 290 return result; | 286 return OK; |
| 291 } | 287 } |
| 292 | 288 |
| 293 int InitProxyResolver::TryToFallbackPacSource(int error) { | 289 int ProxyScriptDecider::TryToFallbackPacSource(int error) { |
| 294 DCHECK_LT(error, 0); | 290 DCHECK_LT(error, 0); |
| 295 | 291 |
| 296 if (current_pac_source_index_ + 1 >= pac_sources_.size()) { | 292 if (current_pac_source_index_ + 1 >= pac_sources_.size()) { |
| 297 // Nothing left to fall back to. | 293 // Nothing left to fall back to. |
| 298 return error; | 294 return error; |
| 299 } | 295 } |
| 300 | 296 |
| 301 // Advance to next URL in our list. | 297 // Advance to next URL in our list. |
| 302 ++current_pac_source_index_; | 298 ++current_pac_source_index_; |
| 303 | 299 |
| 304 net_log_.AddEvent( | 300 net_log_.AddEvent( |
| 305 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_SOURCE, NULL); | 301 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FALLING_BACK_TO_NEXT_PAC_SOURCE, NULL); |
| 306 | 302 |
| 307 next_state_ = GetStartState(); | 303 next_state_ = GetStartState(); |
| 308 | 304 |
| 309 return OK; | 305 return OK; |
| 310 } | 306 } |
| 311 | 307 |
| 312 InitProxyResolver::State InitProxyResolver::GetStartState() const { | 308 ProxyScriptDecider::State ProxyScriptDecider::GetStartState() const { |
| 313 return resolver_->expects_pac_bytes() ? | 309 return fetch_pac_bytes_ ? STATE_FETCH_PAC_SCRIPT : STATE_VERIFY_PAC_SCRIPT; |
| 314 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; | |
| 315 } | 310 } |
| 316 | 311 |
| 317 NetLogStringParameter* InitProxyResolver::CreateNetLogParameterAndDetermineURL( | 312 NetLogStringParameter* ProxyScriptDecider::CreateNetLogParameterAndDetermineURL( |
| 318 const PacSource& pac_source, | 313 const PacSource& pac_source, |
| 319 GURL* effective_pac_url) { | 314 GURL* effective_pac_url) { |
| 320 DCHECK(effective_pac_url); | 315 DCHECK(effective_pac_url); |
| 321 | 316 |
| 322 std::string source_field; | 317 std::string source_field; |
| 323 switch (pac_source.type) { | 318 switch (pac_source.type) { |
| 324 case PacSource::WPAD_DHCP: | 319 case PacSource::WPAD_DHCP: |
| 325 source_field = "WPAD DHCP"; | 320 source_field = "WPAD DHCP"; |
| 326 break; | 321 break; |
| 327 case PacSource::WPAD_DNS: | 322 case PacSource::WPAD_DNS: |
| 328 *effective_pac_url = GURL(kWpadUrl); | 323 *effective_pac_url = GURL(kWpadUrl); |
| 329 source_field = "WPAD DNS: "; | 324 source_field = "WPAD DNS: "; |
| 330 source_field += effective_pac_url->possibly_invalid_spec(); | 325 source_field += effective_pac_url->possibly_invalid_spec(); |
| 331 break; | 326 break; |
| 332 case PacSource::CUSTOM: | 327 case PacSource::CUSTOM: |
| 333 *effective_pac_url = pac_source.url; | 328 *effective_pac_url = pac_source.url; |
| 334 source_field = "Custom PAC URL: "; | 329 source_field = "Custom PAC URL: "; |
| 335 source_field += effective_pac_url->possibly_invalid_spec(); | 330 source_field += effective_pac_url->possibly_invalid_spec(); |
| 336 break; | 331 break; |
| 337 } | 332 } |
| 338 return new NetLogStringParameter("source", source_field); | 333 return new NetLogStringParameter("source", source_field); |
| 339 } | 334 } |
| 340 | 335 |
| 341 const InitProxyResolver::PacSource& | 336 const ProxyScriptDecider::PacSource& |
| 342 InitProxyResolver::current_pac_source() const { | 337 ProxyScriptDecider::current_pac_source() const { |
| 343 DCHECK_LT(current_pac_source_index_, pac_sources_.size()); | 338 DCHECK_LT(current_pac_source_index_, pac_sources_.size()); |
| 344 return pac_sources_[current_pac_source_index_]; | 339 return pac_sources_[current_pac_source_index_]; |
| 345 } | 340 } |
| 346 | 341 |
| 347 void InitProxyResolver::OnWaitTimerFired() { | 342 void ProxyScriptDecider::OnWaitTimerFired() { |
| 348 OnIOCompletion(OK); | 343 OnIOCompletion(OK); |
| 349 } | 344 } |
| 350 | 345 |
| 351 void InitProxyResolver::DidCompleteInit() { | 346 void ProxyScriptDecider::DidComplete() { |
| 352 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); | 347 net_log_.EndEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER, NULL); |
| 353 } | 348 } |
| 354 | 349 |
| 355 void InitProxyResolver::Cancel() { | 350 void ProxyScriptDecider::Cancel() { |
| 356 DCHECK_NE(STATE_NONE, next_state_); | 351 DCHECK_NE(STATE_NONE, next_state_); |
| 357 | 352 |
| 358 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); | 353 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 359 | 354 |
| 360 switch (next_state_) { | 355 switch (next_state_) { |
| 361 case STATE_WAIT_COMPLETE: | 356 case STATE_WAIT_COMPLETE: |
| 362 wait_timer_.Stop(); | 357 wait_timer_.Stop(); |
| 363 break; | 358 break; |
| 364 case STATE_FETCH_PAC_SCRIPT_COMPLETE: | 359 case STATE_FETCH_PAC_SCRIPT_COMPLETE: |
| 365 proxy_script_fetcher_->Cancel(); | 360 proxy_script_fetcher_->Cancel(); |
| 366 break; | 361 break; |
| 367 case STATE_SET_PAC_SCRIPT_COMPLETE: | |
| 368 resolver_->CancelSetPacScript(); | |
| 369 break; | |
| 370 default: | 362 default: |
| 371 NOTREACHED(); | 363 NOTREACHED(); |
| 372 break; | 364 break; |
| 373 } | 365 } |
| 374 | 366 |
| 375 // This is safe to call in any state. | 367 // This is safe to call in any state. |
| 376 if (dhcp_proxy_script_fetcher_) | 368 if (dhcp_proxy_script_fetcher_) |
| 377 dhcp_proxy_script_fetcher_->Cancel(); | 369 dhcp_proxy_script_fetcher_->Cancel(); |
| 378 | 370 |
| 379 DidCompleteInit(); | 371 DidComplete(); |
| 380 } | 372 } |
| 381 | 373 |
| 382 } // namespace net | 374 } // namespace net |
| OLD | NEW |