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

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

Issue 918933002: Implement utility-side proxy resolver factory Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-resolver-mojo
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2015 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/mojo_proxy_resolver_factory_impl.h"
6
7 #include "net/dns/host_resolver_mojo.h"
8 #include "net/proxy/mojo_proxy_resolver_impl.h"
9 #include "net/proxy/proxy_resolver_v8.h"
10 #include "net/proxy/proxy_resolver_v8_tracing.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
12
13 namespace net {
14 namespace {
15
16 scoped_ptr<ProxyResolver> CreateDefaultProxyResolver(
17 HostResolver* host_resolver) {
18 ProxyResolverV8::EnsureIsolateCreated();
eroman 2015/02/25 00:31:18 This should actually be moved elsewhere so it is j
19 return make_scoped_ptr(
20 new ProxyResolverV8Tracing(host_resolver, nullptr, nullptr));
21 }
22
23 // A class to manage the lifetime of a MojoProxyResolverImpl and a
24 // HostResolverMojo. An instance will remain while the message pipes for both
25 // mojo connections remain open.
26 class MojoProxyResolverHolder : public mojo::ErrorHandler {
27 public:
28 MojoProxyResolverHolder(
29 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory,
30 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
31 interfaces::HostResolverPtr host_resolver);
32
33 private:
34 // mojo::ErrorHandler override.
35 void OnConnectionError() override;
36
37 HostResolverMojo host_resolver_;
38 MojoProxyResolverImpl proxy_resolver_;
39 mojo::Binding<interfaces::ProxyResolver> binding_;
40
41 DISALLOW_COPY_AND_ASSIGN(MojoProxyResolverHolder);
42 };
43
44 MojoProxyResolverHolder::MojoProxyResolverHolder(
45 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory,
46 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
47 interfaces::HostResolverPtr host_resolver)
48 : host_resolver_(host_resolver.Pass(),
49 base::Bind(&MojoProxyResolverHolder::OnConnectionError,
50 base::Unretained(this))),
51 proxy_resolver_(proxy_resolver_factory.Run(&host_resolver_)),
52 binding_(&proxy_resolver_, request.Pass()) {
53 binding_.set_error_handler(this);
54 }
55
56 void MojoProxyResolverHolder::OnConnectionError() {
57 delete this;
58 }
59
60 } // namespace
61
62 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl(
63 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory,
64 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request)
65 : proxy_resolver_impl_factory_(proxy_resolver_factory),
66 binding_(this, request.Pass()) {
67 }
68
69 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl(
70 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request)
71 : MojoProxyResolverFactoryImpl(base::Bind(&CreateDefaultProxyResolver),
72 request.Pass()) {
73 }
74
75 MojoProxyResolverFactoryImpl::~MojoProxyResolverFactoryImpl() = default;
76
77 void MojoProxyResolverFactoryImpl::CreateResolver(
78 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
79 interfaces::HostResolverPtr host_resolver) {
80 // The MojoProxyResolverHolder will delete itself when either |request| or
81 // |host_resolver| encounters a connection error, that is, when either the
82 // ProxyResolver client or the HostResolver implementation is deleted.
83 new MojoProxyResolverHolder(proxy_resolver_impl_factory_, request.Pass(),
84 host_resolver.Pass());
85 }
86
87 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mojo_proxy_resolver_factory_impl.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698