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 #ifndef NET_PROXY_PROXY_RESOLVER_MOJO_H_ | 5 #ifndef NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
6 #define NET_PROXY_PROXY_RESOLVER_MOJO_H_ | 6 #define NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/callback_helpers.h" | |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
14 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
16 #include "net/dns/mojo_host_resolver_impl.h" | |
15 #include "net/interfaces/host_resolver_service.mojom.h" | 17 #include "net/interfaces/host_resolver_service.mojom.h" |
16 #include "net/interfaces/proxy_resolver_service.mojom.h" | 18 #include "net/interfaces/proxy_resolver_service.mojom.h" |
17 #include "net/proxy/proxy_resolver.h" | 19 #include "net/proxy/proxy_resolver.h" |
18 #include "net/proxy/proxy_resolver_script_data.h" | 20 #include "net/proxy/proxy_resolver_script_data.h" |
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 21 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
20 | 22 |
21 class GURL; | 23 class GURL; |
22 | 24 |
23 namespace net { | 25 namespace net { |
24 | 26 |
25 class BoundNetLog; | 27 class BoundNetLog; |
26 class HostResolver; | 28 class HostResolver; |
27 class ProxyInfo; | 29 class ProxyInfo; |
28 class MojoProxyResolverFactory; | |
29 | 30 |
30 // Implementation of ProxyResolver that connects to a Mojo service to evaluate | 31 // Implementation of ProxyResolver that connects to a Mojo service to evaluate |
31 // PAC scripts. This implementation only knows about Mojo services, and | 32 // PAC scripts. This implementation only knows about Mojo services, and |
32 // therefore that service may live in or out of process. | 33 // therefore that service may live in or out of process. |
33 // | 34 // |
34 // This implementation handles disconnections from the Mojo service (i.e. if the | 35 // This implementation reports disconnections from the Mojo service (i.e. if the |
35 // service is out-of-process and that process crashes) and transparently | 36 // service is out-of-process and that process crashes) using the error code |
36 // re-connects to a new service. | 37 // ERR_PAC_SCRIPT_TERMINATED. |
37 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler { | 38 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler { |
38 public: | 39 public: |
39 // Constructs a ProxyResolverMojo and connects to a new Mojo proxy resolver | 40 // Constructs a ProxyResolverMojo that will use |mojo_proxy_resolver| to |
40 // service using |mojo_proxy_resolver_factory|. The new Mojo proxy resolver | 41 // service requests. |host_resolver| is not owned and must outlive this. |
41 // uses |host_resolver| as the DNS resolver. |mojo_proxy_resolver_factory| | 42 // When deleted, the closure contained within |runner| will be run. |
eroman
2015/05/02 02:22:31
can you come up with a better name than |runner|?
Sam McNally
2015/05/04 06:17:23
Done.
| |
42 // and |host_resolver| are not owned and must outlive this. | |
43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. | 43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. |
44 ProxyResolverMojo(MojoProxyResolverFactory* mojo_proxy_resolver_factory, | 44 ProxyResolverMojo( |
45 HostResolver* host_resolver); | 45 interfaces::ProxyResolverPtr mojo_proxy_resolver, |
46 HostResolver* host_resolver, | |
47 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request, | |
48 scoped_ptr<base::ScopedClosureRunner> runner); | |
46 ~ProxyResolverMojo() override; | 49 ~ProxyResolverMojo() override; |
47 | 50 |
48 // ProxyResolver implementation: | 51 // ProxyResolver implementation: |
49 int GetProxyForURL(const GURL& url, | 52 int GetProxyForURL(const GURL& url, |
50 ProxyInfo* results, | 53 ProxyInfo* results, |
51 const net::CompletionCallback& callback, | 54 const net::CompletionCallback& callback, |
52 RequestHandle* request, | 55 RequestHandle* request, |
53 const BoundNetLog& net_log) override; | 56 const BoundNetLog& net_log) override; |
54 void CancelRequest(RequestHandle request) override; | 57 void CancelRequest(RequestHandle request) override; |
55 LoadState GetLoadState(RequestHandle request) const override; | 58 LoadState GetLoadState(RequestHandle request) const override; |
56 void CancelSetPacScript() override; | 59 void CancelSetPacScript() override; |
57 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, | 60 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, |
58 const net::CompletionCallback& callback) override; | 61 const net::CompletionCallback& callback) override; |
59 | 62 |
60 private: | 63 private: |
61 class Job; | 64 class Job; |
62 | 65 |
63 // Overridden from mojo::ErrorHandler: | 66 // Overridden from mojo::ErrorHandler: |
64 void OnConnectionError() override; | 67 void OnConnectionError() override; |
65 | 68 |
66 // Callback for ProxyResolverService::SetPacScript. | 69 // Callback for ProxyResolverService::SetPacScript. |
67 void OnSetPacScriptDone( | 70 void OnSetPacScriptDone( |
68 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 71 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
69 const net::CompletionCallback& callback, | 72 const net::CompletionCallback& callback, |
70 int32_t result); | 73 int32_t result); |
71 | 74 |
72 void SetUpServices(); | |
73 | |
74 void RemoveJob(Job* job); | 75 void RemoveJob(Job* job); |
75 | 76 |
76 // Connection to the Mojo proxy resolver. | 77 // Connection to the Mojo proxy resolver. |
77 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; | 78 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; |
78 | 79 |
79 // Mojo host resolver service and binding. | |
80 scoped_ptr<interfaces::HostResolver> mojo_host_resolver_; | |
81 scoped_ptr<mojo::Binding<interfaces::HostResolver>> | |
82 mojo_host_resolver_binding_; | |
83 | |
84 // Factory for connecting to new Mojo proxy resolvers. | |
85 // Not owned. | |
86 MojoProxyResolverFactory* mojo_proxy_resolver_factory_; | |
87 | |
88 // DNS resolver, saved for creating a new Mojo proxy resolver when the | |
89 // existing one disconnects (i.e. when utility process crashes). | |
90 HostResolver* host_resolver_; | |
91 | |
92 std::set<Job*> pending_jobs_; | 80 std::set<Job*> pending_jobs_; |
93 net::CancelableCompletionCallback set_pac_script_callback_; | 81 net::CancelableCompletionCallback set_pac_script_callback_; |
94 | 82 |
95 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
96 | 84 |
85 MojoHostResolverImpl host_resolver_; | |
86 mojo::Binding<interfaces::HostResolver> host_resolver_binding_; | |
87 scoped_ptr<base::ScopedClosureRunner> runner_; | |
88 | |
97 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); | 89 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); |
98 }; | 90 }; |
99 | 91 |
100 } // namespace net | 92 } // namespace net |
101 | 93 |
102 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ | 94 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
OLD | NEW |