OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_v8.h" | 5 #include "net/proxy/proxy_service_v8.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/proxy/multi_threaded_proxy_resolver.h" | |
9 #include "net/proxy/network_delegate_error_observer.h" | 8 #include "net/proxy/network_delegate_error_observer.h" |
10 #include "net/proxy/proxy_resolver.h" | 9 #include "net/proxy/proxy_resolver.h" |
11 #include "net/proxy/proxy_resolver_js_bindings.h" | 10 #include "net/proxy/proxy_resolver_v8_tracing.h" |
12 #include "net/proxy/proxy_resolver_v8.h" | |
13 #include "net/proxy/proxy_service.h" | 11 #include "net/proxy/proxy_service.h" |
14 #include "net/proxy/sync_host_resolver_bridge.h" | |
15 | 12 |
16 namespace net { | 13 namespace net { |
17 namespace { | |
18 | |
19 // This factory creates V8ProxyResolvers with appropriate javascript bindings. | |
20 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { | |
21 public: | |
22 // |async_host_resolver|, |io_loop| and |net_log| must remain | |
23 // valid for the duration of our lifetime. | |
24 // |async_host_resolver| will only be operated on |io_loop|. | |
25 // TODO(willchan): remove io_loop and replace it with origin_loop. | |
26 ProxyResolverFactoryForV8(HostResolver* async_host_resolver, | |
27 MessageLoop* io_loop, | |
28 base::MessageLoopProxy* origin_loop, | |
29 NetLog* net_log, | |
30 NetworkDelegate* network_delegate) | |
31 : ProxyResolverFactory(true /*expects_pac_bytes*/), | |
32 async_host_resolver_(async_host_resolver), | |
33 io_loop_(io_loop), | |
34 origin_loop_(origin_loop), | |
35 net_log_(net_log), | |
36 network_delegate_(network_delegate) { | |
37 } | |
38 | |
39 virtual ProxyResolver* CreateProxyResolver() OVERRIDE { | |
40 // Create a synchronous host resolver wrapper that operates | |
41 // |async_host_resolver_| on |io_loop_|. | |
42 SyncHostResolverBridge* sync_host_resolver = | |
43 new SyncHostResolverBridge(async_host_resolver_, io_loop_); | |
44 | |
45 NetworkDelegateErrorObserver* error_observer = | |
46 new NetworkDelegateErrorObserver( | |
47 network_delegate_, origin_loop_.get()); | |
48 | |
49 // ProxyResolverJSBindings takes ownership of |error_observer| and | |
50 // |sync_host_resolver|. | |
51 ProxyResolverJSBindings* js_bindings = | |
52 ProxyResolverJSBindings::CreateDefault( | |
53 sync_host_resolver, net_log_, error_observer); | |
54 | |
55 // ProxyResolverV8 takes ownership of |js_bindings|. | |
56 return new ProxyResolverV8(js_bindings); | |
57 } | |
58 | |
59 private: | |
60 HostResolver* const async_host_resolver_; | |
61 MessageLoop* io_loop_; | |
62 scoped_refptr<base::MessageLoopProxy> origin_loop_; | |
63 NetLog* net_log_; | |
64 NetworkDelegate* network_delegate_; | |
65 }; | |
66 | |
67 } // namespace | |
68 | 14 |
69 // static | 15 // static |
70 ProxyService* CreateProxyServiceUsingV8ProxyResolver( | 16 ProxyService* CreateProxyServiceUsingV8ProxyResolver( |
71 ProxyConfigService* proxy_config_service, | 17 ProxyConfigService* proxy_config_service, |
72 size_t num_pac_threads, | |
73 ProxyScriptFetcher* proxy_script_fetcher, | 18 ProxyScriptFetcher* proxy_script_fetcher, |
74 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | 19 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, |
75 HostResolver* host_resolver, | 20 HostResolver* host_resolver, |
76 NetLog* net_log, | 21 NetLog* net_log, |
77 NetworkDelegate* network_delegate) { | 22 NetworkDelegate* network_delegate) { |
78 DCHECK(proxy_config_service); | 23 DCHECK(proxy_config_service); |
79 DCHECK(proxy_script_fetcher); | 24 DCHECK(proxy_script_fetcher); |
80 DCHECK(dhcp_proxy_script_fetcher); | 25 DCHECK(dhcp_proxy_script_fetcher); |
81 DCHECK(host_resolver); | 26 DCHECK(host_resolver); |
82 | 27 |
83 if (num_pac_threads == 0) | 28 ProxyResolverErrorObserver* error_observer = |
84 num_pac_threads = ProxyService::kDefaultNumPacThreads; | 29 new NetworkDelegateErrorObserver( |
85 | 30 network_delegate, base::MessageLoopProxy::current()); |
86 ProxyResolverFactory* sync_resolver_factory = | |
87 new ProxyResolverFactoryForV8( | |
88 host_resolver, | |
89 MessageLoop::current(), | |
90 base::MessageLoopProxy::current(), | |
91 net_log, | |
92 network_delegate); | |
93 | 31 |
94 ProxyResolver* proxy_resolver = | 32 ProxyResolver* proxy_resolver = |
95 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); | 33 new ProxyResolverV8Tracing(host_resolver, error_observer, net_log); |
96 | 34 |
97 ProxyService* proxy_service = | 35 ProxyService* proxy_service = |
98 new ProxyService(proxy_config_service, proxy_resolver, net_log); | 36 new ProxyService(proxy_config_service, proxy_resolver, net_log); |
99 | 37 |
100 // Configure fetchers to use for PAC script downloads and auto-detect. | 38 // Configure fetchers to use for PAC script downloads and auto-detect. |
101 proxy_service->SetProxyScriptFetchers(proxy_script_fetcher, | 39 proxy_service->SetProxyScriptFetchers(proxy_script_fetcher, |
102 dhcp_proxy_script_fetcher); | 40 dhcp_proxy_script_fetcher); |
103 | 41 |
104 return proxy_service; | 42 return proxy_service; |
105 } | 43 } |
106 | 44 |
107 } // namespace net | 45 } // namespace net |
OLD | NEW |