| OLD | NEW |
| 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/forwarding_net_log.h" |
| 14 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 17 #include "net/proxy/init_proxy_resolver.h" | 18 #include "net/proxy/init_proxy_resolver.h" |
| 18 #include "net/proxy/multi_threaded_proxy_resolver.h" | 19 #include "net/proxy/multi_threaded_proxy_resolver.h" |
| 19 #include "net/proxy/proxy_config_service_fixed.h" | 20 #include "net/proxy/proxy_config_service_fixed.h" |
| 20 #include "net/proxy/proxy_script_fetcher.h" | 21 #include "net/proxy/proxy_script_fetcher.h" |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 #include "net/proxy/proxy_config_service_win.h" | 23 #include "net/proxy/proxy_config_service_win.h" |
| 23 #include "net/proxy/proxy_resolver_winhttp.h" | 24 #include "net/proxy/proxy_resolver_winhttp.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 virtual int SetPacScript(const GURL& /*pac_url*/, | 73 virtual int SetPacScript(const GURL& /*pac_url*/, |
| 73 const string16& /*pac_script*/, | 74 const string16& /*pac_script*/, |
| 74 CompletionCallback* /*callback*/) { | 75 CompletionCallback* /*callback*/) { |
| 75 return ERR_NOT_IMPLEMENTED; | 76 return ERR_NOT_IMPLEMENTED; |
| 76 } | 77 } |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 // This factory creates V8ProxyResolvers with appropriate javascript bindings. | 80 // This factory creates V8ProxyResolvers with appropriate javascript bindings. |
| 80 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { | 81 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { |
| 81 public: | 82 public: |
| 82 // Both |async_host_resolver| and |host_resolver_loop| must remain valid for | 83 // |async_host_resolver|, |io_loop| and |net_log| must remain |
| 83 // duration of our lifetime. | 84 // valid for the duration of our lifetime. |
| 85 // Both |async_host_resolver| and |net_log| will only be operated on |
| 86 // |io_loop|. |
| 84 ProxyResolverFactoryForV8(HostResolver* async_host_resolver, | 87 ProxyResolverFactoryForV8(HostResolver* async_host_resolver, |
| 85 MessageLoop* host_resolver_loop) | 88 MessageLoop* io_loop, |
| 89 NetLog* net_log) |
| 86 : ProxyResolverFactory(true /*expects_pac_bytes*/), | 90 : ProxyResolverFactory(true /*expects_pac_bytes*/), |
| 87 async_host_resolver_(async_host_resolver), | 91 async_host_resolver_(async_host_resolver), |
| 88 host_resolver_loop_(host_resolver_loop) { | 92 io_loop_(io_loop), |
| 93 forwarding_net_log_( |
| 94 net_log ? new ForwardingNetLog(net_log, io_loop) : NULL) { |
| 89 } | 95 } |
| 90 | 96 |
| 91 virtual ProxyResolver* CreateProxyResolver() { | 97 virtual ProxyResolver* CreateProxyResolver() { |
| 92 // Create a synchronous host resolver wrapper that operates | 98 // Create a synchronous host resolver wrapper that operates |
| 93 // |async_host_resolver_| on |host_resolver_loop_|. | 99 // |async_host_resolver_| on |io_loop_|. |
| 94 SyncHostResolverBridge* sync_host_resolver = | 100 SyncHostResolverBridge* sync_host_resolver = |
| 95 new SyncHostResolverBridge(async_host_resolver_, host_resolver_loop_); | 101 new SyncHostResolverBridge(async_host_resolver_, io_loop_); |
| 96 | 102 |
| 97 ProxyResolverJSBindings* js_bindings = | 103 ProxyResolverJSBindings* js_bindings = |
| 98 ProxyResolverJSBindings::CreateDefault(sync_host_resolver); | 104 ProxyResolverJSBindings::CreateDefault(sync_host_resolver, |
| 105 forwarding_net_log_.get()); |
| 99 | 106 |
| 100 // ProxyResolverV8 takes ownership of |js_bindings|. | 107 // ProxyResolverV8 takes ownership of |js_bindings|. |
| 101 return new ProxyResolverV8(js_bindings); | 108 return new ProxyResolverV8(js_bindings); |
| 102 } | 109 } |
| 103 | 110 |
| 104 private: | 111 private: |
| 105 scoped_refptr<HostResolver> async_host_resolver_; | 112 scoped_refptr<HostResolver> async_host_resolver_; |
| 106 MessageLoop* host_resolver_loop_; | 113 MessageLoop* io_loop_; |
| 114 |
| 115 // Thread-safe wrapper around a non-threadsafe NetLog implementation. This |
| 116 // enables the proxy resolver to emit log messages from the PAC thread. |
| 117 scoped_ptr<ForwardingNetLog> forwarding_net_log_; |
| 107 }; | 118 }; |
| 108 | 119 |
| 109 // Creates ProxyResolvers using a non-V8 implementation. | 120 // Creates ProxyResolvers using a non-V8 implementation. |
| 110 class ProxyResolverFactoryForNonV8 : public ProxyResolverFactory { | 121 class ProxyResolverFactoryForNonV8 : public ProxyResolverFactory { |
| 111 public: | 122 public: |
| 112 ProxyResolverFactoryForNonV8() | 123 ProxyResolverFactoryForNonV8() |
| 113 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} | 124 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} |
| 114 | 125 |
| 115 virtual ProxyResolver* CreateProxyResolver() { | 126 virtual ProxyResolver* CreateProxyResolver() { |
| 116 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 NetLog* net_log, | 281 NetLog* net_log, |
| 271 MessageLoop* io_loop) { | 282 MessageLoop* io_loop) { |
| 272 if (num_pac_threads == 0) | 283 if (num_pac_threads == 0) |
| 273 num_pac_threads = kDefaultNumPacThreads; | 284 num_pac_threads = kDefaultNumPacThreads; |
| 274 | 285 |
| 275 ProxyResolverFactory* sync_resolver_factory; | 286 ProxyResolverFactory* sync_resolver_factory; |
| 276 if (use_v8_resolver) { | 287 if (use_v8_resolver) { |
| 277 sync_resolver_factory = | 288 sync_resolver_factory = |
| 278 new ProxyResolverFactoryForV8( | 289 new ProxyResolverFactoryForV8( |
| 279 url_request_context->host_resolver(), | 290 url_request_context->host_resolver(), |
| 280 io_loop); | 291 io_loop, |
| 292 net_log); |
| 281 } else { | 293 } else { |
| 282 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); | 294 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); |
| 283 } | 295 } |
| 284 | 296 |
| 285 ProxyResolver* proxy_resolver = | 297 ProxyResolver* proxy_resolver = |
| 286 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); | 298 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); |
| 287 | 299 |
| 288 ProxyService* proxy_service = | 300 ProxyService* proxy_service = |
| 289 new ProxyService(proxy_config_service, proxy_resolver, net_log); | 301 new ProxyService(proxy_config_service, proxy_resolver, net_log); |
| 290 | 302 |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 OnCompletion(result_); | 772 OnCompletion(result_); |
| 761 } | 773 } |
| 762 } | 774 } |
| 763 | 775 |
| 764 void SyncProxyServiceHelper::OnCompletion(int rv) { | 776 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 765 result_ = rv; | 777 result_ = rv; |
| 766 event_.Signal(); | 778 event_.Signal(); |
| 767 } | 779 } |
| 768 | 780 |
| 769 } // namespace net | 781 } // namespace net |
| OLD | NEW |