OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_PROCESS_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "extensions/browser/event_page_tracker.h" |
20 #include "extensions/browser/extension_registry_observer.h" | 21 #include "extensions/browser/extension_registry_observer.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "extensions/common/view_type.h" | 23 #include "extensions/common/view_type.h" |
23 | 24 |
24 class GURL; | 25 class GURL; |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 class BrowserContext; | 28 class BrowserContext; |
28 class DevToolsAgentHost; | 29 class DevToolsAgentHost; |
29 class RenderFrameHost; | 30 class RenderFrameHost; |
30 class SiteInstance; | 31 class SiteInstance; |
31 class WebContents; | 32 class WebContents; |
32 }; | 33 }; |
33 | 34 |
34 namespace extensions { | 35 namespace extensions { |
35 | 36 |
36 class Extension; | 37 class Extension; |
37 class ExtensionHost; | 38 class ExtensionHost; |
38 class ExtensionRegistry; | 39 class ExtensionRegistry; |
39 class ProcessManagerObserver; | 40 class ProcessManagerObserver; |
40 | 41 |
41 // Manages dynamic state of running Chromium extensions. There is one instance | 42 // Manages dynamic state of running Chromium extensions. There is one instance |
42 // of this class per Profile. OTR Profiles have a separate instance that keeps | 43 // of this class per Profile. OTR Profiles have a separate instance that keeps |
43 // track of split-mode extensions only. | 44 // track of split-mode extensions only. |
44 class ProcessManager : public KeyedService, | 45 class ProcessManager : public KeyedService, |
45 public content::NotificationObserver, | 46 public content::NotificationObserver, |
46 public ExtensionRegistryObserver { | 47 public ExtensionRegistryObserver, |
| 48 public EventPageTracker { |
47 public: | 49 public: |
48 using ExtensionHostSet = std::set<extensions::ExtensionHost*>; | 50 using ExtensionHostSet = std::set<extensions::ExtensionHost*>; |
49 | 51 |
50 static ProcessManager* Get(content::BrowserContext* context); | 52 static ProcessManager* Get(content::BrowserContext* context); |
51 ~ProcessManager() override; | 53 ~ProcessManager() override; |
52 | 54 |
53 void RegisterRenderFrameHost(content::WebContents* web_contents, | 55 void RegisterRenderFrameHost(content::WebContents* web_contents, |
54 content::RenderFrameHost* render_frame_host, | 56 content::RenderFrameHost* render_frame_host, |
55 const Extension* extension); | 57 const Extension* extension); |
56 void UnregisterRenderFrameHost(content::RenderFrameHost* render_frame_host); | 58 void UnregisterRenderFrameHost(content::RenderFrameHost* render_frame_host); |
(...skipping 19 matching lines...) Expand all Loading... |
76 // displayed anywhere. Returns false if no background host can be created, | 78 // displayed anywhere. Returns false if no background host can be created, |
77 // for example for hosted apps and extensions that aren't enabled in | 79 // for example for hosted apps and extensions that aren't enabled in |
78 // Incognito. | 80 // Incognito. |
79 virtual bool CreateBackgroundHost(const Extension* extension, | 81 virtual bool CreateBackgroundHost(const Extension* extension, |
80 const GURL& url); | 82 const GURL& url); |
81 | 83 |
82 // Creates background hosts if the embedder is ready and they are not already | 84 // Creates background hosts if the embedder is ready and they are not already |
83 // loaded. | 85 // loaded. |
84 void MaybeCreateStartupBackgroundHosts(); | 86 void MaybeCreateStartupBackgroundHosts(); |
85 | 87 |
86 // Gets the ExtensionHost for the background page for an extension, or null if | |
87 // the extension isn't running or doesn't have a background page. | |
88 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); | |
89 | |
90 // Returns true if the (lazy) background host for the given extension has | 88 // Returns true if the (lazy) background host for the given extension has |
91 // already been sent the unload event and is shutting down. | 89 // already been sent the unload event and is shutting down. |
92 bool IsBackgroundHostClosing(const std::string& extension_id); | 90 bool IsBackgroundHostClosing(const std::string& extension_id); |
93 | 91 |
94 // Returns the extension associated with the specified RenderFrameHost/ | 92 // Returns the extension associated with the specified RenderFrameHost/ |
95 // WebContents, or null. | 93 // WebContents, or null. |
96 const Extension* GetExtensionForRenderFrameHost( | 94 const Extension* GetExtensionForRenderFrameHost( |
97 content::RenderFrameHost* render_frame_host); | 95 content::RenderFrameHost* render_frame_host); |
98 const Extension* GetExtensionForWebContents( | 96 const Extension* GetExtensionForWebContents( |
99 content::WebContents* web_contents); | 97 content::WebContents* web_contents); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 void CloseBackgroundHosts(); | 136 void CloseBackgroundHosts(); |
139 | 137 |
140 // Sets callbacks for testing keepalive impulse behavior. | 138 // Sets callbacks for testing keepalive impulse behavior. |
141 using ImpulseCallbackForTesting = | 139 using ImpulseCallbackForTesting = |
142 base::Callback<void(const std::string& extension_id)>; | 140 base::Callback<void(const std::string& extension_id)>; |
143 void SetKeepaliveImpulseCallbackForTesting( | 141 void SetKeepaliveImpulseCallbackForTesting( |
144 const ImpulseCallbackForTesting& callback); | 142 const ImpulseCallbackForTesting& callback); |
145 void SetKeepaliveImpulseDecrementCallbackForTesting( | 143 void SetKeepaliveImpulseDecrementCallbackForTesting( |
146 const ImpulseCallbackForTesting& callback); | 144 const ImpulseCallbackForTesting& callback); |
147 | 145 |
| 146 // EventPageTracker implementation. |
| 147 ExtensionHost* GetBackgroundHostForExtension( |
| 148 const std::string& extension_id) override; |
| 149 void WakeExtension(const std::string& extension_id, |
| 150 const base::Callback<void(bool)>& callback) override; |
| 151 |
148 // Sets the time in milliseconds that an extension event page can | 152 // Sets the time in milliseconds that an extension event page can |
149 // be idle before it is shut down; must be > 0. | 153 // be idle before it is shut down; must be > 0. |
150 static void SetEventPageIdleTimeForTesting(unsigned idle_time_msec); | 154 static void SetEventPageIdleTimeForTesting(unsigned idle_time_msec); |
151 | 155 |
152 // Sets the time in milliseconds that an extension event page has | 156 // Sets the time in milliseconds that an extension event page has |
153 // between being notified of its impending unload and that unload | 157 // between being notified of its impending unload and that unload |
154 // happening. | 158 // happening. |
155 static void SetEventPageSuspendingTimeForTesting( | 159 static void SetEventPageSuspendingTimeForTesting( |
156 unsigned suspending_time_msec); | 160 unsigned suspending_time_msec); |
157 | 161 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 308 |
305 // Must be last member, see doc on WeakPtrFactory. | 309 // Must be last member, see doc on WeakPtrFactory. |
306 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; | 310 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
307 | 311 |
308 DISALLOW_COPY_AND_ASSIGN(ProcessManager); | 312 DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
309 }; | 313 }; |
310 | 314 |
311 } // namespace extensions | 315 } // namespace extensions |
312 | 316 |
313 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 317 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
OLD | NEW |