| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 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.h" | 16 #include "base/time.h" |
| 17 #include "content/public/common/view_type.h" | 17 #include "content/public/common/view_type.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 | 20 |
| 21 class Browser; | 21 class Browser; |
| 22 class Extension; | |
| 23 class ExtensionHost; | 22 class ExtensionHost; |
| 24 class GURL; | 23 class GURL; |
| 25 class Profile; | 24 class Profile; |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 class RenderViewHost; | 27 class RenderViewHost; |
| 29 class SiteInstance; | 28 class SiteInstance; |
| 30 }; | 29 }; |
| 31 | 30 |
| 31 namespace extensions { |
| 32 class Extension; |
| 33 } |
| 34 |
| 32 // Manages dynamic state of running Chromium extensions. There is one instance | 35 // Manages dynamic state of running Chromium extensions. There is one instance |
| 33 // of this class per Profile. OTR Profiles have a separate instance that keeps | 36 // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 34 // track of split-mode extensions only. | 37 // track of split-mode extensions only. |
| 35 class ExtensionProcessManager : public content::NotificationObserver { | 38 class ExtensionProcessManager : public content::NotificationObserver { |
| 36 public: | 39 public: |
| 37 typedef std::set<ExtensionHost*> ExtensionHostSet; | 40 typedef std::set<ExtensionHost*> ExtensionHostSet; |
| 38 typedef ExtensionHostSet::const_iterator const_iterator; | 41 typedef ExtensionHostSet::const_iterator const_iterator; |
| 39 | 42 |
| 40 static ExtensionProcessManager* Create(Profile* profile); | 43 static ExtensionProcessManager* Create(Profile* profile); |
| 41 virtual ~ExtensionProcessManager(); | 44 virtual ~ExtensionProcessManager(); |
| 42 | 45 |
| 43 const ExtensionHostSet& background_hosts() const { | 46 const ExtensionHostSet& background_hosts() const { |
| 44 return background_hosts_; | 47 return background_hosts_; |
| 45 } | 48 } |
| 46 | 49 |
| 47 typedef std::set<content::RenderViewHost*> ViewSet; | 50 typedef std::set<content::RenderViewHost*> ViewSet; |
| 48 const ViewSet GetAllViews() const; | 51 const ViewSet GetAllViews() const; |
| 49 | 52 |
| 50 // Creates a new ExtensionHost with its associated view, grouping it in the | 53 // Creates a new ExtensionHost with its associated view, grouping it in the |
| 51 // appropriate SiteInstance (and therefore process) based on the URL and | 54 // appropriate SiteInstance (and therefore process) based on the URL and |
| 52 // profile. | 55 // profile. |
| 53 virtual ExtensionHost* CreateViewHost(const Extension* extension, | 56 virtual ExtensionHost* CreateViewHost(const extensions::Extension* extension, |
| 54 const GURL& url, | 57 const GURL& url, |
| 55 Browser* browser, | 58 Browser* browser, |
| 56 content::ViewType view_type); | 59 content::ViewType view_type); |
| 57 ExtensionHost* CreateViewHost(const GURL& url, | 60 ExtensionHost* CreateViewHost(const GURL& url, |
| 58 Browser* browser, | 61 Browser* browser, |
| 59 content::ViewType view_type); | 62 content::ViewType view_type); |
| 60 ExtensionHost* CreatePopupHost(const Extension* extension, | 63 ExtensionHost* CreatePopupHost(const extensions::Extension* extension, |
| 61 const GURL& url, | 64 const GURL& url, |
| 62 Browser* browser); | 65 Browser* browser); |
| 63 ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser); | 66 ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser); |
| 64 ExtensionHost* CreateDialogHost(const GURL& url, Browser* browser); | 67 ExtensionHost* CreateDialogHost(const GURL& url, Browser* browser); |
| 65 ExtensionHost* CreateInfobarHost(const Extension* extension, | 68 ExtensionHost* CreateInfobarHost(const extensions::Extension* extension, |
| 66 const GURL& url, | 69 const GURL& url, |
| 67 Browser* browser); | 70 Browser* browser); |
| 68 ExtensionHost* CreateInfobarHost(const GURL& url, | 71 ExtensionHost* CreateInfobarHost(const GURL& url, |
| 69 Browser* browser); | 72 Browser* browser); |
| 70 | 73 |
| 71 // Open the extension's options page. | 74 // Open the extension's options page. |
| 72 void OpenOptionsPage(const Extension* extension, Browser* browser); | 75 void OpenOptionsPage(const extensions::Extension* extension, |
| 76 Browser* browser); |
| 73 | 77 |
| 74 // Creates a new UI-less extension instance. Like CreateViewHost, but not | 78 // Creates a new UI-less extension instance. Like CreateViewHost, but not |
| 75 // displayed anywhere. | 79 // displayed anywhere. |
| 76 virtual void CreateBackgroundHost(const Extension* extension, | 80 virtual void CreateBackgroundHost(const extensions::Extension* extension, |
| 77 const GURL& url); | 81 const GURL& url); |
| 78 | 82 |
| 79 // Gets the ExtensionHost for the background page for an extension, or NULL if | 83 // Gets the ExtensionHost for the background page for an extension, or NULL if |
| 80 // the extension isn't running or doesn't have a background page. | 84 // the extension isn't running or doesn't have a background page. |
| 81 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); | 85 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); |
| 82 | 86 |
| 83 // Returns the SiteInstance that the given URL belongs to. | 87 // Returns the SiteInstance that the given URL belongs to. |
| 84 // TODO(aa): This only returns correct results for extensions and packaged | 88 // TODO(aa): This only returns correct results for extensions and packaged |
| 85 // apps, not hosted apps. | 89 // apps, not hosted apps. |
| 86 virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url); | 90 virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url); |
| 87 | 91 |
| 88 // Registers a RenderViewHost as hosting a given extension. | 92 // Registers a RenderViewHost as hosting a given extension. |
| 89 void RegisterRenderViewHost(content::RenderViewHost* render_view_host, | 93 void RegisterRenderViewHost(content::RenderViewHost* render_view_host, |
| 90 const Extension* extension); | 94 const extensions::Extension* extension); |
| 91 | 95 |
| 92 // Unregisters a RenderViewHost as hosting any extension. | 96 // Unregisters a RenderViewHost as hosting any extension. |
| 93 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); | 97 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); |
| 94 | 98 |
| 95 // Returns all RenderViewHosts that are registered for the specified | 99 // Returns all RenderViewHosts that are registered for the specified |
| 96 // extension. | 100 // extension. |
| 97 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( | 101 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( |
| 98 const std::string& extension_id); | 102 const std::string& extension_id); |
| 99 | 103 |
| 100 // Returns the extension associated with the specified RenderViewHost, or | 104 // Returns the extension associated with the specified RenderViewHost, or |
| 101 // NULL. | 105 // NULL. |
| 102 const Extension* GetExtensionForRenderViewHost( | 106 const extensions::Extension* GetExtensionForRenderViewHost( |
| 103 content::RenderViewHost* render_view_host); | 107 content::RenderViewHost* render_view_host); |
| 104 | 108 |
| 105 // Returns true if the (lazy) background host for the given extension has | 109 // Returns true if the (lazy) background host for the given extension has |
| 106 // already been sent the unload event and is shutting down. | 110 // already been sent the unload event and is shutting down. |
| 107 bool IsBackgroundHostClosing(const std::string& extension_id); | 111 bool IsBackgroundHostClosing(const std::string& extension_id); |
| 108 | 112 |
| 109 // Getter and setter for the lazy background page's keepalive count. This is | 113 // Getter and setter for the lazy background page's keepalive count. This is |
| 110 // the count of how many outstanding "things" are keeping the page alive. | 114 // the count of how many outstanding "things" are keeping the page alive. |
| 111 // When this reaches 0, we will begin the process of shutting down the page. | 115 // When this reaches 0, we will begin the process of shutting down the page. |
| 112 // "Things" include pending events, resource loads, and API calls. | 116 // "Things" include pending events, resource loads, and API calls. |
| 113 int GetLazyKeepaliveCount(const Extension* extension); | 117 int GetLazyKeepaliveCount(const extensions::Extension* extension); |
| 114 int IncrementLazyKeepaliveCount(const Extension* extension); | 118 int IncrementLazyKeepaliveCount(const extensions::Extension* extension); |
| 115 int DecrementLazyKeepaliveCount(const Extension* extension); | 119 int DecrementLazyKeepaliveCount(const extensions::Extension* extension); |
| 116 | 120 |
| 117 void IncrementLazyKeepaliveCountForView( | 121 void IncrementLazyKeepaliveCountForView( |
| 118 content::RenderViewHost* render_view_host); | 122 content::RenderViewHost* render_view_host); |
| 119 | 123 |
| 120 // Handles a response to the ShouldUnload message, used for lazy background | 124 // Handles a response to the ShouldUnload message, used for lazy background |
| 121 // pages. | 125 // pages. |
| 122 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); | 126 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); |
| 123 | 127 |
| 124 // Same as above, for the Unload message. | 128 // Same as above, for the Unload message. |
| 125 void OnUnloadAck(const std::string& extension_id); | 129 void OnUnloadAck(const std::string& extension_id); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // The time to delay between sending a ShouldUnload message and | 205 // The time to delay between sending a ShouldUnload message and |
| 202 // sending a Unload message; read from command-line switch. | 206 // sending a Unload message; read from command-line switch. |
| 203 base::TimeDelta event_page_unloading_time_; | 207 base::TimeDelta event_page_unloading_time_; |
| 204 | 208 |
| 205 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; | 209 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; |
| 206 | 210 |
| 207 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 211 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
| 208 }; | 212 }; |
| 209 | 213 |
| 210 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 214 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| OLD | NEW |