Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: net/proxy/proxy_resolver_mojo.h

Issue 1076083002: Shut down proxy resolver utility processes when no longer needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-service-with-factory-restart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/callback_helpers.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
15 #include "net/base/load_states.h" 16 #include "net/base/load_states.h"
16 #include "net/interfaces/host_resolver_service.mojom.h" 17 #include "net/interfaces/host_resolver_service.mojom.h"
17 #include "net/interfaces/proxy_resolver_service.mojom.h" 18 #include "net/interfaces/proxy_resolver_service.mojom.h"
18 #include "net/proxy/proxy_resolver.h" 19 #include "net/proxy/proxy_resolver.h"
19 #include "net/proxy/proxy_resolver_script_data.h" 20 #include "net/proxy/proxy_resolver_script_data.h"
20 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" 21 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
21 22
22 class GURL; 23 class GURL;
23 24
24 namespace net { 25 namespace net {
25 26
26 class BoundNetLog; 27 class BoundNetLog;
27 class HostResolver; 28 class HostResolver;
28 class ProxyInfo; 29 class ProxyInfo;
29 class MojoProxyResolverFactory; 30 class MojoProxyResolverFactory;
30 31
31 // Implementation of ProxyResolver that connects to a Mojo service to evaluate 32 // Implementation of ProxyResolver that connects to a Mojo service to evaluate
32 // PAC scripts. This implementation only knows about Mojo services, and 33 // PAC scripts. This implementation only knows about Mojo services, and
33 // therefore that service may live in or out of process. 34 // therefore that service may live in or out of process.
34 // 35 //
35 // This implementation handles disconnections from the Mojo service (i.e. if the 36 // This implementation reports disconnections from the Mojo service (i.e. if the
36 // service is out-of-process and that process crashes) and transparently 37 // service is out-of-process and that process crashes) using the error code
37 // re-connects to a new service. 38 // ERR_PAC_SCRIPT_TERMINATED.
38 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler { 39 class ProxyResolverMojo : public ProxyResolver, public mojo::ErrorHandler {
39 public: 40 public:
40 // Constructs a ProxyResolverMojo and connects to a new Mojo proxy resolver 41 // Constructs a ProxyResolverMojo connected to a Mojo proxy resolver service
41 // service using |mojo_proxy_resolver_factory|. The new Mojo proxy resolver 42 // using |mojo_proxy_resolver| that will delete |runner| when it is deleted.
eroman 2015/04/15 00:46:44 this comment is hard to parse
Sam McNally 2015/04/15 06:04:22 How about now?
42 // uses |host_resolver| as the DNS resolver. |mojo_proxy_resolver_factory|
43 // and |host_resolver| are not owned and must outlive this.
44 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog. 43 // TODO(amistry): Add ProxyResolverErrorObserver and NetLog.
45 ProxyResolverMojo(MojoProxyResolverFactory* mojo_proxy_resolver_factory, 44 ProxyResolverMojo(interfaces::ProxyResolverPtr mojo_proxy_resolver,
46 HostResolver* host_resolver); 45 scoped_ptr<base::ScopedClosureRunner> runner);
47 ~ProxyResolverMojo() override; 46 ~ProxyResolverMojo() override;
48 47
49 // ProxyResolver implementation: 48 // ProxyResolver implementation:
50 int GetProxyForURL(const GURL& url, 49 int GetProxyForURL(const GURL& url,
51 ProxyInfo* results, 50 ProxyInfo* results,
52 const net::CompletionCallback& callback, 51 const net::CompletionCallback& callback,
53 RequestHandle* request, 52 RequestHandle* request,
54 const BoundNetLog& net_log) override; 53 const BoundNetLog& net_log) override;
55 void CancelRequest(RequestHandle request) override; 54 void CancelRequest(RequestHandle request) override;
56 LoadState GetLoadState(RequestHandle request) const override; 55 LoadState GetLoadState(RequestHandle request) const override;
57 void CancelSetPacScript() override; 56 void CancelSetPacScript() override;
58 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script, 57 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& pac_script,
59 const net::CompletionCallback& callback) override; 58 const net::CompletionCallback& callback) override;
60 59
61 private: 60 private:
62 class Job; 61 class Job;
63 62
64 // Overridden from mojo::ErrorHandler: 63 // Overridden from mojo::ErrorHandler:
65 void OnConnectionError() override; 64 void OnConnectionError() override;
66 65
67 // Callback for ProxyResolverService::SetPacScript. 66 // Callback for ProxyResolverService::SetPacScript.
68 void OnSetPacScriptDone( 67 void OnSetPacScriptDone(
69 const scoped_refptr<ProxyResolverScriptData>& pac_script, 68 const scoped_refptr<ProxyResolverScriptData>& pac_script,
70 const net::CompletionCallback& callback, 69 const net::CompletionCallback& callback,
71 int32_t result); 70 int32_t result);
72 71
73 void SetUpServices();
74
75 void AbortPendingRequests(); 72 void AbortPendingRequests();
76 73
77 void RemoveJob(Job* job); 74 void RemoveJob(Job* job);
78 75
79 // Connection to the Mojo proxy resolver. 76 // Connection to the Mojo proxy resolver.
80 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; 77 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_;
81 78
82 // Mojo host resolver service and binding.
83 scoped_ptr<interfaces::HostResolver> mojo_host_resolver_;
84 scoped_ptr<mojo::Binding<interfaces::HostResolver>>
85 mojo_host_resolver_binding_;
86
87 // Factory for connecting to new Mojo proxy resolvers.
88 // Not owned.
89 MojoProxyResolverFactory* mojo_proxy_resolver_factory_;
90
91 // DNS resolver, saved for creating a new Mojo proxy resolver when the
92 // existing one disconnects (i.e. when utility process crashes).
93 HostResolver* host_resolver_;
94
95 std::set<Job*> pending_jobs_; 79 std::set<Job*> pending_jobs_;
96 net::CancelableCompletionCallback set_pac_script_callback_; 80 net::CancelableCompletionCallback set_pac_script_callback_;
97 81
98 base::ThreadChecker thread_checker_; 82 base::ThreadChecker thread_checker_;
99 83
84 scoped_ptr<base::ScopedClosureRunner> runner_;
85
100 base::WeakPtrFactory<ProxyResolverMojo> weak_factory_; 86 base::WeakPtrFactory<ProxyResolverMojo> weak_factory_;
101 87
102 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); 88 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
103 }; 89 };
104 90
105 } // namespace net 91 } // namespace net
106 92
107 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_ 93 #endif // NET_PROXY_PROXY_RESOLVER_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698