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

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

Issue 2945004: Revert 51877, since SpdyNetworkTransactionTest.CorruptFrameSessionError start... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
19 #include "net/proxy/proxy_config_service_fixed.h" 18 #include "net/proxy/proxy_config_service_fixed.h"
20 #include "net/proxy/proxy_script_fetcher.h" 19 #include "net/proxy/proxy_script_fetcher.h"
21 #if defined(OS_WIN) 20 #if defined(OS_WIN)
22 #include "net/proxy/proxy_config_service_win.h" 21 #include "net/proxy/proxy_config_service_win.h"
23 #include "net/proxy/proxy_resolver_winhttp.h" 22 #include "net/proxy/proxy_resolver_winhttp.h"
24 #elif defined(OS_MACOSX) 23 #elif defined(OS_MACOSX)
25 #include "net/proxy/proxy_config_service_mac.h" 24 #include "net/proxy/proxy_config_service_mac.h"
26 #include "net/proxy/proxy_resolver_mac.h" 25 #include "net/proxy/proxy_resolver_mac.h"
27 #elif defined(OS_LINUX) 26 #elif defined(OS_LINUX)
28 #include "net/proxy/proxy_config_service_linux.h" 27 #include "net/proxy/proxy_config_service_linux.h"
29 #endif 28 #endif
30 #include "net/proxy/proxy_resolver.h" 29 #include "net/proxy/proxy_resolver.h"
31 #include "net/proxy/proxy_resolver_js_bindings.h" 30 #include "net/proxy/proxy_resolver_js_bindings.h"
32 #include "net/proxy/proxy_resolver_v8.h" 31 #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
127 // ProxyService::PacRequest --------------------------------------------------- 78 // ProxyService::PacRequest ---------------------------------------------------
128 79
129 class ProxyService::PacRequest 80 class ProxyService::PacRequest
130 : public base::RefCounted<ProxyService::PacRequest> { 81 : public base::RefCounted<ProxyService::PacRequest> {
131 public: 82 public:
132 PacRequest(ProxyService* service, 83 PacRequest(ProxyService* service,
133 const GURL& url, 84 const GURL& url,
134 ProxyInfo* results, 85 ProxyInfo* results,
135 CompletionCallback* user_callback, 86 CompletionCallback* user_callback,
136 const BoundNetLog& net_log) 87 const BoundNetLog& net_log)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 NetworkChangeNotifier::AddObserver(this); 211 NetworkChangeNotifier::AddObserver(this);
261 } 212 }
262 213
263 // static 214 // static
264 ProxyService* ProxyService::Create( 215 ProxyService* ProxyService::Create(
265 ProxyConfigService* proxy_config_service, 216 ProxyConfigService* proxy_config_service,
266 bool use_v8_resolver, 217 bool use_v8_resolver,
267 URLRequestContext* url_request_context, 218 URLRequestContext* url_request_context,
268 NetLog* net_log, 219 NetLog* net_log,
269 MessageLoop* io_loop) { 220 MessageLoop* io_loop) {
221 ProxyResolver* proxy_resolver = NULL;
270 222
271 ProxyResolverFactory* sync_resolver_factory;
272 if (use_v8_resolver) { 223 if (use_v8_resolver) {
273 sync_resolver_factory = 224 // Use the IO thread's host resolver (but since it is not threadsafe,
274 new ProxyResolverFactoryForV8( 225 // bridge requests from the PAC thread over to the IO thread).
275 url_request_context->host_resolver(), 226 SyncHostResolverBridge* sync_host_resolver =
276 io_loop); 227 new SyncHostResolverBridge(url_request_context->host_resolver(),
228 io_loop);
229
230 // Send javascript errors and alerts to LOG(INFO).
231 ProxyResolverJSBindings* js_bindings =
232 ProxyResolverJSBindings::CreateDefault(sync_host_resolver);
233
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);
277 } else { 242 } else {
278 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); 243 proxy_resolver =
244 new SingleThreadedProxyResolver(CreateNonV8ProxyResolver());
279 } 245 }
280 246
281 const size_t kMaxNumResolverThreads = 1u;
282 ProxyResolver* proxy_resolver =
283 new MultiThreadedProxyResolver(sync_resolver_factory,
284 kMaxNumResolverThreads);
285
286 ProxyService* proxy_service = 247 ProxyService* proxy_service =
287 new ProxyService(proxy_config_service, proxy_resolver, net_log); 248 new ProxyService(proxy_config_service, proxy_resolver, net_log);
288 249
289 if (proxy_resolver->expects_pac_bytes()) { 250 if (proxy_resolver->expects_pac_bytes()) {
290 // Configure PAC script downloads to be issued using |url_request_context|. 251 // Configure PAC script downloads to be issued using |url_request_context|.
291 DCHECK(url_request_context); 252 DCHECK(url_request_context);
292 proxy_service->SetProxyScriptFetcher( 253 proxy_service->SetProxyScriptFetcher(
293 ProxyScriptFetcher::Create(url_request_context)); 254 ProxyScriptFetcher::Create(url_request_context));
294 } 255 }
295 256
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 static_cast<MessageLoopForIO*>(file_loop)); 552 static_cast<MessageLoopForIO*>(file_loop));
592 553
593 return linux_config_service; 554 return linux_config_service;
594 #else 555 #else
595 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " 556 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
596 "for this platform."; 557 "for this platform.";
597 return new ProxyConfigServiceNull(); 558 return new ProxyConfigServiceNull();
598 #endif 559 #endif
599 } 560 }
600 561
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
601 void ProxyService::UpdateConfig(const BoundNetLog& net_log) { 575 void ProxyService::UpdateConfig(const BoundNetLog& net_log) {
602 bool is_first_update = !config_has_been_initialized(); 576 bool is_first_update = !config_has_been_initialized();
603 577
604 ProxyConfig latest; 578 ProxyConfig latest;
605 579
606 // Fetch the proxy settings. 580 // Fetch the proxy settings.
607 TimeTicks start_time = TimeTicks::Now(); 581 TimeTicks start_time = TimeTicks::Now();
608 net_log.BeginEvent( 582 net_log.BeginEvent(
609 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, NULL); 583 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, NULL);
610 int rv = config_service_->GetProxyConfig(&latest); 584 int rv = config_service_->GetProxyConfig(&latest);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 OnCompletion(result_); 730 OnCompletion(result_);
757 } 731 }
758 } 732 }
759 733
760 void SyncProxyServiceHelper::OnCompletion(int rv) { 734 void SyncProxyServiceHelper::OnCompletion(int rv) {
761 result_ = rv; 735 result_ = rv;
762 event_.Signal(); 736 event_.Signal();
763 } 737 }
764 738
765 } // namespace net 739 } // 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