blob: 1cfec713cfdbf7f4ac69dad335b673ac8fbd5f86 [file] [log] [blame]
[email protected]481e1a42009-05-06 20:56:051// 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]45776222009-07-15 20:21:588#include <map>
[email protected]8a17bd52009-06-06 08:19:499#include <set>
[email protected]45776222009-07-15 20:21:5810#include <string>
[email protected]481e1a42009-05-06 20:56:0511
12#include "base/ref_counted.h"
[email protected]fc368952009-05-21 21:37:0613#include "chrome/common/notification_registrar.h"
[email protected]2d8d9232009-10-02 20:19:2014#include "chrome/common/view_types.h"
[email protected]481e1a42009-05-06 20:56:0515
16class Browser;
17class BrowsingInstance;
18class Extension;
19class ExtensionHost;
[email protected]a4c368182009-05-29 21:53:2720#if defined(TOOLKIT_VIEWS)
[email protected]481e1a42009-05-06 20:56:0521class ExtensionView;
[email protected]673aad72009-05-29 06:32:4322#endif
[email protected]481e1a42009-05-06 20:56:0523class GURL;
24class Profile;
[email protected]7120f132009-07-20 21:05:3725class RenderProcessHost;
[email protected]481e1a42009-05-06 20:56:0526class SiteInstance;
27
28// Manages dynamic state of running Chromium extensions. There is one instance
29// of this class per Profile (including OTR).
30class ExtensionProcessManager : public NotificationObserver {
31 public:
[email protected]8a17bd52009-06-06 08:19:4932 explicit ExtensionProcessManager(Profile* profile);
[email protected]481e1a42009-05-06 20:56:0533 ~ExtensionProcessManager();
34
[email protected]ab4eaf782009-06-10 00:11:2435 // 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]481e1a42009-05-06 20:56:0539 const GURL& url,
[email protected]2d8d9232009-10-02 20:19:2040 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]481e1a42009-05-06 20:56:0553
54 // Creates a new UI-less extension instance. Like CreateView, but not
55 // displayed anywhere.
[email protected]ab4eaf782009-06-10 00:11:2456 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
[email protected]481e1a42009-05-06 20:56:0557
[email protected]4814b512009-11-07 00:12:2958 // 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]481e1a42009-05-06 20:56:0562 // Returns the SiteInstance that the given URL belongs to.
63 SiteInstance* GetSiteInstanceForURL(const GURL& url);
64
[email protected]7120f132009-07-20 21:05:3765 // Registers an extension process by |extension_id| and specifying which
[email protected]45776222009-07-15 20:21:5866 // |process_id| it belongs to.
[email protected]7120f132009-07-20 21:05:3767 void RegisterExtensionProcess(const std::string& extension_id,
68 int process_id);
[email protected]45776222009-07-15 20:21:5869
[email protected]7120f132009-07-20 21:05:3770 // Unregisters an extension process with specified |process_id|.
[email protected]45776222009-07-15 20:21:5871 void UnregisterExtensionProcess(int process_id);
72
[email protected]7120f132009-07-20 21:05:3773 // Returns the process that the extension with the given ID is running in.
74 RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
75
[email protected]27e469a2010-01-11 20:35:0976 // Returns true if |host| is managed by this process manager.
77 bool HasExtensionHost(ExtensionHost* host) const;
78
[email protected]481e1a42009-05-06 20:56:0579 // NotificationObserver:
80 virtual void Observe(NotificationType type,
81 const NotificationSource& source,
82 const NotificationDetails& details);
83
[email protected]8a17bd52009-06-06 08:19:4984 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]fc368952009-05-21 21:37:0688
[email protected]8a17bd52009-06-06 08:19:4989 private:
[email protected]94fe52e2009-06-13 10:09:0690 // 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]ae5497f2009-11-05 00:39:4693 // Called on browser shutdown to close our extension hosts.
94 void CloseBackgroundHosts();
95
[email protected]fc368952009-05-21 21:37:0696 NotificationRegistrar registrar_;
97
[email protected]8a17bd52009-06-06 08:19:4998 // 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]481e1a42009-05-06 20:56:05103
104 // The BrowsingInstance shared by all extensions in this profile. This
105 // controls process grouping.
106 scoped_refptr<BrowsingInstance> browsing_instance_;
107
[email protected]45776222009-07-15 20:21:58108 // 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]481e1a42009-05-06 20:56:05112 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
113};
114
115#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_