Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: extensions/browser/renderer_startup_helper.h

Issue 2211213002: Revert of [Extensions] Ensure ordering of extension [un]loaded, activated messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
12 #include "base/macros.h" 9 #include "base/macros.h"
13 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
14 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" 11 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
15 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
16 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/common/extension_id.h"
19 15
20 namespace content { 16 namespace content {
21 class BrowserContext; 17 class BrowserContext;
22 class RenderProcessHost; 18 class RenderProcessHost;
23 } 19 }
24 20
25 namespace extensions { 21 namespace extensions {
26 class Extension;
27 22
28 // Informs renderers about extensions-related data (loaded extensions, available 23 // Informs renderers about extensions-related data (loaded extensions, available
29 // functions, etc.) when they start. Sends this information to both extension 24 // functions, etc.) when they start. Sends this information to both extension
30 // and non-extension renderers, as the non-extension renderers may have content 25 // 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 26 // scripts. Lives on the UI thread. Shared between incognito and non-incognito
32 // browser contexts. Also handles sending the loaded, unloaded, and activated 27 // browser contexts.
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.
37 class RendererStartupHelper : public KeyedService, 28 class RendererStartupHelper : public KeyedService,
38 public content::NotificationObserver { 29 public content::NotificationObserver {
39 public: 30 public:
40 // This class sends messages to all renderers started for |browser_context|. 31 // This class sends messages to all renderers started for |browser_context|.
41 explicit RendererStartupHelper(content::BrowserContext* browser_context); 32 explicit RendererStartupHelper(content::BrowserContext* browser_context);
42 ~RendererStartupHelper() override; 33 ~RendererStartupHelper() override;
43 34
44 // content::NotificationObserver overrides: 35 // content::NotificationObserver overrides:
45 void Observe(int type, 36 void Observe(int type,
46 const content::NotificationSource& source, 37 const content::NotificationSource& source,
47 const content::NotificationDetails& details) override; 38 const content::NotificationDetails& details) override;
48 39
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
61 private: 40 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
69 content::BrowserContext* browser_context_; // Not owned. 41 content::BrowserContext* browser_context_; // Not owned.
70 42
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
83 content::NotificationRegistrar registrar_; 43 content::NotificationRegistrar registrar_;
84 44
85 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelper); 45 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelper);
86 }; 46 };
87 47
88 // Factory for RendererStartupHelpers. Declared here because this header is 48 // 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 49 // rarely included and it's probably cheaper to put it here than to make the
90 // compiler generate another object file. 50 // compiler generate another object file.
91 class RendererStartupHelperFactory : public BrowserContextKeyedServiceFactory { 51 class RendererStartupHelperFactory : public BrowserContextKeyedServiceFactory {
92 public: 52 public:
(...skipping 13 matching lines...) Expand all
106 content::BrowserContext* GetBrowserContextToUse( 66 content::BrowserContext* GetBrowserContextToUse(
107 content::BrowserContext* context) const override; 67 content::BrowserContext* context) const override;
108 bool ServiceIsCreatedWithBrowserContext() const override; 68 bool ServiceIsCreatedWithBrowserContext() const override;
109 69
110 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelperFactory); 70 DISALLOW_COPY_AND_ASSIGN(RendererStartupHelperFactory);
111 }; 71 };
112 72
113 } // namespace extensions 73 } // namespace extensions
114 74
115 #endif // EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_ 75 #endif // EXTENSIONS_BROWSER_RENDERER_STARTUP_HELPER_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_web_contents_observer.cc ('k') | extensions/browser/renderer_startup_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698