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.
5 #ifndef NET_PROXY_PROXY_RESOLVER_MOJO_H_
6 #define NET_PROXY_PROXY_RESOLVER_MOJO_H_
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"
28 class MojoProxyResolverFactory
;
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.
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
{
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
;
48 // ProxyResolver implementation:
49 int GetProxyForURL(const GURL
& url
,
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
;
63 // Overridden from mojo::ErrorHandler:
64 void OnConnectionError() override
;
66 // Callback for ProxyResolverService::SetPacScript.
67 void OnSetPacScriptDone(
68 const scoped_refptr
<ProxyResolverScriptData
>& pac_script
,
69 const net::CompletionCallback
& callback
,
74 void AbortPendingRequests();
76 void RemoveJob(Job
* job
);
78 // Connection to the Mojo proxy resolver.
79 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_
;
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_
;
86 // Factory for connecting to new Mojo proxy resolvers.
88 MojoProxyResolverFactory
* mojo_proxy_resolver_factory_
;
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_
;
94 std::set
<Job
*> pending_jobs_
;
95 net::CancelableCompletionCallback set_pac_script_callback_
;
97 base::ThreadChecker thread_checker_
;
99 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo
);
104 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_