OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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/time/time.h" | 16 #include "base/time/time.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "extensions/common/view_type.h" | 19 #include "extensions/common/view_type.h" |
20 | 20 |
21 class Browser; | |
22 class GURL; | 21 class GURL; |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 class BrowserContext; | 24 class BrowserContext; |
26 class DevToolsAgentHost; | 25 class DevToolsAgentHost; |
27 class RenderViewHost; | 26 class RenderViewHost; |
28 class SiteInstance; | 27 class SiteInstance; |
29 }; | 28 }; |
30 | 29 |
31 namespace extensions { | 30 namespace extensions { |
(...skipping 12 matching lines...) Expand all Loading... | |
44 static ExtensionProcessManager* Create(content::BrowserContext* context); | 43 static ExtensionProcessManager* Create(content::BrowserContext* context); |
45 virtual ~ExtensionProcessManager(); | 44 virtual ~ExtensionProcessManager(); |
46 | 45 |
47 const ExtensionHostSet& background_hosts() const { | 46 const ExtensionHostSet& background_hosts() const { |
48 return background_hosts_; | 47 return background_hosts_; |
49 } | 48 } |
50 | 49 |
51 typedef std::set<content::RenderViewHost*> ViewSet; | 50 typedef std::set<content::RenderViewHost*> ViewSet; |
52 const ViewSet GetAllViews() const; | 51 const ViewSet GetAllViews() const; |
53 | 52 |
54 // Creates a new ExtensionHost with its associated view, grouping it in the | |
55 // appropriate SiteInstance (and therefore process) based on the URL and | |
56 // profile. | |
57 virtual extensions::ExtensionHost* CreateViewHost( | |
58 const extensions::Extension* extension, | |
59 const GURL& url, | |
60 Browser* browser, | |
61 extensions::ViewType view_type); | |
62 extensions::ExtensionHost* CreateViewHost(const GURL& url, | |
63 Browser* browser, | |
64 extensions::ViewType view_type); | |
65 extensions::ExtensionHost* CreatePopupHost( | |
66 const extensions::Extension* extension, | |
67 const GURL& url, | |
68 Browser* browser); | |
69 extensions::ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser); | |
70 extensions::ExtensionHost* CreateDialogHost(const GURL& url); | |
71 extensions::ExtensionHost* CreateInfobarHost( | |
72 const extensions::Extension* extension, | |
73 const GURL& url, | |
74 Browser* browser); | |
75 extensions::ExtensionHost* CreateInfobarHost(const GURL& url, | |
76 Browser* browser); | |
77 | |
78 // Creates a new UI-less extension instance. Like CreateViewHost, but not | 53 // Creates a new UI-less extension instance. Like CreateViewHost, but not |
79 // displayed anywhere. | 54 // displayed anywhere. |
80 virtual extensions::ExtensionHost* CreateBackgroundHost( | 55 virtual extensions::ExtensionHost* CreateBackgroundHost( |
81 const extensions::Extension* extension, | 56 const extensions::Extension* extension, |
82 const GURL& url); | 57 const GURL& url); |
83 | 58 |
84 // Gets the ExtensionHost for the background page for an extension, or NULL if | 59 // Gets the ExtensionHost for the background page for an extension, or NULL if |
85 // the extension isn't running or doesn't have a background page. | 60 // the extension isn't running or doesn't have a background page. |
86 extensions::ExtensionHost* GetBackgroundHostForExtension( | 61 extensions::ExtensionHost* GetBackgroundHostForExtension( |
87 const std::string& extension_id); | 62 const std::string& extension_id); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 void CancelSuspend(const extensions::Extension* extension); | 111 void CancelSuspend(const extensions::Extension* extension); |
137 | 112 |
138 // If |defer| is true background host creation is to be deferred until this is | 113 // If |defer| is true background host creation is to be deferred until this is |
139 // called again with |defer| set to false, at which point all deferred | 114 // called again with |defer| set to false, at which point all deferred |
140 // background hosts will be created. Defaults to false. | 115 // background hosts will be created. Defaults to false. |
141 void DeferBackgroundHostCreation(bool defer); | 116 void DeferBackgroundHostCreation(bool defer); |
142 | 117 |
143 // Ensures background hosts are loaded for a new browser window. | 118 // Ensures background hosts are loaded for a new browser window. |
144 void OnBrowserWindowReady(); | 119 void OnBrowserWindowReady(); |
145 | 120 |
121 // Called just after |host| is created so it can be registered in our lists. | |
122 void OnExtensionHostCreated(extensions::ExtensionHost* host); | |
Yoyo Zhou
2013/11/06 19:08:07
Can you rename this to OnBackgroundHostCreated and
| |
123 | |
146 // Gets the BrowserContext associated with site_instance_ and all other | 124 // Gets the BrowserContext associated with site_instance_ and all other |
147 // related SiteInstances. | 125 // related SiteInstances. |
148 content::BrowserContext* GetBrowserContext() const; | 126 content::BrowserContext* GetBrowserContext() const; |
149 | 127 |
150 protected: | 128 protected: |
151 // If |context| is incognito pass the master context as |original_context|. | 129 // If |context| is incognito pass the master context as |original_context|. |
152 // Otherwise pass the same context for both. | 130 // Otherwise pass the same context for both. |
153 ExtensionProcessManager(content::BrowserContext* context, | 131 ExtensionProcessManager(content::BrowserContext* context, |
154 content::BrowserContext* original_context); | 132 content::BrowserContext* original_context); |
155 | 133 |
156 // Called just after |host| is created so it can be registered in our lists. | |
157 void OnExtensionHostCreated(extensions::ExtensionHost* host, | |
158 bool is_background); | |
159 | |
160 // Called on browser shutdown to close our extension hosts. | 134 // Called on browser shutdown to close our extension hosts. |
161 void CloseBackgroundHosts(); | 135 void CloseBackgroundHosts(); |
162 | 136 |
163 // content::NotificationObserver: | 137 // content::NotificationObserver: |
164 virtual void Observe(int type, | 138 virtual void Observe(int type, |
165 const content::NotificationSource& source, | 139 const content::NotificationSource& source, |
166 const content::NotificationDetails& details) OVERRIDE; | 140 const content::NotificationDetails& details) OVERRIDE; |
167 | 141 |
168 // Load all background pages once the profile data is ready and the pages | 142 // Load all background pages once the profile data is ready and the pages |
169 // should be loaded. | 143 // should be loaded. |
(...skipping 15 matching lines...) Expand all Loading... | |
185 // Extra information we keep for each extension's background page. | 159 // Extra information we keep for each extension's background page. |
186 struct BackgroundPageData; | 160 struct BackgroundPageData; |
187 typedef std::string ExtensionId; | 161 typedef std::string ExtensionId; |
188 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; | 162 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; |
189 typedef std::map<content::RenderViewHost*, | 163 typedef std::map<content::RenderViewHost*, |
190 extensions::ViewType> ExtensionRenderViews; | 164 extensions::ViewType> ExtensionRenderViews; |
191 | 165 |
192 // Close the given |host| iff it's a background page. | 166 // Close the given |host| iff it's a background page. |
193 void CloseBackgroundHost(extensions::ExtensionHost* host); | 167 void CloseBackgroundHost(extensions::ExtensionHost* host); |
194 | 168 |
195 // Ensure browser object is not null except for certain situations. | |
196 void EnsureBrowserWhenRequired(Browser* browser, | |
197 extensions::ViewType view_type); | |
198 | |
199 // These are called when the extension transitions between idle and active. | 169 // These are called when the extension transitions between idle and active. |
200 // They control the process of closing the background page when idle. | 170 // They control the process of closing the background page when idle. |
201 void OnLazyBackgroundPageIdle(const std::string& extension_id, | 171 void OnLazyBackgroundPageIdle(const std::string& extension_id, |
202 int sequence_id); | 172 int sequence_id); |
203 void OnLazyBackgroundPageActive(const std::string& extension_id); | 173 void OnLazyBackgroundPageActive(const std::string& extension_id); |
204 void CloseLazyBackgroundPageNow(const std::string& extension_id, | 174 void CloseLazyBackgroundPageNow(const std::string& extension_id, |
205 int sequence_id); | 175 int sequence_id); |
206 | 176 |
207 // Potentially registers a RenderViewHost, if it is associated with an | 177 // Potentially registers a RenderViewHost, if it is associated with an |
208 // extension. Does nothing if this is not an extension renderer. | 178 // extension. Does nothing if this is not an extension renderer. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 bool startup_background_hosts_created_; | 212 bool startup_background_hosts_created_; |
243 | 213 |
244 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 214 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
245 | 215 |
246 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; | 216 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; |
247 | 217 |
248 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 218 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
249 }; | 219 }; |
250 | 220 |
251 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 221 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
OLD | NEW |