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

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

Issue 10874077: net: Add a new target 'net_with_v8'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix7 Created 8 years, 3 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
« net/proxy/proxy_service.h ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/proxy/proxy_service.h"
6
7 #include "base/logging.h"
8 #include "net/proxy/multi_threaded_proxy_resolver.h"
9 #include "net/proxy/network_delegate_error_observer.h"
10 #include "net/proxy/proxy_resolver.h"
11 #include "net/proxy/proxy_resolver_js_bindings.h"
12 #include "net/proxy/proxy_resolver_v8.h"
13 #include "net/proxy/sync_host_resolver_bridge.h"
14
15 namespace net {
16 namespace {
17
18 // This factory creates V8ProxyResolvers with appropriate javascript bindings.
19 class ProxyResolverFactoryForV8 : public ProxyResolverFactory {
20 public:
21 // |async_host_resolver|, |io_loop| and |net_log| must remain
22 // valid for the duration of our lifetime.
23 // |async_host_resolver| will only be operated on |io_loop|.
24 // TODO(willchan): remove io_loop and replace it with origin_loop.
25 ProxyResolverFactoryForV8(HostResolver* async_host_resolver,
26 MessageLoop* io_loop,
27 base::MessageLoopProxy* origin_loop,
28 NetLog* net_log,
29 NetworkDelegate* network_delegate)
30 : ProxyResolverFactory(true /*expects_pac_bytes*/),
31 async_host_resolver_(async_host_resolver),
32 io_loop_(io_loop),
33 origin_loop_(origin_loop),
34 net_log_(net_log),
35 network_delegate_(network_delegate) {
36 }
37
38 virtual ProxyResolver* CreateProxyResolver() OVERRIDE {
39 // Create a synchronous host resolver wrapper that operates
40 // |async_host_resolver_| on |io_loop_|.
41 SyncHostResolverBridge* sync_host_resolver =
42 new SyncHostResolverBridge(async_host_resolver_, io_loop_);
43
44 NetworkDelegateErrorObserver* error_observer =
45 new NetworkDelegateErrorObserver(
46 network_delegate_, origin_loop_.get());
47
48 // ProxyResolverJSBindings takes ownership of |error_observer| and
49 // |sync_host_resolver|.
50 ProxyResolverJSBindings* js_bindings =
51 ProxyResolverJSBindings::CreateDefault(
52 sync_host_resolver, net_log_, error_observer);
53
54 // ProxyResolverV8 takes ownership of |js_bindings|.
55 return new ProxyResolverV8(js_bindings);
56 }
57
58 private:
59 HostResolver* const async_host_resolver_;
60 MessageLoop* io_loop_;
61 scoped_refptr<base::MessageLoopProxy> origin_loop_;
62 NetLog* net_log_;
63 NetworkDelegate* network_delegate_;
64 };
65
66 } // namespace
67
68 // static
69 ProxyService* ProxyService::CreateUsingV8ProxyResolver(
70 ProxyConfigService* proxy_config_service,
71 size_t num_pac_threads,
72 ProxyScriptFetcher* proxy_script_fetcher,
73 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
74 HostResolver* host_resolver,
75 NetLog* net_log,
76 NetworkDelegate* network_delegate) {
77 DCHECK(proxy_config_service);
78 DCHECK(proxy_script_fetcher);
79 DCHECK(dhcp_proxy_script_fetcher);
80 DCHECK(host_resolver);
81
82 if (num_pac_threads == 0)
83 num_pac_threads = kDefaultNumPacThreads;
84
85 ProxyResolverFactory* sync_resolver_factory =
86 new ProxyResolverFactoryForV8(
87 host_resolver,
88 MessageLoop::current(),
89 base::MessageLoopProxy::current(),
90 net_log,
91 network_delegate);
92
93 ProxyResolver* proxy_resolver =
94 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads);
95
96 ProxyService* proxy_service =
97 new ProxyService(proxy_config_service, proxy_resolver, net_log);
98
99 // Configure fetchers to use for PAC script downloads and auto-detect.
100 proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
101 dhcp_proxy_script_fetcher);
102
103 return proxy_service;
104 }
105
106 } // namespace net
OLDNEW
« net/proxy/proxy_service.h ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698