Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / renderer_startup_helper.h
blob5ae1635f921de0a4ea73b01794fb8f8509edeee7
1 // Copyright 2014 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 EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_
6 #define EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/singleton.h"
10 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
15 namespace content {
16 class BrowserContext;
17 class RenderProcessHost;
20 namespace extensions {
22 // Informs renderers about extensions-related data (loaded extensions, available
23 // functions, etc.) when they start. Sends this information to both extension
24 // and non-extension renderers, as the non-extension renderers may have content
25 // scripts. Lives on the UI thread. Shared between incognito and non-incognito
26 // browser contexts.
27 class RendererStartupHelper : public KeyedService,
28 public content::NotificationObserver {
29 public:
30 // This class sends messages to all renderers started for |browser_context|.
31 explicit RendererStartupHelper(content::BrowserContext* browser_context);
32 ~RendererStartupHelper() override;
34 // content::NotificationObserver overrides:
35 void Observe(int type,
36 const content::NotificationSource& source,
37 const content::NotificationDetails& details) override;
39 private:
40 content::BrowserContext* browser_context_; // Not owned.
42 content::NotificationRegistrar registrar_;
44 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelper);
47 // Factory for RendererStartupHelpers. Declared here because this header is
48 // rarely included and it's probably cheaper to put it here than to make the
49 // compiler generate another object file.
50 class RendererStartupHelperFactory : public BrowserContextKeyedServiceFactory {
51 public:
52 static RendererStartupHelper* GetForBrowserContext(
53 content::BrowserContext* context);
54 static RendererStartupHelperFactory* GetInstance();
56 private:
57 friend struct DefaultSingletonTraits<RendererStartupHelperFactory>;
59 RendererStartupHelperFactory();
60 ~RendererStartupHelperFactory() override;
62 // BrowserContextKeyedServiceFactory implementation:
63 KeyedService* BuildServiceInstanceFor(
64 content::BrowserContext* profile) const override;
65 content::BrowserContext* GetBrowserContextToUse(
66 content::BrowserContext* context) const override;
67 bool ServiceIsCreatedWithBrowserContext() const override;
69 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelperFactory);
72 } // namespace extensions
74 #endif // EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_