blob: 9cd861cfe7eaa2ea0ed3f49258af8f9f90e746af [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]8a17bd52009-06-06 08:19:498#include <set>
[email protected]481e1a42009-05-06 20:56:059
10#include "base/ref_counted.h"
[email protected]fc368952009-05-21 21:37:0611#include "chrome/common/notification_registrar.h"
[email protected]481e1a42009-05-06 20:56:0512
13class Browser;
14class BrowsingInstance;
15class Extension;
16class ExtensionHost;
[email protected]a4c368182009-05-29 21:53:2717#if defined(TOOLKIT_VIEWS)
[email protected]481e1a42009-05-06 20:56:0518class ExtensionView;
[email protected]673aad72009-05-29 06:32:4319#endif
[email protected]481e1a42009-05-06 20:56:0520class GURL;
21class Profile;
22class SiteInstance;
23
24// Manages dynamic state of running Chromium extensions. There is one instance
25// of this class per Profile (including OTR).
26class ExtensionProcessManager : public NotificationObserver {
27 public:
[email protected]8a17bd52009-06-06 08:19:4928 explicit ExtensionProcessManager(Profile* profile);
[email protected]481e1a42009-05-06 20:56:0529 ~ExtensionProcessManager();
30
[email protected]ab4eaf782009-06-10 00:11:2431 // Creates a new ExtensionHost with its associated view, grouping it in the
32 // appropriate SiteInstance (and therefore process) based on the URL and
33 // profile.
34 ExtensionHost* CreateView(Extension* extension,
[email protected]481e1a42009-05-06 20:56:0535 const GURL& url,
36 Browser* browser);
[email protected]9f1087e2009-06-15 17:29:3237 ExtensionHost* CreateView(const GURL& url, Browser* browser);
[email protected]481e1a42009-05-06 20:56:0538
39 // Creates a new UI-less extension instance. Like CreateView, but not
40 // displayed anywhere.
[email protected]ab4eaf782009-06-10 00:11:2441 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
[email protected]481e1a42009-05-06 20:56:0542
43 // Returns the SiteInstance that the given URL belongs to.
44 SiteInstance* GetSiteInstanceForURL(const GURL& url);
45
46 // NotificationObserver:
47 virtual void Observe(NotificationType type,
48 const NotificationSource& source,
49 const NotificationDetails& details);
50
[email protected]8a17bd52009-06-06 08:19:4951 typedef std::set<ExtensionHost*> ExtensionHostSet;
52 typedef ExtensionHostSet::const_iterator const_iterator;
53 const_iterator begin() const { return all_hosts_.begin(); }
54 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:0655
[email protected]8a17bd52009-06-06 08:19:4956 // Called just before |host| is destroyed so it can be de-registered
57 // from our lists.
58 void OnExtensionHostDestroyed(ExtensionHost* host);
59
60 private:
[email protected]94fe52e2009-06-13 10:09:0661 // Called just after |host| is created so it can be registered in our lists.
62 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
63
[email protected]fc368952009-05-21 21:37:0664 NotificationRegistrar registrar_;
65
[email protected]8a17bd52009-06-06 08:19:4966 // The set of all ExtensionHosts managed by this process manager.
67 ExtensionHostSet all_hosts_;
68
69 // The set of running viewless background extensions.
70 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:0571
72 // The BrowsingInstance shared by all extensions in this profile. This
73 // controls process grouping.
74 scoped_refptr<BrowsingInstance> browsing_instance_;
75
76 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
77};
78
79#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_