OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ | 5 #ifndef EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ |
6 #define EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ | 6 #define EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ |
7 | 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 |
8 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 12 #include "base/macros.h" |
10 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
11 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 14 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
13 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/common/extension_id.h" |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 class BrowserContext; | 21 class BrowserContext; |
18 class RenderProcessHost; | 22 class RenderProcessHost; |
19 } | 23 } |
20 | 24 |
21 namespace extensions { | 25 namespace extensions { |
| 26 class Extension; |
22 | 27 |
23 // Informs renderers about extensions-related data (loaded extensions, available | 28 // Informs renderers about extensions-related data (loaded extensions, available |
24 // functions, etc.) when they start. Sends this information to both extension | 29 // functions, etc.) when they start. Sends this information to both extension |
25 // and non-extension renderers, as the non-extension renderers may have content | 30 // and non-extension renderers, as the non-extension renderers may have content |
26 // scripts. Lives on the UI thread. Shared between incognito and non-incognito | 31 // scripts. Lives on the UI thread. Shared between incognito and non-incognito |
27 // browser contexts. | 32 // browser contexts. Also handles sending the loaded, unloaded, and activated |
| 33 // extension messages, since these can *only* be sent once the process is |
| 34 // initialized. |
| 35 // TODO(devlin): "StartupHelper" is no longer sufficient to describe the entire |
| 36 // behavior of this class. |
28 class RendererStartupHelper : public KeyedService, | 37 class RendererStartupHelper : public KeyedService, |
29 public content::NotificationObserver { | 38 public content::NotificationObserver { |
30 public: | 39 public: |
31 // This class sends messages to all renderers started for |browser_context|. | 40 // This class sends messages to all renderers started for |browser_context|. |
32 explicit RendererStartupHelper(content::BrowserContext* browser_context); | 41 explicit RendererStartupHelper(content::BrowserContext* browser_context); |
33 ~RendererStartupHelper() override; | 42 ~RendererStartupHelper() override; |
34 | 43 |
35 // content::NotificationObserver overrides: | 44 // content::NotificationObserver overrides: |
36 void Observe(int type, | 45 void Observe(int type, |
37 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
38 const content::NotificationDetails& details) override; | 47 const content::NotificationDetails& details) override; |
39 | 48 |
| 49 // Sends a message to the specified |process| activating the given extension |
| 50 // once the process is initialized. |
| 51 void ActivateExtensionInProcess(const ExtensionId& id, |
| 52 content::RenderProcessHost* process); |
| 53 |
| 54 // Sends a message to all initialized processes to [un]load the given |
| 55 // extension. We have explicit calls for these (rather than using an |
| 56 // ExtensionRegistryObserver) because this needs to happen before other |
| 57 // initialization which might rely on the renderers being notified. |
| 58 void OnExtensionUnloaded(const ExtensionId& id); |
| 59 void OnExtensionLoaded(const Extension& extension); |
| 60 |
40 private: | 61 private: |
| 62 // Initializes the specified process, informing it of system state and loaded |
| 63 // extensions. |
| 64 void InitializeProcess(content::RenderProcessHost* process); |
| 65 |
| 66 // Untracks the given process. |
| 67 void UntrackProcess(content::RenderProcessHost* process); |
| 68 |
41 content::BrowserContext* browser_context_; // Not owned. | 69 content::BrowserContext* browser_context_; // Not owned. |
42 | 70 |
| 71 // The set of render processes that have had the initial batch of IPC messages |
| 72 // sent, including the set of loaded extensions. Further messages that |
| 73 // activate, load, or unload extensions should not be sent until after this |
| 74 // happens. |
| 75 std::set<content::RenderProcessHost*> initialized_processes_; |
| 76 |
| 77 // The set of ids for extensions that are active in a process that has not |
| 78 // been initialized. The activation message will be sent the process is |
| 79 // initialized. |
| 80 std::map<content::RenderProcessHost*, std::set<ExtensionId>> |
| 81 pending_active_extensions_; |
| 82 |
43 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
44 | 84 |
45 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelper); | 85 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelper); |
46 }; | 86 }; |
47 | 87 |
48 // Factory for RendererStartupHelpers. Declared here because this header is | 88 // Factory for RendererStartupHelpers. Declared here because this header is |
49 // rarely included and it's probably cheaper to put it here than to make the | 89 // rarely included and it's probably cheaper to put it here than to make the |
50 // compiler generate another object file. | 90 // compiler generate another object file. |
51 class RendererStartupHelperFactory : public BrowserContextKeyedServiceFactory { | 91 class RendererStartupHelperFactory : public BrowserContextKeyedServiceFactory { |
52 public: | 92 public: |
(...skipping 13 matching lines...) Expand all Loading... |
66 content::BrowserContext* GetBrowserContextToUse( | 106 content::BrowserContext* GetBrowserContextToUse( |
67 content::BrowserContext* context) const override; | 107 content::BrowserContext* context) const override; |
68 bool ServiceIsCreatedWithBrowserContext() const override; | 108 bool ServiceIsCreatedWithBrowserContext() const override; |
69 | 109 |
70 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelperFactory); | 110 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelperFactory); |
71 }; | 111 }; |
72 | 112 |
73 } // namespace extensions | 113 } // namespace extensions |
74 | 114 |
75 #endif // EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ | 115 #endif // EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ |
OLD | NEW |