blob: d2d62effa59769be9e86ae05ab3104d21ee07873 [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
58 // Returns the SiteInstance that the given URL belongs to.
59 SiteInstance* GetSiteInstanceForURL(const GURL& url);
60
[email protected]7120f132009-07-20 21:05:3761 // Registers an extension process by |extension_id| and specifying which
[email protected]45776222009-07-15 20:21:5862 // |process_id| it belongs to.
[email protected]7120f132009-07-20 21:05:3763 void RegisterExtensionProcess(const std::string& extension_id,
64 int process_id);
[email protected]45776222009-07-15 20:21:5865
[email protected]7120f132009-07-20 21:05:3766 // Unregisters an extension process with specified |process_id|.
[email protected]45776222009-07-15 20:21:5867 void UnregisterExtensionProcess(int process_id);
68
[email protected]7120f132009-07-20 21:05:3769 // Returns the process that the extension with the given ID is running in.
70 RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
71
[email protected]481e1a42009-05-06 20:56:0572 // NotificationObserver:
73 virtual void Observe(NotificationType type,
74 const NotificationSource& source,
75 const NotificationDetails& details);
76
[email protected]8a17bd52009-06-06 08:19:4977 typedef std::set<ExtensionHost*> ExtensionHostSet;
78 typedef ExtensionHostSet::const_iterator const_iterator;
79 const_iterator begin() const { return all_hosts_.begin(); }
80 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:0681
[email protected]8a17bd52009-06-06 08:19:4982 private:
[email protected]94fe52e2009-06-13 10:09:0683 // Called just after |host| is created so it can be registered in our lists.
84 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
85
[email protected]ae5497f2009-11-05 00:39:4686 // Called on browser shutdown to close our extension hosts.
87 void CloseBackgroundHosts();
88
[email protected]fc368952009-05-21 21:37:0689 NotificationRegistrar registrar_;
90
[email protected]8a17bd52009-06-06 08:19:4991 // The set of all ExtensionHosts managed by this process manager.
92 ExtensionHostSet all_hosts_;
93
94 // The set of running viewless background extensions.
95 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:0596
97 // The BrowsingInstance shared by all extensions in this profile. This
98 // controls process grouping.
99 scoped_refptr<BrowsingInstance> browsing_instance_;
100
[email protected]45776222009-07-15 20:21:58101 // A map of extension ID to the render_process_id that the extension lives in.
102 typedef std::map<std::string, int> ProcessIDMap;
103 ProcessIDMap process_ids_;
104
[email protected]481e1a42009-05-06 20:56:05105 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
106};
107
108#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_