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