OLD | NEW |
---|---|
(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 #ifndef NET_PROXY_PROXY_RESOLVER_MOJO_H_ | |
6 #define NET_PROXY_PROXY_RESOLVER_MOJO_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "net/base/completion_callback.h" | |
14 #include "net/base/load_states.h" | |
15 #include "net/interfaces/host_resolver_service.mojom.h" | |
16 #include "net/interfaces/proxy_resolver_service.mojom.h" | |
17 #include "net/proxy/proxy_resolver.h" | |
18 #include "net/proxy/proxy_resolver_script_data.h" | |
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
20 | |
21 class GURL; | |
22 | |
23 namespace net { | |
24 | |
25 class BoundNetLog; | |
26 class HostResolver; | |
27 class ProxyInfo; | |
28 class MojoProxyResolverFactory; | |
29 | |
30 // Implementation of ProxyResolver that connects to a Mojo service to evaluate | |
31 // PAC scripts. This implementation only knows about Mojo services, and | |
32 // therefore that service may live in or out of process. | |
33 // | |
34 // 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 // re-connects to a new service. | |
37 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler { | |
38 public: | |
39 // Constructs a ProxyResolverMojo and connects to a new Mojo proxy resolver | |
40 // service using |proxy_resolver_factory|. The new Mojo proxy resolver uses | |
41 // |host_resolver| as the DNS resolver. |proxy_resolver_factory| and | |
42 // |host_resolver| are not owned and must outlive this. | |
43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. | |
44 explicit ProxyResolverMojo(MojoProxyResolverFactory* proxy_resolver_factory, | |
Sam McNally
2015/02/16 05:52:38
No explicit.
Anand Mistry (off Chromium)
2015/02/17 05:49:21
Done.
| |
45 HostResolver* host_resolver); | |
46 ~ProxyResolverMojo() override; | |
47 | |
48 // ProxyResolver implementation: | |
49 int GetProxyForURL(const GURL& url, | |
50 ProxyInfo* results, | |
51 const net::CompletionCallback& callback, | |
52 RequestHandle* request, | |
53 const BoundNetLog& net_log) override; | |
54 void CancelRequest(RequestHandle request) override; | |
55 LoadState GetLoadState(RequestHandle request) const override; | |
56 void CancelSetPacScript() override; | |
57 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
58 const net::CompletionCallback& callback) override; | |
59 | |
60 private: | |
61 class Job; | |
62 | |
63 // Overridden from mojo::ErrorHandler: | |
64 void OnConnectionError() override; | |
65 | |
66 // Callback for ProxyResolverService::SetPacScript. | |
67 void OnSetPacScriptDone(int32_t result); | |
68 | |
69 void SetupServices(); | |
Sam McNally
2015/02/16 05:52:38
SetUpServices
Anand Mistry (off Chromium)
2015/02/17 05:49:21
Done.
| |
70 | |
71 void CancelPendingRequests(); | |
72 | |
73 void RemoveJob(Job* job); | |
74 | |
75 // Connection to the Mojo proxy resolver. | |
76 interfaces::ProxyResolverPtr proxy_resolver_ptr_; | |
77 | |
78 // Binding to the Mojo host resolver. | |
79 scoped_ptr<mojo::StrongBinding<interfaces::HostResolver>> | |
80 host_resolver_binding_; | |
81 | |
82 // Factory for connecting to new Mojo proxy resolvers. | |
83 // Not owned. | |
84 MojoProxyResolverFactory* proxy_resolver_factory_; | |
85 | |
86 // Parameters for creating a new Mojo proxy resolver when the existing one | |
87 // disconnects (i.e. when utility process crashes). | |
88 HostResolver* host_resolver_; | |
89 scoped_refptr<ProxyResolverScriptData> pac_script_; | |
90 | |
91 std::set<Job*> pending_jobs_; | |
92 net::CompletionCallback set_pac_script_callback_; | |
93 | |
94 base::ThreadChecker thread_checker_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); | |
97 }; | |
98 | |
99 } // namespace net | |
100 | |
101 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ | |
OLD | NEW |