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

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

Issue 6597070: Allow ProxyConfigService to report "no configuration set" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 9 years, 9 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) 2010 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/values.h"
12 #include "base/message_loop.h" 11 #include "base/message_loop.h"
13 #include "base/string_util.h" 12 #include "base/string_util.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_log.h" 16 #include "net/base/net_log.h"
16 #include "net/base/net_errors.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "net/proxy/init_proxy_resolver.h" 18 #include "net/proxy/init_proxy_resolver.h"
19 #include "net/proxy/multi_threaded_proxy_resolver.h" 19 #include "net/proxy/multi_threaded_proxy_resolver.h"
20 #include "net/proxy/proxy_config_service_fixed.h" 20 #include "net/proxy/proxy_config_service_fixed.h"
21 #include "net/proxy/proxy_resolver.h"
22 #include "net/proxy/proxy_resolver_js_bindings.h"
23 #include "net/proxy/proxy_resolver_v8.h"
21 #include "net/proxy/proxy_script_fetcher.h" 24 #include "net/proxy/proxy_script_fetcher.h"
25 #include "net/proxy/sync_host_resolver_bridge.h"
26 #include "net/url_request/url_request_context.h"
27
22 #if defined(OS_WIN) 28 #if defined(OS_WIN)
23 #include "net/proxy/proxy_config_service_win.h" 29 #include "net/proxy/proxy_config_service_win.h"
24 #include "net/proxy/proxy_resolver_winhttp.h" 30 #include "net/proxy/proxy_resolver_winhttp.h"
25 #elif defined(OS_MACOSX) 31 #elif defined(OS_MACOSX)
26 #include "net/proxy/proxy_config_service_mac.h" 32 #include "net/proxy/proxy_config_service_mac.h"
27 #include "net/proxy/proxy_resolver_mac.h" 33 #include "net/proxy/proxy_resolver_mac.h"
28 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) 34 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
29 #include "net/proxy/proxy_config_service_linux.h" 35 #include "net/proxy/proxy_config_service_linux.h"
30 #endif 36 #endif
31 #include "net/proxy/proxy_resolver.h"
32 #include "net/proxy/proxy_resolver_js_bindings.h"
33 #include "net/proxy/proxy_resolver_v8.h"
34 #include "net/proxy/sync_host_resolver_bridge.h"
35 #include "net/url_request/url_request_context.h"
36 37
37 using base::TimeDelta; 38 using base::TimeDelta;
38 using base::TimeTicks; 39 using base::TimeTicks;
39 40
40 namespace net { 41 namespace net {
41 42
42 namespace { 43 namespace {
43 44
44 const size_t kMaxNumNetLogEntries = 100; 45 const size_t kMaxNumNetLogEntries = 100;
45 const size_t kDefaultNumPacThreads = 4; 46 const size_t kDefaultNumPacThreads = 4;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // things. It is entirely possible that the value is insuficient for other 83 // things. It is entirely possible that the value is insuficient for other
83 // setups. 84 // setups.
84 const int64 kNumMillisToStallAfterNetworkChanges = 2000; 85 const int64 kNumMillisToStallAfterNetworkChanges = 2000;
85 86
86 // Config getter that always returns direct settings. 87 // Config getter that always returns direct settings.
87 class ProxyConfigServiceDirect : public ProxyConfigService { 88 class ProxyConfigServiceDirect : public ProxyConfigService {
88 public: 89 public:
89 // ProxyConfigService implementation: 90 // ProxyConfigService implementation:
90 virtual void AddObserver(Observer* observer) {} 91 virtual void AddObserver(Observer* observer) {}
91 virtual void RemoveObserver(Observer* observer) {} 92 virtual void RemoveObserver(Observer* observer) {}
92 virtual bool GetLatestProxyConfig(ProxyConfig* config) { 93 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) {
93 *config = ProxyConfig::CreateDirect(); 94 *config = ProxyConfig::CreateDirect();
94 return true; 95 return CONFIG_VALID;
95 } 96 }
96 }; 97 };
97 98
98 // Proxy resolver that fails every time. 99 // Proxy resolver that fails every time.
99 class ProxyResolverNull : public ProxyResolver { 100 class ProxyResolverNull : public ProxyResolver {
100 public: 101 public:
101 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} 102 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {}
102 103
103 // ProxyResolver implementation: 104 // ProxyResolver implementation:
104 virtual int GetProxyForURL(const GURL& url, 105 virtual int GetProxyForURL(const GURL& url,
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return; 621 return;
621 } 622 }
622 623
623 // Otherwise we need to first fetch the configuration. 624 // Otherwise we need to first fetch the configuration.
624 current_state_ = STATE_WAITING_FOR_PROXY_CONFIG; 625 current_state_ = STATE_WAITING_FOR_PROXY_CONFIG;
625 626
626 // Retrieve the current proxy configuration from the ProxyConfigService. 627 // Retrieve the current proxy configuration from the ProxyConfigService.
627 // If a configuration is not available yet, we will get called back later 628 // If a configuration is not available yet, we will get called back later
628 // by our ProxyConfigService::Observer once it changes. 629 // by our ProxyConfigService::Observer once it changes.
629 ProxyConfig config; 630 ProxyConfig config;
630 bool has_config = config_service_->GetLatestProxyConfig(&config); 631 ProxyConfigService::ConfigAvailability availability =
631 if (has_config) 632 config_service_->GetLatestProxyConfig(&config);
632 OnProxyConfigChanged(config); 633 if (availability != ProxyConfigService::CONFIG_PENDING)
634 OnProxyConfigChanged(config, availability);
633 } 635 }
634 636
635 void ProxyService::OnInitProxyResolverComplete(int result) { 637 void ProxyService::OnInitProxyResolverComplete(int result) {
636 DCHECK_EQ(STATE_WAITING_FOR_INIT_PROXY_RESOLVER, current_state_); 638 DCHECK_EQ(STATE_WAITING_FOR_INIT_PROXY_RESOLVER, current_state_);
637 DCHECK(init_proxy_resolver_.get()); 639 DCHECK(init_proxy_resolver_.get());
638 DCHECK(fetched_config_.HasAutomaticSettings()); 640 DCHECK(fetched_config_.HasAutomaticSettings());
639 init_proxy_resolver_.reset(); 641 init_proxy_resolver_.reset();
640 642
641 if (result != OK) { 643 if (result != OK) {
642 VLOG(1) << "Failed configuring with PAC script, falling-back to manual " 644 VLOG(1) << "Failed configuring with PAC script, falling-back to manual "
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 788
787 // static 789 // static
788 ProxyConfigService* ProxyService::CreateSystemProxyConfigService( 790 ProxyConfigService* ProxyService::CreateSystemProxyConfigService(
789 MessageLoop* io_loop, MessageLoop* file_loop) { 791 MessageLoop* io_loop, MessageLoop* file_loop) {
790 #if defined(OS_WIN) 792 #if defined(OS_WIN)
791 return new ProxyConfigServiceWin(); 793 return new ProxyConfigServiceWin();
792 #elif defined(OS_MACOSX) 794 #elif defined(OS_MACOSX)
793 return new ProxyConfigServiceMac(io_loop); 795 return new ProxyConfigServiceMac(io_loop);
794 #elif defined(OS_CHROMEOS) 796 #elif defined(OS_CHROMEOS)
795 NOTREACHED() << "ProxyConfigService for ChromeOS should be created in " 797 NOTREACHED() << "ProxyConfigService for ChromeOS should be created in "
796 << "chrome_url_request_context.cc::CreateProxyConfigService."; 798 << "profile_io_data.cc::CreateProxyConfigService.";
797 return NULL; 799 return NULL;
798 #elif defined(OS_LINUX) 800 #elif defined(OS_LINUX)
799 ProxyConfigServiceLinux* linux_config_service 801 ProxyConfigServiceLinux* linux_config_service =
800 = new ProxyConfigServiceLinux(); 802 new ProxyConfigServiceLinux();
801 803
802 // Assume we got called from the UI loop, which runs the default 804 // Assume we got called from the UI loop, which runs the default
803 // glib main loop, so the current thread is where we should be 805 // glib main loop, so the current thread is where we should be
804 // running gconf calls from. 806 // running gconf calls from.
805 MessageLoop* glib_default_loop = MessageLoopForUI::current(); 807 MessageLoop* glib_default_loop = MessageLoopForUI::current();
806 808
807 // The file loop should be a MessageLoopForIO on Linux. 809 // The file loop should be a MessageLoopForIO on Linux.
808 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); 810 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type());
809 811
810 // Synchronously fetch the current proxy config (since we are 812 // Synchronously fetch the current proxy config (since we are
811 // running on glib_default_loop). Additionally register for 813 // running on glib_default_loop). Additionally register for
812 // notifications (delivered in either |glib_default_loop| or 814 // notifications (delivered in either |glib_default_loop| or
813 // |file_loop|) to keep us updated when the proxy config changes. 815 // |file_loop|) to keep us updated when the proxy config changes.
814 linux_config_service->SetupAndFetchInitialConfig(glib_default_loop, io_loop, 816 linux_config_service->SetupAndFetchInitialConfig(glib_default_loop, io_loop,
815 static_cast<MessageLoopForIO*>(file_loop)); 817 static_cast<MessageLoopForIO*>(file_loop));
816 818
817 return linux_config_service; 819 return linux_config_service;
818 #else 820 #else
819 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " 821 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
820 "for this platform."; 822 "for this platform.";
821 return new ProxyConfigServiceNull(); 823 return new ProxyConfigServiceNull();
822 #endif 824 #endif
823 } 825 }
824 826
825 void ProxyService::OnProxyConfigChanged(const ProxyConfig& config) { 827 void ProxyService::OnProxyConfigChanged(
828 const ProxyConfig& config,
829 ProxyConfigService::ConfigAvailability availability) {
830 // Retrieve the current proxy configuration from the ProxyConfigService.
831 // If a configuration is not available yet, we will get called back later
832 // by our ProxyConfigService::Observer once it changes.
833 ProxyConfig effective_config;
834 switch (availability) {
835 case ProxyConfigService::CONFIG_PENDING:
eroman 2011/03/16 01:30:00 I don't think this case makes sense. We should ins
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 You're right in that it doesn't make sense to send
836 // Will get called back later through ProxyConfigService::Observer.
837 return;
838 case ProxyConfigService::CONFIG_VALID:
839 effective_config = config;
840 break;
841 case ProxyConfigService::CONFIG_UNSET:
842 effective_config = ProxyConfig::CreateAutoDetect();
eroman 2011/03/16 01:30:00 I think we should default to Direct() rather than
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 OK, I agree that for now we should make the system
843 break;
844 }
845
826 // Emit the proxy settings change to the NetLog stream. 846 // Emit the proxy settings change to the NetLog stream.
827 if (net_log_) { 847 if (net_log_) {
828 scoped_refptr<NetLog::EventParameters> params( 848 scoped_refptr<NetLog::EventParameters> params(
829 new ProxyConfigChangedNetLogParam(fetched_config_, config)); 849 new ProxyConfigChangedNetLogParam(fetched_config_, effective_config));
830 net_log_->AddEntry(net::NetLog::TYPE_PROXY_CONFIG_CHANGED, 850 net_log_->AddEntry(net::NetLog::TYPE_PROXY_CONFIG_CHANGED,
831 base::TimeTicks::Now(), 851 base::TimeTicks::Now(),
832 NetLog::Source(), 852 NetLog::Source(),
833 NetLog::PHASE_NONE, 853 NetLog::PHASE_NONE,
834 params); 854 params);
835 } 855 }
836 856
837 // Set the new configuration as the most recently fetched one. 857 // Set the new configuration as the most recently fetched one.
838 fetched_config_ = config; 858 fetched_config_ = effective_config;
839 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). 859 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid().
840 860
841 InitializeUsingLastFetchedConfig(); 861 InitializeUsingLastFetchedConfig();
842 } 862 }
843 863
844 void ProxyService::InitializeUsingLastFetchedConfig() { 864 void ProxyService::InitializeUsingLastFetchedConfig() {
845 ResetProxyConfig(false); 865 ResetProxyConfig(false);
846 866
847 DCHECK(fetched_config_.is_valid()); 867 DCHECK(fetched_config_.is_valid());
848 868
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 OnCompletion(result_); 963 OnCompletion(result_);
944 } 964 }
945 } 965 }
946 966
947 void SyncProxyServiceHelper::OnCompletion(int rv) { 967 void SyncProxyServiceHelper::OnCompletion(int rv) {
948 result_ = rv; 968 result_ = rv;
949 event_.Signal(); 969 event_.Signal();
950 } 970 }
951 971
952 } // namespace net 972 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698