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

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

Issue 2822043: Add the capability to run multiple proxy PAC scripts in parallel.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Re-upload after revert Created 10 years, 5 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
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/single_threaded_proxy_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "net/proxy/init_proxy_resolver.h" 17 #include "net/proxy/init_proxy_resolver.h"
18 #include "net/proxy/multi_threaded_proxy_resolver.h"
18 #include "net/proxy/proxy_config_service_fixed.h" 19 #include "net/proxy/proxy_config_service_fixed.h"
19 #include "net/proxy/proxy_script_fetcher.h" 20 #include "net/proxy/proxy_script_fetcher.h"
20 #if defined(OS_WIN) 21 #if defined(OS_WIN)
21 #include "net/proxy/proxy_config_service_win.h" 22 #include "net/proxy/proxy_config_service_win.h"
22 #include "net/proxy/proxy_resolver_winhttp.h" 23 #include "net/proxy/proxy_resolver_winhttp.h"
23 #elif defined(OS_MACOSX) 24 #elif defined(OS_MACOSX)
24 #include "net/proxy/proxy_config_service_mac.h" 25 #include "net/proxy/proxy_config_service_mac.h"
25 #include "net/proxy/proxy_resolver_mac.h" 26 #include "net/proxy/proxy_resolver_mac.h"
26 #elif defined(OS_LINUX) 27 #elif defined(OS_LINUX)
27 #include "net/proxy/proxy_config_service_linux.h" 28 #include "net/proxy/proxy_config_service_linux.h"
28 #endif 29 #endif
29 #include "net/proxy/proxy_resolver.h" 30 #include "net/proxy/proxy_resolver.h"
30 #include "net/proxy/proxy_resolver_js_bindings.h" 31 #include "net/proxy/proxy_resolver_js_bindings.h"
31 #include "net/proxy/proxy_resolver_v8.h" 32 #include "net/proxy/proxy_resolver_v8.h"
32 #include "net/proxy/single_threaded_proxy_resolver.h"
33 #include "net/proxy/sync_host_resolver_bridge.h" 33 #include "net/proxy/sync_host_resolver_bridge.h"
34 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
35 35
36 using base::TimeDelta; 36 using base::TimeDelta;
37 using base::TimeTicks; 37 using base::TimeTicks;
38 38
39 namespace net { 39 namespace net {
40 40
41 static const size_t kMaxNumNetLogEntries = 100; 41 static const size_t kMaxNumNetLogEntries = 100;
42 42
(...skipping 25 matching lines...) Expand all
68 } 68 }
69 69
70 private: 70 private:
71 virtual int SetPacScript(const GURL& /*pac_url*/, 71 virtual int SetPacScript(const GURL& /*pac_url*/,
72 const string16& /*pac_script*/, 72 const string16& /*pac_script*/,
73 CompletionCallback* /*callback*/) { 73 CompletionCallback* /*callback*/) {
74 return ERR_NOT_IMPLEMENTED; 74 return ERR_NOT_IMPLEMENTED;
75 } 75 }
76 }; 76 };
77 77
78 // This factory creates V8ProxyResolvers with appropriate javascript bindings.
79 class ProxyResolverFactoryForV8 : public ProxyResolverFactory {
80 public:
81 // Both |async_host_resolver| and |host_resolver_loop| must remain valid for
82 // duration of our lifetime.
83 ProxyResolverFactoryForV8(HostResolver* async_host_resolver,
84 MessageLoop* host_resolver_loop)
85 : ProxyResolverFactory(true /*expects_pac_bytes*/),
86 async_host_resolver_(async_host_resolver),
87 host_resolver_loop_(host_resolver_loop) {
88 }
89
90 virtual ProxyResolver* CreateProxyResolver() {
91 // Create a synchronous host resolver wrapper that operates
92 // |async_host_resolver_| on |host_resolver_loop_|.
93 SyncHostResolverBridge* sync_host_resolver =
94 new SyncHostResolverBridge(async_host_resolver_, host_resolver_loop_);
95
96 ProxyResolverJSBindings* js_bindings =
97 ProxyResolverJSBindings::CreateDefault(sync_host_resolver);
98
99 // ProxyResolverV8 takes ownership of |js_bindings|.
100 return new ProxyResolverV8(js_bindings);
101 }
102
103 private:
104 scoped_refptr<HostResolver> async_host_resolver_;
105 MessageLoop* host_resolver_loop_;
106 };
107
108 // Creates ProxyResolvers using a non-V8 implementation.
109 class ProxyResolverFactoryForNonV8 : public ProxyResolverFactory {
110 public:
111 ProxyResolverFactoryForNonV8()
112 : ProxyResolverFactory(false /*expects_pac_bytes*/) {}
113
114 virtual ProxyResolver* CreateProxyResolver() {
115 #if defined(OS_WIN)
116 return new ProxyResolverWinHttp();
117 #elif defined(OS_MACOSX)
118 return new ProxyResolverMac();
119 #else
120 LOG(WARNING) << "PAC support disabled because there is no fallback "
121 "non-V8 implementation";
122 return new ProxyResolverNull();
123 #endif
124 }
125 };
126
78 // ProxyService::PacRequest --------------------------------------------------- 127 // ProxyService::PacRequest ---------------------------------------------------
79 128
80 class ProxyService::PacRequest 129 class ProxyService::PacRequest
81 : public base::RefCounted<ProxyService::PacRequest> { 130 : public base::RefCounted<ProxyService::PacRequest> {
82 public: 131 public:
83 PacRequest(ProxyService* service, 132 PacRequest(ProxyService* service,
84 const GURL& url, 133 const GURL& url,
85 ProxyInfo* results, 134 ProxyInfo* results,
86 CompletionCallback* user_callback, 135 CompletionCallback* user_callback,
87 const BoundNetLog& net_log) 136 const BoundNetLog& net_log)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 NetworkChangeNotifier::AddObserver(this); 260 NetworkChangeNotifier::AddObserver(this);
212 } 261 }
213 262
214 // static 263 // static
215 ProxyService* ProxyService::Create( 264 ProxyService* ProxyService::Create(
216 ProxyConfigService* proxy_config_service, 265 ProxyConfigService* proxy_config_service,
217 bool use_v8_resolver, 266 bool use_v8_resolver,
218 URLRequestContext* url_request_context, 267 URLRequestContext* url_request_context,
219 NetLog* net_log, 268 NetLog* net_log,
220 MessageLoop* io_loop) { 269 MessageLoop* io_loop) {
221 ProxyResolver* proxy_resolver = NULL;
222 270
271 ProxyResolverFactory* sync_resolver_factory;
223 if (use_v8_resolver) { 272 if (use_v8_resolver) {
224 // Use the IO thread's host resolver (but since it is not threadsafe, 273 sync_resolver_factory =
225 // bridge requests from the PAC thread over to the IO thread). 274 new ProxyResolverFactoryForV8(
226 SyncHostResolverBridge* sync_host_resolver = 275 url_request_context->host_resolver(),
227 new SyncHostResolverBridge(url_request_context->host_resolver(), 276 io_loop);
228 io_loop); 277 } else {
278 sync_resolver_factory = new ProxyResolverFactoryForNonV8();
279 }
229 280
230 // Send javascript errors and alerts to LOG(INFO). 281 const size_t kMaxNumResolverThreads = 1u;
231 ProxyResolverJSBindings* js_bindings = 282 ProxyResolver* proxy_resolver =
232 ProxyResolverJSBindings::CreateDefault(sync_host_resolver); 283 new MultiThreadedProxyResolver(sync_resolver_factory,
233 284 kMaxNumResolverThreads);
234 // Wrap the (synchronous) ProxyResolver implementation in a single-threaded
235 // asynchronous resolver. This version of SingleThreadedProxyResolver
236 // additionally aborts any synchronous host resolves to avoid deadlock
237 // during shutdown.
238 proxy_resolver =
239 new SingleThreadedProxyResolverUsingBridgedHostResolver(
240 new ProxyResolverV8(js_bindings),
241 sync_host_resolver);
242 } else {
243 proxy_resolver =
244 new SingleThreadedProxyResolver(CreateNonV8ProxyResolver());
245 }
246 285
247 ProxyService* proxy_service = 286 ProxyService* proxy_service =
248 new ProxyService(proxy_config_service, proxy_resolver, net_log); 287 new ProxyService(proxy_config_service, proxy_resolver, net_log);
249 288
250 if (proxy_resolver->expects_pac_bytes()) { 289 if (proxy_resolver->expects_pac_bytes()) {
251 // Configure PAC script downloads to be issued using |url_request_context|. 290 // Configure PAC script downloads to be issued using |url_request_context|.
252 DCHECK(url_request_context); 291 DCHECK(url_request_context);
253 proxy_service->SetProxyScriptFetcher( 292 proxy_service->SetProxyScriptFetcher(
254 ProxyScriptFetcher::Create(url_request_context)); 293 ProxyScriptFetcher::Create(url_request_context));
255 } 294 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 static_cast<MessageLoopForIO*>(file_loop)); 591 static_cast<MessageLoopForIO*>(file_loop));
553 592
554 return linux_config_service; 593 return linux_config_service;
555 #else 594 #else
556 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " 595 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
557 "for this platform."; 596 "for this platform.";
558 return new ProxyConfigServiceNull(); 597 return new ProxyConfigServiceNull();
559 #endif 598 #endif
560 } 599 }
561 600
562 // static
563 ProxyResolver* ProxyService::CreateNonV8ProxyResolver() {
564 #if defined(OS_WIN)
565 return new ProxyResolverWinHttp();
566 #elif defined(OS_MACOSX)
567 return new ProxyResolverMac();
568 #else
569 LOG(WARNING) << "PAC support disabled because there is no fallback "
570 "non-V8 implementation";
571 return new ProxyResolverNull();
572 #endif
573 }
574
575 void ProxyService::UpdateConfig(const BoundNetLog& net_log) { 601 void ProxyService::UpdateConfig(const BoundNetLog& net_log) {
576 bool is_first_update = !config_has_been_initialized(); 602 bool is_first_update = !config_has_been_initialized();
577 603
578 ProxyConfig latest; 604 ProxyConfig latest;
579 605
580 // Fetch the proxy settings. 606 // Fetch the proxy settings.
581 TimeTicks start_time = TimeTicks::Now(); 607 TimeTicks start_time = TimeTicks::Now();
582 net_log.BeginEvent( 608 net_log.BeginEvent(
583 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, NULL); 609 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, NULL);
584 int rv = config_service_->GetProxyConfig(&latest); 610 int rv = config_service_->GetProxyConfig(&latest);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 OnCompletion(result_); 756 OnCompletion(result_);
731 } 757 }
732 } 758 }
733 759
734 void SyncProxyServiceHelper::OnCompletion(int rv) { 760 void SyncProxyServiceHelper::OnCompletion(int rv) {
735 result_ = rv; 761 result_ = rv;
736 event_.Signal(); 762 event_.Signal();
737 } 763 }
738 764
739 } // namespace net 765 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/single_threaded_proxy_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698