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: Fix memory leaks in unit test. 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
791 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 797 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 if (!fetched_config_.HasAutomaticSettings()) { 926 if (!fetched_config_.HasAutomaticSettings()) {
921 config_ = fetched_config_; 927 config_ = fetched_config_;
922 SetReady(); 928 SetReady();
923 return; 929 return;
924 } 930 }
925 931
926 // Start downloading + testing the PAC scripts for this new configuration. 932 // Start downloading + testing the PAC scripts for this new configuration.
927 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER; 933 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER;
928 934
929 init_proxy_resolver_.reset( 935 init_proxy_resolver_.reset(
930 new InitProxyResolver(resolver_.get(), proxy_script_fetcher_.get(), 936 new InitProxyResolver(resolver_.get(),
937 proxy_script_fetcher_.get(),
938 dhcp_proxy_script_fetcher_.get(),
931 net_log_)); 939 net_log_));
932 940
933 // If we changed networks recently, we should delay running proxy auto-config. 941 // If we changed networks recently, we should delay running proxy auto-config.
934 base::TimeDelta wait_delay = 942 base::TimeDelta wait_delay =
935 stall_proxy_autoconfig_until_ - base::TimeTicks::Now(); 943 stall_proxy_autoconfig_until_ - base::TimeTicks::Now();
936 944
937 int rv = init_proxy_resolver_->Init( 945 int rv = init_proxy_resolver_->Init(
938 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_); 946 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_);
939 947
940 if (rv != ERR_IO_PENDING) 948 if (rv != ERR_IO_PENDING)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 OnCompletion(result_); 1019 OnCompletion(result_);
1012 } 1020 }
1013 } 1021 }
1014 1022
1015 void SyncProxyServiceHelper::OnCompletion(int rv) { 1023 void SyncProxyServiceHelper::OnCompletion(int rv) {
1016 result_ = rv; 1024 result_ = rv;
1017 event_.Signal(); 1025 event_.Signal();
1018 } 1026 }
1019 1027
1020 } // namespace net 1028 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698