[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 7 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 8 | #include <map> |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 9 | #include <set> |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 10 | #include <string> |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 11 | |
| 12 | #include "base/ref_counted.h" |
[email protected] | fc36895 | 2009-05-21 21:37:06 | [diff] [blame] | 13 | #include "chrome/common/notification_registrar.h" |
[email protected] | 2d8d923 | 2009-10-02 20:19:20 | [diff] [blame] | 14 | #include "chrome/common/view_types.h" |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 15 | |
| 16 | class Browser; |
| 17 | class BrowsingInstance; |
| 18 | class Extension; |
| 19 | class ExtensionHost; |
[email protected] | a4c36818 | 2009-05-29 21:53:27 | [diff] [blame] | 20 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 21 | class ExtensionView; |
[email protected] | 673aad7 | 2009-05-29 06:32:43 | [diff] [blame] | 22 | #endif |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 23 | class GURL; |
| 24 | class Profile; |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 25 | class RenderProcessHost; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 26 | class SiteInstance; |
| 27 | |
| 28 | // Manages dynamic state of running Chromium extensions. There is one instance |
| 29 | // of this class per Profile (including OTR). |
| 30 | class ExtensionProcessManager : public NotificationObserver { |
| 31 | public: |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 32 | explicit ExtensionProcessManager(Profile* profile); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 33 | ~ExtensionProcessManager(); |
| 34 | |
[email protected] | ab4eaf78 | 2009-06-10 00:11:24 | [diff] [blame] | 35 | // Creates a new ExtensionHost with its associated view, grouping it in the |
| 36 | // appropriate SiteInstance (and therefore process) based on the URL and |
| 37 | // profile. |
| 38 | ExtensionHost* CreateView(Extension* extension, |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 39 | const GURL& url, |
[email protected] | 2d8d923 | 2009-10-02 20:19:20 | [diff] [blame] | 40 | Browser* browser, |
| 41 | ViewType::Type view_type); |
| 42 | ExtensionHost* CreateView(const GURL& url, |
| 43 | Browser* browser, |
| 44 | ViewType::Type view_type); |
| 45 | ExtensionHost* CreateToolstrip(Extension* extension, |
| 46 | const GURL& url, |
| 47 | Browser* browser); |
| 48 | ExtensionHost* CreateToolstrip(const GURL& url, Browser* browser); |
| 49 | ExtensionHost* CreatePopup(Extension* extension, |
| 50 | const GURL& url, |
| 51 | Browser* browser); |
| 52 | ExtensionHost* CreatePopup(const GURL& url, Browser* browser); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 53 | |
| 54 | // Creates a new UI-less extension instance. Like CreateView, but not |
| 55 | // displayed anywhere. |
[email protected] | ab4eaf78 | 2009-06-10 00:11:24 | [diff] [blame] | 56 | ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 57 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 58 | // Gets the ExtensionHost for the background page for an extension, or NULL if |
| 59 | // the extension isn't running or doesn't have a background page. |
| 60 | ExtensionHost* GetBackgroundHostForExtension(Extension* extension); |
| 61 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 62 | // Returns the SiteInstance that the given URL belongs to. |
| 63 | SiteInstance* GetSiteInstanceForURL(const GURL& url); |
| 64 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 65 | // Registers an extension process by |extension_id| and specifying which |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 66 | // |process_id| it belongs to. |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 67 | void RegisterExtensionProcess(const std::string& extension_id, |
| 68 | int process_id); |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 69 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 70 | // Unregisters an extension process with specified |process_id|. |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 71 | void UnregisterExtensionProcess(int process_id); |
| 72 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 73 | // Returns the process that the extension with the given ID is running in. |
| 74 | RenderProcessHost* GetExtensionProcess(const std::string& extension_id); |
| 75 | |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame^] | 76 | // Returns true if |host| is managed by this process manager. |
| 77 | bool HasExtensionHost(ExtensionHost* host) const; |
| 78 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 79 | // NotificationObserver: |
| 80 | virtual void Observe(NotificationType type, |
| 81 | const NotificationSource& source, |
| 82 | const NotificationDetails& details); |
| 83 | |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 84 | typedef std::set<ExtensionHost*> ExtensionHostSet; |
| 85 | typedef ExtensionHostSet::const_iterator const_iterator; |
| 86 | const_iterator begin() const { return all_hosts_.begin(); } |
| 87 | const_iterator end() const { return all_hosts_.end(); } |
[email protected] | fc36895 | 2009-05-21 21:37:06 | [diff] [blame] | 88 | |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 89 | private: |
[email protected] | 94fe52e | 2009-06-13 10:09:06 | [diff] [blame] | 90 | // Called just after |host| is created so it can be registered in our lists. |
| 91 | void OnExtensionHostCreated(ExtensionHost* host, bool is_background); |
| 92 | |
[email protected] | ae5497f | 2009-11-05 00:39:46 | [diff] [blame] | 93 | // Called on browser shutdown to close our extension hosts. |
| 94 | void CloseBackgroundHosts(); |
| 95 | |
[email protected] | fc36895 | 2009-05-21 21:37:06 | [diff] [blame] | 96 | NotificationRegistrar registrar_; |
| 97 | |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 98 | // The set of all ExtensionHosts managed by this process manager. |
| 99 | ExtensionHostSet all_hosts_; |
| 100 | |
| 101 | // The set of running viewless background extensions. |
| 102 | ExtensionHostSet background_hosts_; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 103 | |
| 104 | // The BrowsingInstance shared by all extensions in this profile. This |
| 105 | // controls process grouping. |
| 106 | scoped_refptr<BrowsingInstance> browsing_instance_; |
| 107 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 108 | // A map of extension ID to the render_process_id that the extension lives in. |
| 109 | typedef std::map<std::string, int> ProcessIDMap; |
| 110 | ProcessIDMap process_ids_; |
| 111 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 112 | DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
| 113 | }; |
| 114 | |
| 115 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |