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 90581. |
| 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 config_ = config; |
| 354 wait_delay_ = wait_delay; |
| 355 effective_config_ = effective_config; |
| 356 user_callback_ = callback; |
| 357 |
| 358 next_state_ = STATE_DECIDE_PROXY_SCRIPT; |
| 359 return DoLoop(OK); |
| 360 } |
| 361 |
| 362 private: |
| 363 enum State { |
| 364 STATE_NONE, |
| 365 STATE_DECIDE_PROXY_SCRIPT, |
| 366 STATE_DECIDE_PROXY_SCRIPT_COMPLETE, |
| 367 STATE_SET_PAC_SCRIPT, |
| 368 STATE_SET_PAC_SCRIPT_COMPLETE, |
| 369 }; |
| 370 |
| 371 int DoLoop(int result) { |
| 372 DCHECK_NE(next_state_, STATE_NONE); |
| 373 int rv = result; |
| 374 do { |
| 375 State state = next_state_; |
| 376 next_state_ = STATE_NONE; |
| 377 switch (state) { |
| 378 case STATE_DECIDE_PROXY_SCRIPT: |
| 379 DCHECK_EQ(OK, rv); |
| 380 rv = DoDecideProxyScript(); |
| 381 break; |
| 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: " << 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 DoDecideProxyScript() { |
| 402 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; |
| 403 |
| 404 return decider_.Start( |
| 405 config_, wait_delay_, proxy_resolver_->expects_pac_bytes(), |
| 406 &io_callback_); |
| 407 } |
| 408 |
| 409 int DoDecideProxyScriptComplete(int result) { |
| 410 if (result != OK) |
| 411 return result; |
| 412 |
| 413 *effective_config_ = decider_.effective_config(); |
| 414 next_state_ = STATE_SET_PAC_SCRIPT; |
| 415 return OK; |
| 416 } |
| 417 |
| 418 int DoSetPacScript() { |
| 419 DCHECK(decider_.script_data()); |
| 420 // TODO(eroman): Should log this latency to the NetLog. |
| 421 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 422 return proxy_resolver_->SetPacScript(decider_.script_data(), &io_callback_); |
| 423 } |
| 424 |
| 425 int DoSetPacScriptComplete(int result) { |
| 426 return result; |
| 427 } |
| 428 |
| 429 void OnIOCompletion(int result) { |
| 430 DCHECK_NE(STATE_NONE, next_state_); |
| 431 int rv = DoLoop(result); |
| 432 if (rv != ERR_IO_PENDING) |
| 433 DoCallback(rv); |
| 434 } |
| 435 |
| 436 void DoCallback(int result) { |
| 437 DCHECK_NE(ERR_IO_PENDING, result); |
| 438 user_callback_->Run(result); |
| 439 } |
| 440 |
| 441 ProxyConfig config_; |
| 442 base::TimeDelta wait_delay_; |
| 443 ProxyScriptDecider decider_; |
| 444 ProxyConfig* effective_config_; |
| 445 ProxyResolver* proxy_resolver_; |
| 446 OldCompletionCallback* user_callback_; |
| 447 OldCompletionCallbackImpl<InitProxyResolver> io_callback_; |
| 448 State next_state_; |
| 449 |
| 450 DISALLOW_COPY_AND_ASSIGN(InitProxyResolver); |
| 451 }; |
| 452 |
317 // ProxyService::PacRequest --------------------------------------------------- | 453 // ProxyService::PacRequest --------------------------------------------------- |
318 | 454 |
319 class ProxyService::PacRequest | 455 class ProxyService::PacRequest |
320 : public base::RefCounted<ProxyService::PacRequest> { | 456 : public base::RefCounted<ProxyService::PacRequest> { |
321 public: | 457 public: |
322 PacRequest(ProxyService* service, | 458 PacRequest(ProxyService* service, |
323 const GURL& url, | 459 const GURL& url, |
324 ProxyInfo* results, | 460 ProxyInfo* results, |
325 OldCompletionCallback* user_callback, | 461 OldCompletionCallback* user_callback, |
326 const BoundNetLog& net_log) | 462 const BoundNetLog& net_log) |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 OnCompletion(result_); | 1316 OnCompletion(result_); |
1181 } | 1317 } |
1182 } | 1318 } |
1183 | 1319 |
1184 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1320 void SyncProxyServiceHelper::OnCompletion(int rv) { |
1185 result_ = rv; | 1321 result_ = rv; |
1186 event_.Signal(); | 1322 event_.Signal(); |
1187 } | 1323 } |
1188 | 1324 |
1189 } // namespace net | 1325 } // namespace net |
OLD | NEW |