Revert of suppress unaddressable error in ManifestBrowserTest.CORSManifest (patchset...
[chromium-blink-merge.git] / net / proxy / proxy_resolver_mojo.h
blob9d97095142479b2bd58d78d096efecd3d9e1c302
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_
8 #include <set>
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"
21 class GURL;
23 namespace net {
25 class BoundNetLog;
26 class HostResolver;
27 class ProxyInfo;
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 {
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;
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;
60 private:
61 class Job;
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,
70 int32_t result);
72 void SetUpServices();
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.
87 // Not owned.
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);
102 } // namespace net
104 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_