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/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 |mojo_proxy_resolver_factory|. The new Mojo proxy resolver |
| 41 // uses |host_resolver| as the DNS resolver. |mojo_proxy_resolver_factory| |
| 42 // and |host_resolver| are not owned and must outlive this. |
| 43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. |
| 44 ProxyResolverMojo(MojoProxyResolverFactory* mojo_proxy_resolver_factory, |
| 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( |
| 68 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 69 const net::CompletionCallback& callback, |
| 70 int32_t result); |
| 71 |
| 72 void SetUpServices(); |
| 73 |
| 74 void AbortPendingRequests(); |
| 75 |
| 76 void RemoveJob(Job* job); |
| 77 |
| 78 // Connection to the Mojo proxy resolver. |
| 79 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; |
| 80 |
| 81 // Mojo host resolver service and binding. |
| 82 scoped_ptr<interfaces::HostResolver> mojo_host_resolver_; |
| 83 scoped_ptr<mojo::Binding<interfaces::HostResolver>> |
| 84 mojo_host_resolver_binding_; |
| 85 |
| 86 // Factory for connecting to new Mojo proxy resolvers. |
| 87 // Not owned. |
| 88 MojoProxyResolverFactory* mojo_proxy_resolver_factory_; |
| 89 |
| 90 // DNS resolver, saved for creating a new Mojo proxy resolver when the |
| 91 // existing one disconnects (i.e. when utility process crashes). |
| 92 HostResolver* host_resolver_; |
| 93 |
| 94 std::set<Job*> pending_jobs_; |
| 95 net::CancelableCompletionCallback set_pac_script_callback_; |
| 96 |
| 97 base::ThreadChecker thread_checker_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); |
| 100 }; |
| 101 |
| 102 } // namespace net |
| 103 |
| 104 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ |
OLD | NEW |