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> | |
9 | |
10 #include "base/callback_helpers.h" | |
11 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
13 #include "base/threading/thread_checker.h" | |
14 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
15 #include "net/base/load_states.h" | |
16 #include "net/interfaces/host_resolver_service.mojom.h" | |
17 #include "net/interfaces/proxy_resolver_service.mojom.h" | |
18 #include "net/proxy/proxy_resolver.h" | |
19 #include "net/proxy/proxy_resolver_factory.h" | 11 #include "net/proxy/proxy_resolver_factory.h" |
20 #include "net/proxy/proxy_resolver_script_data.h" | |
21 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
22 | 13 |
23 class GURL; | |
24 | |
25 namespace net { | 14 namespace net { |
26 | |
27 class BoundNetLog; | |
28 class HostResolver; | 15 class HostResolver; |
29 class ProxyInfo; | 16 class ProxyResolverErrorObserver; |
| 17 class ProxyResolverScriptData; |
30 class MojoProxyResolverFactory; | 18 class MojoProxyResolverFactory; |
31 | 19 |
32 // Implementation of ProxyResolver that connects to a Mojo service to evaluate | |
33 // PAC scripts. This implementation only knows about Mojo services, and | |
34 // therefore that service may live in or out of process. | |
35 // | |
36 // This implementation reports disconnections from the Mojo service (i.e. if the | |
37 // service is out-of-process and that process crashes) using the error code | |
38 // ERR_PAC_SCRIPT_TERMINATED. | |
39 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler { | |
40 public: | |
41 // Constructs a ProxyResolverMojo that connects to a mojo proxy resolver | |
42 // implementation using |resolver_ptr|. The implementation uses | |
43 // |host_resolver| as the DNS resolver, using |host_resolver_binding| to | |
44 // communicate with it. When deleted, the closure contained within | |
45 // |on_delete_callback_runner| will be run. | |
46 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. | |
47 ProxyResolverMojo( | |
48 interfaces::ProxyResolverPtr resolver_ptr, | |
49 scoped_ptr<interfaces::HostResolver> host_resolver, | |
50 scoped_ptr<mojo::Binding<interfaces::HostResolver>> host_resolver_binding, | |
51 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner); | |
52 ~ProxyResolverMojo() override; | |
53 | |
54 // ProxyResolver implementation: | |
55 int GetProxyForURL(const GURL& url, | |
56 ProxyInfo* results, | |
57 const net::CompletionCallback& callback, | |
58 RequestHandle* request, | |
59 const BoundNetLog& net_log) override; | |
60 void CancelRequest(RequestHandle request) override; | |
61 LoadState GetLoadState(RequestHandle request) const override; | |
62 void CancelSetPacScript() override; | |
63 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
64 const net::CompletionCallback& callback) override; | |
65 | |
66 private: | |
67 class Job; | |
68 | |
69 // Overridden from mojo::ErrorHandler: | |
70 void OnConnectionError() override; | |
71 | |
72 void RemoveJob(Job* job); | |
73 | |
74 // Connection to the Mojo proxy resolver. | |
75 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; | |
76 | |
77 // Mojo host resolver service and binding. | |
78 scoped_ptr<interfaces::HostResolver> mojo_host_resolver_; | |
79 scoped_ptr<mojo::Binding<interfaces::HostResolver>> | |
80 mojo_host_resolver_binding_; | |
81 | |
82 std::set<Job*> pending_jobs_; | |
83 | |
84 base::ThreadChecker thread_checker_; | |
85 | |
86 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); | |
89 }; | |
90 | |
91 // Implementation of ProxyResolverFactory that connects to a Mojo service to | 20 // Implementation of ProxyResolverFactory that connects to a Mojo service to |
92 // create implementations of a Mojo proxy resolver to back a ProxyResolverMojo. | 21 // create implementations of a Mojo proxy resolver to back a ProxyResolverMojo. |
93 class ProxyResolverFactoryMojo : public ProxyResolverFactory { | 22 class ProxyResolverFactoryMojo : public ProxyResolverFactory { |
94 public: | 23 public: |
95 ProxyResolverFactoryMojo(MojoProxyResolverFactory* mojo_proxy_factory, | 24 ProxyResolverFactoryMojo( |
96 HostResolver* host_resolver); | 25 MojoProxyResolverFactory* mojo_proxy_factory, |
| 26 HostResolver* host_resolver, |
| 27 const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>& |
| 28 error_observer_factory); |
97 ~ProxyResolverFactoryMojo() override; | 29 ~ProxyResolverFactoryMojo() override; |
98 | 30 |
99 // ProxyResolverFactory override. | 31 // ProxyResolverFactory override. |
100 int CreateProxyResolver( | 32 int CreateProxyResolver( |
101 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 33 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
102 scoped_ptr<ProxyResolver>* resolver, | 34 scoped_ptr<ProxyResolver>* resolver, |
103 const CompletionCallback& callback, | 35 const CompletionCallback& callback, |
104 scoped_ptr<Request>* request) override; | 36 scoped_ptr<Request>* request) override; |
105 | 37 |
106 private: | 38 private: |
107 class Job; | 39 class Job; |
108 | 40 |
109 MojoProxyResolverFactory* const mojo_proxy_factory_; | 41 MojoProxyResolverFactory* const mojo_proxy_factory_; |
110 HostResolver* const host_resolver_; | 42 HostResolver* const host_resolver_; |
| 43 const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()> |
| 44 error_observer_factory_; |
111 | 45 |
112 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryMojo); | 46 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryMojo); |
113 }; | 47 }; |
114 | 48 |
115 } // namespace net | 49 } // namespace net |
116 | 50 |
117 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ | 51 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
OLD | NEW |