Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / net / utility_process_mojo_proxy_resolver_factory.h
blob6bbc1ca905c701f37d9e134b6c7c1ad423ad9638
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 CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_
6 #define CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_
8 #include "base/macros.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"
14 namespace content {
15 class UtilityProcessHost;
17 namespace base {
18 template <typename Type>
19 struct DefaultSingletonTraits;
20 } // namespace base
22 // A factory used to create connections to Mojo proxy resolver services run in a
23 // utility process. All Mojo proxy resolver services will be run in the same
24 // utility process. Utility process crashes are detected and the utility
25 // process is automatically restarted.
26 class UtilityProcessMojoProxyResolverFactory
27 : public net::MojoProxyResolverFactory {
28 public:
29 static UtilityProcessMojoProxyResolverFactory* GetInstance();
31 // Overridden from net::MojoProxyResolverFactory:
32 scoped_ptr<base::ScopedClosureRunner> CreateResolver(
33 const mojo::String& pac_script,
34 mojo::InterfaceRequest<net::interfaces::ProxyResolver> req,
35 net::interfaces::ProxyResolverFactoryRequestClientPtr client) override;
37 private:
38 friend struct base::DefaultSingletonTraits<
39 UtilityProcessMojoProxyResolverFactory>;
40 UtilityProcessMojoProxyResolverFactory();
41 ~UtilityProcessMojoProxyResolverFactory() override;
43 // Error handler callback for |resolver_factory_|.
44 void OnConnectionError();
46 // Invoked each time a proxy resolver is destroyed.
47 void OnResolverDestroyed();
49 // Invoked once an idle timeout has elapsed after all proxy resolvers are
50 // destroyed.
51 void OnIdleTimeout();
53 // Creates a new utility process and connects to its Mojo proxy resolver
54 // factory.
55 void CreateProcessAndConnect();
57 net::interfaces::ProxyResolverFactoryPtr resolver_factory_;
59 base::WeakPtr<content::UtilityProcessHost> weak_utility_process_host_;
60 size_t num_proxy_resolvers_ = 0;
62 base::OneShotTimer<UtilityProcessMojoProxyResolverFactory> idle_timer_;
64 base::ThreadChecker thread_checker_;
66 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoProxyResolverFactory);
69 #endif // CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_