1 // Copyright 2020 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.
4 
5 #ifndef WEBLAYER_BROWSER_NO_STATE_PREFETCH_PRERENDER_MANAGER_FACTORY_H_
6 #define WEBLAYER_BROWSER_NO_STATE_PREFETCH_PRERENDER_MANAGER_FACTORY_H_
7 
8 #include "base/memory/singleton.h"
9 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
10 
11 namespace content {
12 class BrowserContext;
13 }
14 
15 namespace prerender {
16 class PrerenderManager;
17 }
18 
19 namespace weblayer {
20 
21 // Singleton that owns all PrerenderManagers and associates them with
22 // BrowserContexts. Listens for the BrowserContext's destruction notification
23 // and cleans up the associated PrerenderManager.
24 class PrerenderManagerFactory : public BrowserContextKeyedServiceFactory {
25  public:
26   // Returns the PrerenderManager for |context|.
27   static prerender::PrerenderManager* GetForBrowserContext(
28       content::BrowserContext* context);
29 
30   static PrerenderManagerFactory* GetInstance();
31 
32  private:
33   friend struct base::DefaultSingletonTraits<PrerenderManagerFactory>;
34 
35   PrerenderManagerFactory();
36   ~PrerenderManagerFactory() override = default;
37 
38   // BrowserContextKeyedServiceFactory:
39   KeyedService* BuildServiceInstanceFor(
40       content::BrowserContext* browser) const override;
41   content::BrowserContext* GetBrowserContextToUse(
42       content::BrowserContext* context) const override;
43 };
44 
45 }  // namespace weblayer
46 
47 #endif  // WEBLAYER_BROWSER_NO_STATE_PREFETCH_PRERENDER_MANAGER_FACTORY_H_
48