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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "net/base/load_states.h" | 14 #include "net/base/load_states.h" |
15 #include "net/interfaces/host_resolver_service.mojom.h" | 15 #include "net/interfaces/host_resolver_service.mojom.h" |
16 #include "net/interfaces/proxy_resolver_service.mojom.h" | 16 #include "net/interfaces/proxy_resolver_service.mojom.h" |
17 #include "net/proxy/proxy_resolver.h" | 17 #include "net/proxy/proxy_resolver.h" |
18 #include "net/proxy/proxy_resolver_script_data.h" | 18 #include "net/proxy/proxy_resolver_script_data.h" |
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 19 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
20 | 20 |
21 class GURL; | 21 class GURL; |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 | 24 |
25 class BoundNetLog; | 25 class BoundNetLog; |
26 class HostResolver; | 26 class HostResolver; |
27 class ProxyInfo; | 27 class ProxyInfo; |
| 28 class ProxyResolverErrorObserver; |
28 class MojoProxyResolverFactory; | 29 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 handles 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) and transparently |
36 // re-connects to a new service. | 37 // re-connects to a new service. |
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 and connects to a new Mojo proxy resolver |
40 // service using |mojo_proxy_resolver_factory|. The new Mojo proxy resolver | 41 // service using |mojo_proxy_resolver_factory|. The new Mojo proxy resolver |
41 // uses |host_resolver| as the DNS resolver. |mojo_proxy_resolver_factory| | 42 // uses |host_resolver| as the DNS resolver. |mojo_proxy_resolver_factory| |
42 // and |host_resolver| are not owned and must outlive this. | 43 // and |host_resolver| are not owned and must outlive this. |
43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. | 44 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. |
44 ProxyResolverMojo(MojoProxyResolverFactory* mojo_proxy_resolver_factory, | 45 ProxyResolverMojo(MojoProxyResolverFactory* mojo_proxy_resolver_factory, |
45 HostResolver* host_resolver); | 46 HostResolver* host_resolver, |
| 47 scoped_ptr<ProxyResolverErrorObserver> error_observer); |
46 ~ProxyResolverMojo() override; | 48 ~ProxyResolverMojo() override; |
47 | 49 |
48 // ProxyResolver implementation: | 50 // ProxyResolver implementation: |
49 int GetProxyForURL(const GURL& url, | 51 int GetProxyForURL(const GURL& url, |
50 ProxyInfo* results, | 52 ProxyInfo* results, |
51 const net::CompletionCallback& callback, | 53 const net::CompletionCallback& callback, |
52 RequestHandle* request, | 54 RequestHandle* request, |
53 const BoundNetLog& net_log) override; | 55 const BoundNetLog& net_log) override; |
54 void CancelRequest(RequestHandle request) override; | 56 void CancelRequest(RequestHandle request) override; |
55 LoadState GetLoadState(RequestHandle request) const override; | 57 LoadState GetLoadState(RequestHandle request) const override; |
56 void CancelSetPacScript() override; | 58 void CancelSetPacScript() override; |
57 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, | 59 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, |
58 const net::CompletionCallback& callback) override; | 60 const net::CompletionCallback& callback) override; |
59 | 61 |
60 private: | 62 private: |
61 class Job; | 63 class Job; |
| 64 class ErrorObserverHolder; |
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 |
(...skipping 12 matching lines...) Expand all Loading... |
84 mojo_host_resolver_binding_; | 87 mojo_host_resolver_binding_; |
85 | 88 |
86 // Factory for connecting to new Mojo proxy resolvers. | 89 // Factory for connecting to new Mojo proxy resolvers. |
87 // Not owned. | 90 // Not owned. |
88 MojoProxyResolverFactory* mojo_proxy_resolver_factory_; | 91 MojoProxyResolverFactory* mojo_proxy_resolver_factory_; |
89 | 92 |
90 // DNS resolver, saved for creating a new Mojo proxy resolver when the | 93 // DNS resolver, saved for creating a new Mojo proxy resolver when the |
91 // existing one disconnects (i.e. when utility process crashes). | 94 // existing one disconnects (i.e. when utility process crashes). |
92 HostResolver* host_resolver_; | 95 HostResolver* host_resolver_; |
93 | 96 |
| 97 scoped_ptr<ErrorObserverHolder> error_observer_; |
| 98 |
94 std::set<Job*> pending_jobs_; | 99 std::set<Job*> pending_jobs_; |
95 net::CancelableCompletionCallback set_pac_script_callback_; | 100 net::CancelableCompletionCallback set_pac_script_callback_; |
96 | 101 |
97 base::ThreadChecker thread_checker_; | 102 base::ThreadChecker thread_checker_; |
98 | 103 |
99 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); | 104 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); |
100 }; | 105 }; |
101 | 106 |
102 } // namespace net | 107 } // namespace net |
103 | 108 |
104 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ | 109 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
OLD | NEW |