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