Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_mojo.h" | 5 #include "net/proxy/proxy_service_mojo.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "net/dns/host_resolver_mojo.h" | 9 #include "net/dns/mojo_host_resolver_impl.h" |
| 9 #include "net/interfaces/proxy_resolver_service.mojom.h" | 10 #include "net/interfaces/proxy_resolver_service.mojom.h" |
| 10 #include "net/proxy/in_process_mojo_proxy_resolver_factory.h" | 11 #include "net/proxy/in_process_mojo_proxy_resolver_factory.h" |
| 11 #include "net/proxy/mojo_proxy_resolver_impl.h" | 12 #include "net/proxy/mojo_proxy_resolver_impl.h" |
| 12 #include "net/proxy/proxy_resolver_factory.h" | 13 #include "net/proxy/proxy_resolver_factory.h" |
| 13 #include "net/proxy/proxy_resolver_mojo.h" | 14 #include "net/proxy/proxy_resolver_mojo.h" |
| 14 #include "net/proxy/proxy_resolver_v8_tracing.h" | 15 #include "net/proxy/proxy_resolver_v8_tracing.h" |
| 15 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 21 class MojoHostResolverHolder { | |
| 22 public: | |
| 23 // Connects |host_resolver_request| to |host_resolver| using a | |
| 24 // MojoHostResolverImpl that will remain until the returned | |
| 25 // base::ScopedClosureRunner is destroyed. |runner| is destroyed when the | |
| 26 // returned base::ScopedClosureRunner is destroyed. | |
| 27 static scoped_ptr<base::ScopedClosureRunner> Create( | |
|
eroman
2015/04/15 00:46:44
This code is hard to read and the ownerships hard
Sam McNally
2015/04/15 06:04:22
Moved ownership of the MojoHostResolverImpl back i
| |
| 28 HostResolver* host_resolver, | |
| 29 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request, | |
| 30 scoped_ptr<base::ScopedClosureRunner> runner) { | |
| 31 return make_scoped_ptr(new base::ScopedClosureRunner(base::Bind( | |
| 32 &MojoHostResolverHolder::Delete, | |
| 33 base::Passed(make_scoped_ptr(new MojoHostResolverHolder( | |
| 34 host_resolver, host_resolver_request.Pass(), runner.Pass())))))); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 MojoHostResolverHolder( | |
| 39 HostResolver* host_resolver, | |
| 40 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request, | |
| 41 scoped_ptr<base::ScopedClosureRunner> runner) | |
| 42 : mojo_host_resolver_(host_resolver), | |
| 43 mojo_host_resolver_binding_(&mojo_host_resolver_, | |
| 44 host_resolver_request.Pass()), | |
| 45 runner_(runner.Pass()) {} | |
| 46 | |
| 47 // Implicitly delete when |holder| falls out of scope. | |
| 48 static void Delete(scoped_ptr<MojoHostResolverHolder> holder) {} | |
| 49 | |
| 50 MojoHostResolverImpl mojo_host_resolver_; | |
| 51 mojo::Binding<interfaces::HostResolver> mojo_host_resolver_binding_; | |
| 52 scoped_ptr<base::ScopedClosureRunner> runner_; | |
| 53 }; | |
| 54 | |
| 20 class ProxyResolverFactoryForMojoResolver : public ProxyResolverFactory { | 55 class ProxyResolverFactoryForMojoResolver : public ProxyResolverFactory { |
| 21 public: | 56 public: |
| 22 ProxyResolverFactoryForMojoResolver( | 57 ProxyResolverFactoryForMojoResolver( |
| 23 MojoProxyResolverFactory* mojo_proxy_factory, | 58 MojoProxyResolverFactory* mojo_proxy_factory, |
| 24 HostResolver* host_resolver) | 59 HostResolver* host_resolver) |
| 25 : ProxyResolverFactory(true), | 60 : ProxyResolverFactory(true), |
| 26 mojo_proxy_factory_(mojo_proxy_factory), | 61 mojo_proxy_factory_(mojo_proxy_factory), |
| 27 host_resolver_(host_resolver) {} | 62 host_resolver_(host_resolver) {} |
| 28 | 63 |
| 29 // ProxyResolverFactory override. | 64 // ProxyResolverFactory override. |
| 30 scoped_ptr<ProxyResolver> CreateProxyResolver() override { | 65 scoped_ptr<ProxyResolver> CreateProxyResolver() override { |
| 66 interfaces::HostResolverPtr mojo_host_resolver_ptr; | |
| 67 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr; | |
| 68 auto host_resolver_request = mojo::GetProxy(&mojo_host_resolver_ptr); | |
| 69 scoped_ptr<base::ScopedClosureRunner> runner( | |
| 70 mojo_proxy_factory_->Create(mojo::GetProxy(&mojo_proxy_resolver_ptr), | |
| 71 mojo_host_resolver_ptr.Pass())); | |
| 72 runner = MojoHostResolverHolder::Create( | |
| 73 host_resolver_, host_resolver_request.Pass(), runner.Pass()); | |
| 31 return make_scoped_ptr( | 74 return make_scoped_ptr( |
| 32 new ProxyResolverMojo(mojo_proxy_factory_, host_resolver_)); | 75 new ProxyResolverMojo(mojo_proxy_resolver_ptr.Pass(), runner.Pass())); |
| 33 } | 76 } |
| 34 | 77 |
| 35 private: | 78 private: |
| 36 MojoProxyResolverFactory* const mojo_proxy_factory_; | 79 MojoProxyResolverFactory* const mojo_proxy_factory_; |
| 37 HostResolver* const host_resolver_; | 80 HostResolver* const host_resolver_; |
| 38 | 81 |
| 39 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryForMojoResolver); | 82 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryForMojoResolver); |
| 40 }; | 83 }; |
| 41 | 84 |
| 42 } // namespace | 85 } // namespace |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 HostResolver* host_resolver, | 117 HostResolver* host_resolver, |
| 75 NetLog* net_log, | 118 NetLog* net_log, |
| 76 NetworkDelegate* network_delegate) { | 119 NetworkDelegate* network_delegate) { |
| 77 return CreateProxyServiceUsingMojoFactory( | 120 return CreateProxyServiceUsingMojoFactory( |
| 78 InProcessMojoProxyResolverFactory::GetInstance(), proxy_config_service, | 121 InProcessMojoProxyResolverFactory::GetInstance(), proxy_config_service, |
| 79 proxy_script_fetcher, dhcp_proxy_script_fetcher, host_resolver, net_log, | 122 proxy_script_fetcher, dhcp_proxy_script_fetcher, host_resolver, net_log, |
| 80 network_delegate); | 123 network_delegate); |
| 81 } | 124 } |
| 82 | 125 |
| 83 } // namespace net | 126 } // namespace net |
| OLD | NEW |