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

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: Isolate worker thread to separate object. Refcount context. Fix mandatory PAC. 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/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/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/net_log.h" 17 #include "net/base/net_log.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "net/proxy/dhcp_proxy_script_fetcher.h"
19 #include "net/proxy/init_proxy_resolver.h" 20 #include "net/proxy/init_proxy_resolver.h"
20 #include "net/proxy/multi_threaded_proxy_resolver.h" 21 #include "net/proxy/multi_threaded_proxy_resolver.h"
21 #include "net/proxy/network_delegate_error_observer.h" 22 #include "net/proxy/network_delegate_error_observer.h"
22 #include "net/proxy/proxy_config_service_fixed.h" 23 #include "net/proxy/proxy_config_service_fixed.h"
23 #include "net/proxy/proxy_resolver.h" 24 #include "net/proxy/proxy_resolver.h"
24 #include "net/proxy/proxy_resolver_js_bindings.h" 25 #include "net/proxy/proxy_resolver_js_bindings.h"
25 #include "net/proxy/proxy_resolver_v8.h" 26 #include "net/proxy/proxy_resolver_v8.h"
26 #include "net/proxy/proxy_script_fetcher.h" 27 #include "net/proxy/proxy_script_fetcher.h"
27 #include "net/proxy/sync_host_resolver_bridge.h" 28 #include "net/proxy/sync_host_resolver_bridge.h"
28 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 kNumMillisToStallAfterNetworkChanges)) { 403 kNumMillisToStallAfterNetworkChanges)) {
403 NetworkChangeNotifier::AddIPAddressObserver(this); 404 NetworkChangeNotifier::AddIPAddressObserver(this);
404 ResetConfigService(config_service); 405 ResetConfigService(config_service);
405 } 406 }
406 407
407 // static 408 // static
408 ProxyService* ProxyService::CreateUsingV8ProxyResolver( 409 ProxyService* ProxyService::CreateUsingV8ProxyResolver(
409 ProxyConfigService* proxy_config_service, 410 ProxyConfigService* proxy_config_service,
410 size_t num_pac_threads, 411 size_t num_pac_threads,
411 ProxyScriptFetcher* proxy_script_fetcher, 412 ProxyScriptFetcher* proxy_script_fetcher,
413 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
412 HostResolver* host_resolver, 414 HostResolver* host_resolver,
413 NetLog* net_log, 415 NetLog* net_log,
414 NetworkDelegate* network_delegate) { 416 NetworkDelegate* network_delegate) {
415 DCHECK(proxy_config_service); 417 DCHECK(proxy_config_service);
416 DCHECK(proxy_script_fetcher); 418 DCHECK(proxy_script_fetcher);
419 DCHECK(dhcp_proxy_script_fetcher);
417 DCHECK(host_resolver); 420 DCHECK(host_resolver);
418 421
419 if (num_pac_threads == 0) 422 if (num_pac_threads == 0)
420 num_pac_threads = kDefaultNumPacThreads; 423 num_pac_threads = kDefaultNumPacThreads;
421 424
422 ProxyResolverFactory* sync_resolver_factory = 425 ProxyResolverFactory* sync_resolver_factory =
423 new ProxyResolverFactoryForV8( 426 new ProxyResolverFactoryForV8(
424 host_resolver, 427 host_resolver,
425 MessageLoop::current(), 428 MessageLoop::current(),
426 base::MessageLoopProxy::CreateForCurrentThread(), 429 base::MessageLoopProxy::CreateForCurrentThread(),
427 net_log, 430 net_log,
428 network_delegate); 431 network_delegate);
429 432
430 ProxyResolver* proxy_resolver = 433 ProxyResolver* proxy_resolver =
431 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); 434 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads);
432 435
433 ProxyService* proxy_service = 436 ProxyService* proxy_service =
434 new ProxyService(proxy_config_service, proxy_resolver, net_log); 437 new ProxyService(proxy_config_service, proxy_resolver, net_log);
435 438
436 // Configure PAC script downloads to be issued using |proxy_script_fetcher|. 439 // Configure fetchers to use for PAC script downloads and auto-detect.
437 proxy_service->SetProxyScriptFetcher(proxy_script_fetcher); 440 proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
441 dhcp_proxy_script_fetcher);
438 442
439 return proxy_service; 443 return proxy_service;
440 } 444 }
441 445
442 // static 446 // static
443 ProxyService* ProxyService::CreateUsingSystemProxyResolver( 447 ProxyService* ProxyService::CreateUsingSystemProxyResolver(
444 ProxyConfigService* proxy_config_service, 448 ProxyConfigService* proxy_config_service,
445 size_t num_pac_threads, 449 size_t num_pac_threads,
446 NetLog* net_log) { 450 NetLog* net_log) {
447 DCHECK(proxy_config_service); 451 DCHECK(proxy_config_service);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 result_code = OK; 771 result_code = OK;
768 } else { 772 } else {
769 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED; 773 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
770 } 774 }
771 } 775 }
772 776
773 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); 777 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL);
774 return result_code; 778 return result_code;
775 } 779 }
776 780
777 void ProxyService::SetProxyScriptFetcher( 781 void ProxyService::SetProxyScriptFetchers(
778 ProxyScriptFetcher* proxy_script_fetcher) { 782 ProxyScriptFetcher* proxy_script_fetcher,
783 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher) {
779 DCHECK(CalledOnValidThread()); 784 DCHECK(CalledOnValidThread());
780 State previous_state = ResetProxyConfig(false); 785 State previous_state = ResetProxyConfig(false);
781 proxy_script_fetcher_.reset(proxy_script_fetcher); 786 proxy_script_fetcher_.reset(proxy_script_fetcher);
787 dhcp_proxy_script_fetcher_.reset(dhcp_proxy_script_fetcher);
782 if (previous_state != STATE_NONE) 788 if (previous_state != STATE_NONE)
783 ApplyProxyConfigIfAvailable(); 789 ApplyProxyConfigIfAvailable();
784 } 790 }
785 791
786 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { 792 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const {
787 DCHECK(CalledOnValidThread()); 793 DCHECK(CalledOnValidThread());
788 return proxy_script_fetcher_.get(); 794 return proxy_script_fetcher_.get();
789 } 795 }
790 796
797 DhcpProxyScriptFetcher* ProxyService::GetDhcpProxyScriptFetcher() const {
eroman 2011/05/17 04:39:39 Is this used somewhere? (I wander if we can get ri
Jói 2011/05/17 15:38:35 Removed.
798 DCHECK(CalledOnValidThread());
799 return dhcp_proxy_script_fetcher_.get();
800 }
801
791 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 802 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
792 DCHECK(CalledOnValidThread()); 803 DCHECK(CalledOnValidThread());
793 State previous_state = current_state_; 804 State previous_state = current_state_;
794 805
795 permanent_error_ = OK; 806 permanent_error_ = OK;
796 proxy_retry_info_.clear(); 807 proxy_retry_info_.clear();
797 init_proxy_resolver_.reset(); 808 init_proxy_resolver_.reset();
798 SuspendAllPendingRequests(); 809 SuspendAllPendingRequests();
799 config_ = ProxyConfig(); 810 config_ = ProxyConfig();
800 if (reset_fetched_config) 811 if (reset_fetched_config)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 if (!fetched_config_.HasAutomaticSettings()) { 931 if (!fetched_config_.HasAutomaticSettings()) {
921 config_ = fetched_config_; 932 config_ = fetched_config_;
922 SetReady(); 933 SetReady();
923 return; 934 return;
924 } 935 }
925 936
926 // Start downloading + testing the PAC scripts for this new configuration. 937 // Start downloading + testing the PAC scripts for this new configuration.
927 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER; 938 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER;
928 939
929 init_proxy_resolver_.reset( 940 init_proxy_resolver_.reset(
930 new InitProxyResolver(resolver_.get(), proxy_script_fetcher_.get(), 941 new InitProxyResolver(resolver_.get(),
942 proxy_script_fetcher_.get(),
943 dhcp_proxy_script_fetcher_.get(),
931 net_log_)); 944 net_log_));
932 945
933 // If we changed networks recently, we should delay running proxy auto-config. 946 // If we changed networks recently, we should delay running proxy auto-config.
934 base::TimeDelta wait_delay = 947 base::TimeDelta wait_delay =
935 stall_proxy_autoconfig_until_ - base::TimeTicks::Now(); 948 stall_proxy_autoconfig_until_ - base::TimeTicks::Now();
936 949
937 int rv = init_proxy_resolver_->Init( 950 int rv = init_proxy_resolver_->Init(
938 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_); 951 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_);
939 952
940 if (rv != ERR_IO_PENDING) 953 if (rv != ERR_IO_PENDING)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 OnCompletion(result_); 1024 OnCompletion(result_);
1012 } 1025 }
1013 } 1026 }
1014 1027
1015 void SyncProxyServiceHelper::OnCompletion(int rv) { 1028 void SyncProxyServiceHelper::OnCompletion(int rv) {
1016 result_ = rv; 1029 result_ = rv;
1017 event_.Signal(); 1030 event_.Signal();
1018 } 1031 }
1019 1032
1020 } // namespace net 1033 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698