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/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 20 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 21 #include "net/proxy/init_proxy_resolver.h" | |
| 22 #include "net/proxy/multi_threaded_proxy_resolver.h" | 21 #include "net/proxy/multi_threaded_proxy_resolver.h" |
| 23 #include "net/proxy/network_delegate_error_observer.h" | 22 #include "net/proxy/network_delegate_error_observer.h" |
| 24 #include "net/proxy/proxy_config_service_fixed.h" | 23 #include "net/proxy/proxy_config_service_fixed.h" |
| 25 #include "net/proxy/proxy_resolver.h" | 24 #include "net/proxy/proxy_resolver.h" |
| 26 #include "net/proxy/proxy_resolver_js_bindings.h" | 25 #include "net/proxy/proxy_resolver_js_bindings.h" |
| 27 #include "net/proxy/proxy_resolver_v8.h" | 26 #include "net/proxy/proxy_resolver_v8.h" |
| 27 #include "net/proxy/proxy_script_decider.h" | |
| 28 #include "net/proxy/proxy_script_fetcher.h" | 28 #include "net/proxy/proxy_script_fetcher.h" |
| 29 #include "net/proxy/sync_host_resolver_bridge.h" | 29 #include "net/proxy/sync_host_resolver_bridge.h" |
| 30 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 #include "net/proxy/proxy_config_service_win.h" | 33 #include "net/proxy/proxy_config_service_win.h" |
| 34 #include "net/proxy/proxy_resolver_winhttp.h" | 34 #include "net/proxy/proxy_resolver_winhttp.h" |
| 35 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
| 36 #include "net/proxy/proxy_config_service_mac.h" | 36 #include "net/proxy/proxy_config_service_mac.h" |
| 37 #include "net/proxy/proxy_resolver_mac.h" | 37 #include "net/proxy/proxy_resolver_mac.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 return dict; | 307 return dict; |
| 308 } | 308 } |
| 309 | 309 |
| 310 private: | 310 private: |
| 311 std::vector<std::string> proxy_list_; | 311 std::vector<std::string> proxy_list_; |
| 312 DISALLOW_COPY_AND_ASSIGN(BadProxyListNetLogParam); | 312 DISALLOW_COPY_AND_ASSIGN(BadProxyListNetLogParam); |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 } // namespace | 315 } // namespace |
| 316 | 316 |
| 317 // ProxyService::InitProxyResolver -------------------------------------------- | |
| 318 | |
| 319 // This glues together two asynchronous steps: | |
| 320 // (1) ProxyScriptDecider -- try to fetch/validate a sequence of PAC scripts t o | |
| 321 // figure out what we should configure against. | |
| 322 // (2) Feed the fetched PAC script into the ProxyResolver. | |
| 323 // | |
| 324 // TODO(eroman): This is something of a temporary shim while refactoring to keep | |
| 325 // things similar. It will probably end up changing while solving bug XXX. | |
|
willchan no longer on Chromium
2011/12/12 23:53:47
bug XXX?
| |
| 326 | |
| 327 class ProxyService::InitProxyResolver { | |
| 328 public: | |
| 329 InitProxyResolver(ProxyResolver* proxy_resolver, | |
| 330 ProxyScriptFetcher* proxy_script_fetcher, | |
| 331 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | |
| 332 NetLog* net_log) | |
| 333 : decider_(proxy_script_fetcher, dhcp_proxy_script_fetcher, net_log), | |
| 334 effective_config_(NULL), | |
| 335 proxy_resolver_(proxy_resolver), | |
| 336 user_callback_(NULL), | |
| 337 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | |
| 338 this, &InitProxyResolver::OnIOCompletion)) { | |
| 339 } | |
| 340 | |
| 341 ~InitProxyResolver() { | |
| 342 // Note that the destruction of ProxyScriptDecider will automatically cancel | |
| 343 // any outstanding work. | |
| 344 if (next_state_ == STATE_SET_PAC_SCRIPT_COMPLETE) { | |
| 345 proxy_resolver_->CancelSetPacScript(); | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 int Init(const ProxyConfig& config, | |
| 350 base::TimeDelta wait_delay, | |
| 351 ProxyConfig* effective_config, | |
| 352 OldCompletionCallback* callback) { | |
| 353 effective_config_ = effective_config; | |
| 354 user_callback_ = callback; | |
| 355 | |
| 356 // Start the ProxyScriptDecider. | |
| 357 int result = decider_.Start( | |
| 358 config, wait_delay, proxy_resolver_->expects_pac_bytes(), | |
| 359 &io_callback_); | |
| 360 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; | |
| 361 if (result == ERR_IO_PENDING) | |
| 362 return ERR_IO_PENDING; | |
| 363 | |
| 364 return DoLoop(OK); | |
| 365 } | |
| 366 | |
| 367 private: | |
| 368 enum State { | |
| 369 STATE_NONE, | |
| 370 STATE_DECIDE_PROXY_SCRIPT_COMPLETE, | |
| 371 STATE_SET_PAC_SCRIPT, | |
| 372 STATE_SET_PAC_SCRIPT_COMPLETE, | |
| 373 }; | |
| 374 | |
| 375 int DoLoop(int result) { | |
| 376 DCHECK_NE(next_state_, STATE_NONE); | |
| 377 int rv = result; | |
| 378 do { | |
| 379 State state = next_state_; | |
| 380 next_state_ = STATE_NONE; | |
| 381 switch (state) { | |
| 382 case STATE_DECIDE_PROXY_SCRIPT_COMPLETE: | |
| 383 rv = DoDecideProxyScriptComplete(rv); | |
| 384 break; | |
| 385 case STATE_SET_PAC_SCRIPT: | |
| 386 DCHECK_EQ(OK, rv); | |
| 387 rv = DoSetPacScript(); | |
| 388 break; | |
| 389 case STATE_SET_PAC_SCRIPT_COMPLETE: | |
| 390 rv = DoSetPacScriptComplete(rv); | |
| 391 break; | |
| 392 default: | |
| 393 NOTREACHED() << "bad state"; | |
| 394 rv = ERR_UNEXPECTED; | |
| 395 break; | |
| 396 } | |
| 397 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | |
| 398 return rv; | |
| 399 } | |
| 400 | |
| 401 int DoDecideProxyScriptComplete(int result) { | |
| 402 if (result != OK) | |
| 403 return result; | |
| 404 | |
| 405 *effective_config_ = decider_.effective_config(); | |
| 406 next_state_ = STATE_SET_PAC_SCRIPT; | |
| 407 return OK; | |
| 408 } | |
| 409 | |
| 410 int DoSetPacScript() { | |
| 411 // TODO(eroman): Should log this latency to the NetLog. | |
| 412 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | |
| 413 return proxy_resolver_->SetPacScript(decider_.script_data(), &io_callback_); | |
| 414 } | |
| 415 | |
| 416 int DoSetPacScriptComplete(int result) { | |
| 417 return result; | |
| 418 } | |
| 419 | |
| 420 void OnIOCompletion(int result) { | |
| 421 DCHECK_NE(STATE_NONE, next_state_); | |
| 422 int rv = DoLoop(result); | |
| 423 if (rv != ERR_IO_PENDING) | |
| 424 DoCallback(rv); | |
| 425 } | |
| 426 | |
| 427 void DoCallback(int result) { | |
| 428 DCHECK_NE(ERR_IO_PENDING, result); | |
| 429 user_callback_->Run(result); | |
| 430 } | |
| 431 | |
| 432 ProxyScriptDecider decider_; | |
| 433 ProxyConfig* effective_config_; | |
| 434 ProxyResolver* proxy_resolver_; | |
| 435 OldCompletionCallback* user_callback_; | |
| 436 OldCompletionCallbackImpl<InitProxyResolver> io_callback_; | |
| 437 State next_state_; | |
| 438 | |
| 439 DISALLOW_COPY_AND_ASSIGN(InitProxyResolver); | |
| 440 }; | |
| 441 | |
| 317 // ProxyService::PacRequest --------------------------------------------------- | 442 // ProxyService::PacRequest --------------------------------------------------- |
| 318 | 443 |
| 319 class ProxyService::PacRequest | 444 class ProxyService::PacRequest |
| 320 : public base::RefCounted<ProxyService::PacRequest> { | 445 : public base::RefCounted<ProxyService::PacRequest> { |
| 321 public: | 446 public: |
| 322 PacRequest(ProxyService* service, | 447 PacRequest(ProxyService* service, |
| 323 const GURL& url, | 448 const GURL& url, |
| 324 ProxyInfo* results, | 449 ProxyInfo* results, |
| 325 OldCompletionCallback* user_callback, | 450 OldCompletionCallback* user_callback, |
| 326 const BoundNetLog& net_log) | 451 const BoundNetLog& net_log) |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 OnCompletion(result_); | 1305 OnCompletion(result_); |
| 1181 } | 1306 } |
| 1182 } | 1307 } |
| 1183 | 1308 |
| 1184 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1309 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 1185 result_ = rv; | 1310 result_ = rv; |
| 1186 event_.Signal(); | 1311 event_.Signal(); |
| 1187 } | 1312 } |
| 1188 | 1313 |
| 1189 } // namespace net | 1314 } // namespace net |
| OLD | NEW |