OLD | NEW |
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 CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ |
6 #define CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ | 6 #define CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/timer/timer.h" |
9 #include "net/proxy/mojo_proxy_resolver_factory.h" | 11 #include "net/proxy/mojo_proxy_resolver_factory.h" |
10 | 12 |
| 13 namespace content { |
| 14 class UtilityProcessHost; |
| 15 } |
| 16 |
11 template <typename Type> | 17 template <typename Type> |
12 struct DefaultSingletonTraits; | 18 struct DefaultSingletonTraits; |
13 | 19 |
14 // A factory used to create connections to Mojo proxy resolver services run in a | 20 // A factory used to create connections to Mojo proxy resolver services run in a |
15 // utility process. All Mojo proxy resolver services will be run in the same | 21 // utility process. All Mojo proxy resolver services will be run in the same |
16 // utility process. Utility process crashes are detected and the utility | 22 // utility process. Utility process crashes are detected and the utility |
17 // process is automatically restarted. | 23 // process is automatically restarted. |
18 class UtilityProcessMojoProxyResolverFactory | 24 class UtilityProcessMojoProxyResolverFactory |
19 : public net::MojoProxyResolverFactory, | 25 : public net::MojoProxyResolverFactory, |
20 public mojo::ErrorHandler { | 26 public mojo::ErrorHandler { |
21 public: | 27 public: |
22 static UtilityProcessMojoProxyResolverFactory* GetInstance(); | 28 static UtilityProcessMojoProxyResolverFactory* GetInstance(); |
23 | 29 |
24 // Overridden from net::MojoProxyResolverFactory: | 30 // Overridden from net::MojoProxyResolverFactory: |
25 void Create(mojo::InterfaceRequest<net::interfaces::ProxyResolver> req, | 31 scoped_ptr<base::ScopedClosureRunner> Create( |
26 net::interfaces::HostResolverPtr host_resolver) override; | 32 mojo::InterfaceRequest<net::interfaces::ProxyResolver> req, |
| 33 net::interfaces::HostResolverPtr host_resolver) override; |
27 | 34 |
28 private: | 35 private: |
29 friend struct DefaultSingletonTraits<UtilityProcessMojoProxyResolverFactory>; | 36 friend struct DefaultSingletonTraits<UtilityProcessMojoProxyResolverFactory>; |
30 UtilityProcessMojoProxyResolverFactory(); | 37 UtilityProcessMojoProxyResolverFactory(); |
31 ~UtilityProcessMojoProxyResolverFactory() override; | 38 ~UtilityProcessMojoProxyResolverFactory() override; |
32 | 39 |
33 // Overridden from mojo::ErrorHandler: | 40 // Overridden from mojo::ErrorHandler: |
34 void OnConnectionError() override; | 41 void OnConnectionError() override; |
35 | 42 |
| 43 // Invoked each time a proxy resolver is destroyed. |
| 44 void OnResolverDestroyed(); |
| 45 |
| 46 // Invoked once an idle timeout has elapsed after all proxy resolvers are |
| 47 // destroyed. |
| 48 void OnIdleTimeout(); |
| 49 |
36 // Creates a new utility process and connects to its Mojo proxy resolver | 50 // Creates a new utility process and connects to its Mojo proxy resolver |
37 // factory. | 51 // factory. |
38 void CreateProcessAndConnect(); | 52 void CreateProcessAndConnect(); |
39 | 53 |
40 net::interfaces::ProxyResolverFactoryPtr resolver_factory_; | 54 net::interfaces::ProxyResolverFactoryPtr resolver_factory_; |
41 | 55 |
| 56 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 57 size_t num_proxy_resolvers_ = 0; |
| 58 |
| 59 base::OneShotTimer<UtilityProcessMojoProxyResolverFactory> idle_timer_; |
| 60 |
42 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoProxyResolverFactory); | 61 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoProxyResolverFactory); |
43 }; | 62 }; |
44 | 63 |
45 #endif // CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ | 64 #endif // CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_ |
OLD | NEW |