Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: net/proxy/proxy_service.cc

Issue 6831025: Adds support for the DHCP portion of the WPAD (proxy auto-discovery) protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responding to review comments. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_util.h" 12 #include "base/string_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/net_log.h" 16 #include "net/base/net_log.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "net/proxy/dhcp_proxy_script_fetcher.h"
18 #include "net/proxy/init_proxy_resolver.h" 19 #include "net/proxy/init_proxy_resolver.h"
19 #include "net/proxy/multi_threaded_proxy_resolver.h" 20 #include "net/proxy/multi_threaded_proxy_resolver.h"
20 #include "net/proxy/proxy_config_service_fixed.h" 21 #include "net/proxy/proxy_config_service_fixed.h"
21 #include "net/proxy/proxy_resolver.h" 22 #include "net/proxy/proxy_resolver.h"
22 #include "net/proxy/proxy_resolver_js_bindings.h" 23 #include "net/proxy/proxy_resolver_js_bindings.h"
23 #include "net/proxy/proxy_resolver_v8.h" 24 #include "net/proxy/proxy_resolver_v8.h"
24 #include "net/proxy/proxy_script_fetcher.h" 25 #include "net/proxy/proxy_script_fetcher.h"
25 #include "net/proxy/sync_host_resolver_bridge.h" 26 #include "net/proxy/sync_host_resolver_bridge.h"
26 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
27 28
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 kNumMillisToStallAfterNetworkChanges)) { 388 kNumMillisToStallAfterNetworkChanges)) {
388 NetworkChangeNotifier::AddIPAddressObserver(this); 389 NetworkChangeNotifier::AddIPAddressObserver(this);
389 ResetConfigService(config_service); 390 ResetConfigService(config_service);
390 } 391 }
391 392
392 // static 393 // static
393 ProxyService* ProxyService::CreateUsingV8ProxyResolver( 394 ProxyService* ProxyService::CreateUsingV8ProxyResolver(
394 ProxyConfigService* proxy_config_service, 395 ProxyConfigService* proxy_config_service,
395 size_t num_pac_threads, 396 size_t num_pac_threads,
396 ProxyScriptFetcher* proxy_script_fetcher, 397 ProxyScriptFetcher* proxy_script_fetcher,
398 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
397 HostResolver* host_resolver, 399 HostResolver* host_resolver,
398 NetLog* net_log) { 400 NetLog* net_log) {
399 DCHECK(proxy_config_service); 401 DCHECK(proxy_config_service);
400 DCHECK(proxy_script_fetcher); 402 DCHECK(proxy_script_fetcher);
403 DCHECK(dhcp_proxy_script_fetcher);
401 DCHECK(host_resolver); 404 DCHECK(host_resolver);
402 405
403 if (num_pac_threads == 0) 406 if (num_pac_threads == 0)
404 num_pac_threads = kDefaultNumPacThreads; 407 num_pac_threads = kDefaultNumPacThreads;
405 408
406 ProxyResolverFactory* sync_resolver_factory = 409 ProxyResolverFactory* sync_resolver_factory =
407 new ProxyResolverFactoryForV8( 410 new ProxyResolverFactoryForV8(
408 host_resolver, 411 host_resolver,
409 MessageLoop::current(), 412 MessageLoop::current(),
410 net_log); 413 net_log);
411 414
412 ProxyResolver* proxy_resolver = 415 ProxyResolver* proxy_resolver =
413 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); 416 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads);
414 417
415 ProxyService* proxy_service = 418 ProxyService* proxy_service =
416 new ProxyService(proxy_config_service, proxy_resolver, net_log); 419 new ProxyService(proxy_config_service, proxy_resolver, net_log);
417 420
418 // Configure PAC script downloads to be issued using |proxy_script_fetcher|. 421 // Configure fetchers to use for PAC script downloads and auto-detect.
419 proxy_service->SetProxyScriptFetcher(proxy_script_fetcher); 422 proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
423 dhcp_proxy_script_fetcher);
420 424
421 return proxy_service; 425 return proxy_service;
422 } 426 }
423 427
424 // static 428 // static
425 ProxyService* ProxyService::CreateUsingSystemProxyResolver( 429 ProxyService* ProxyService::CreateUsingSystemProxyResolver(
426 ProxyConfigService* proxy_config_service, 430 ProxyConfigService* proxy_config_service,
427 size_t num_pac_threads, 431 size_t num_pac_threads,
428 NetLog* net_log) { 432 NetLog* net_log) {
429 DCHECK(proxy_config_service); 433 DCHECK(proxy_config_service);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 // 735 //
732 // http://www.chromium.org/developers/design-documents/proxy-settings-fallba ck 736 // http://www.chromium.org/developers/design-documents/proxy-settings-fallba ck
733 result->UseDirect(); 737 result->UseDirect();
734 result_code = OK; 738 result_code = OK;
735 } 739 }
736 740
737 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); 741 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL);
738 return result_code; 742 return result_code;
739 } 743 }
740 744
741 void ProxyService::SetProxyScriptFetcher( 745 void ProxyService::SetProxyScriptFetchers(
742 ProxyScriptFetcher* proxy_script_fetcher) { 746 ProxyScriptFetcher* proxy_script_fetcher,
747 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher) {
743 DCHECK(CalledOnValidThread()); 748 DCHECK(CalledOnValidThread());
744 State previous_state = ResetProxyConfig(false); 749 State previous_state = ResetProxyConfig(false);
745 proxy_script_fetcher_.reset(proxy_script_fetcher); 750 proxy_script_fetcher_.reset(proxy_script_fetcher);
751 dhcp_proxy_script_fetcher_.reset(dhcp_proxy_script_fetcher);
746 if (previous_state != STATE_NONE) 752 if (previous_state != STATE_NONE)
747 ApplyProxyConfigIfAvailable(); 753 ApplyProxyConfigIfAvailable();
748 } 754 }
749 755
750 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { 756 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const {
751 DCHECK(CalledOnValidThread()); 757 DCHECK(CalledOnValidThread());
752 return proxy_script_fetcher_.get(); 758 return proxy_script_fetcher_.get();
753 } 759 }
754 760
761 DhcpProxyScriptFetcher* ProxyService::GetDhcpProxyScriptFetcher() const {
762 DCHECK(CalledOnValidThread());
763 return dhcp_proxy_script_fetcher_.get();
764 }
765
755 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 766 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
756 DCHECK(CalledOnValidThread()); 767 DCHECK(CalledOnValidThread());
757 State previous_state = current_state_; 768 State previous_state = current_state_;
758 769
759 proxy_retry_info_.clear(); 770 proxy_retry_info_.clear();
760 init_proxy_resolver_.reset(); 771 init_proxy_resolver_.reset();
761 SuspendAllPendingRequests(); 772 SuspendAllPendingRequests();
762 config_ = ProxyConfig(); 773 config_ = ProxyConfig();
763 if (reset_fetched_config) 774 if (reset_fetched_config)
764 fetched_config_ = ProxyConfig(); 775 fetched_config_ = ProxyConfig();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 if (!fetched_config_.HasAutomaticSettings()) { 894 if (!fetched_config_.HasAutomaticSettings()) {
884 config_ = fetched_config_; 895 config_ = fetched_config_;
885 SetReady(); 896 SetReady();
886 return; 897 return;
887 } 898 }
888 899
889 // Start downloading + testing the PAC scripts for this new configuration. 900 // Start downloading + testing the PAC scripts for this new configuration.
890 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER; 901 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER;
891 902
892 init_proxy_resolver_.reset( 903 init_proxy_resolver_.reset(
893 new InitProxyResolver(resolver_.get(), proxy_script_fetcher_.get(), 904 new InitProxyResolver(resolver_.get(),
905 proxy_script_fetcher_.get(),
906 dhcp_proxy_script_fetcher_.get(),
894 net_log_)); 907 net_log_));
895 908
896 // If we changed networks recently, we should delay running proxy auto-config. 909 // If we changed networks recently, we should delay running proxy auto-config.
897 base::TimeDelta wait_delay = 910 base::TimeDelta wait_delay =
898 stall_proxy_autoconfig_until_ - base::TimeTicks::Now(); 911 stall_proxy_autoconfig_until_ - base::TimeTicks::Now();
899 912
900 int rv = init_proxy_resolver_->Init( 913 int rv = init_proxy_resolver_->Init(
901 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_); 914 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_);
902 915
903 if (rv != ERR_IO_PENDING) 916 if (rv != ERR_IO_PENDING)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 OnCompletion(result_); 987 OnCompletion(result_);
975 } 988 }
976 } 989 }
977 990
978 void SyncProxyServiceHelper::OnCompletion(int rv) { 991 void SyncProxyServiceHelper::OnCompletion(int rv) {
979 result_ = rv; 992 result_ = rv;
980 event_.Signal(); 993 event_.Signal();
981 } 994 }
982 995
983 } // namespace net 996 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698