Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / net / utility_process_mojo_proxy_resolver_factory.h
blobd4223aa4e14d10f8d2fd2c6abb79154d2055e0b0
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;
18 template <typename Type>
19 struct DefaultSingletonTraits;
21 // A factory used to create connections to Mojo proxy resolver services run in a
22 // utility process. All Mojo proxy resolver services will be run in the same
23 // utility process. Utility process crashes are detected and the utility
24 // process is automatically restarted.
25 class UtilityProcessMojoProxyResolverFactory
26 : public net::MojoProxyResolverFactory {
27 public:
28 static UtilityProcessMojoProxyResolverFactory* GetInstance();
30 // Overridden from net::MojoProxyResolverFactory:
31 scoped_ptr<base::ScopedClosureRunner> CreateResolver(
32 const mojo::String& pac_script,
33 mojo::InterfaceRequest<net::interfaces::ProxyResolver> req,
34 net::interfaces::ProxyResolverFactoryRequestClientPtr client) override;
36 private:
37 friend struct DefaultSingletonTraits<UtilityProcessMojoProxyResolverFactory>;
38 UtilityProcessMojoProxyResolverFactory();
39 ~UtilityProcessMojoProxyResolverFactory() override;
41 // Error handler callback for |resolver_factory_|.
42 void OnConnectionError();
44 // Invoked each time a proxy resolver is destroyed.
45 void OnResolverDestroyed();
47 // Invoked once an idle timeout has elapsed after all proxy resolvers are
48 // destroyed.
49 void OnIdleTimeout();
51 // Creates a new utility process and connects to its Mojo proxy resolver
52 // factory.
53 void CreateProcessAndConnect();
55 net::interfaces::ProxyResolverFactoryPtr resolver_factory_;
57 base::WeakPtr<content::UtilityProcessHost> weak_utility_process_host_;
58 size_t num_proxy_resolvers_ = 0;
60 base::OneShotTimer<UtilityProcessMojoProxyResolverFactory> idle_timer_;
62 base::ThreadChecker thread_checker_;
64 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoProxyResolverFactory);
67 #endif // CHROME_BROWSER_NET_UTILITY_PROCESS_MOJO_PROXY_RESOLVER_FACTORY_H_