blob: e3d6b76cbb5dd8503050c3e2516480351f296413 [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]481e1a42009-05-06 20:56:0514
15class Browser;
16class BrowsingInstance;
17class Extension;
18class ExtensionHost;
[email protected]a4c368182009-05-29 21:53:2719#if defined(TOOLKIT_VIEWS)
[email protected]481e1a42009-05-06 20:56:0520class ExtensionView;
[email protected]673aad72009-05-29 06:32:4321#endif
[email protected]481e1a42009-05-06 20:56:0522class GURL;
23class Profile;
24class SiteInstance;
25
26// Manages dynamic state of running Chromium extensions. There is one instance
27// of this class per Profile (including OTR).
28class ExtensionProcessManager : public NotificationObserver {
29 public:
[email protected]8a17bd52009-06-06 08:19:4930 explicit ExtensionProcessManager(Profile* profile);
[email protected]481e1a42009-05-06 20:56:0531 ~ExtensionProcessManager();
32
[email protected]ab4eaf782009-06-10 00:11:2433 // Creates a new ExtensionHost with its associated view, grouping it in the
34 // appropriate SiteInstance (and therefore process) based on the URL and
35 // profile.
36 ExtensionHost* CreateView(Extension* extension,
[email protected]481e1a42009-05-06 20:56:0537 const GURL& url,
38 Browser* browser);
[email protected]9f1087e2009-06-15 17:29:3239 ExtensionHost* CreateView(const GURL& url, Browser* browser);
[email protected]481e1a42009-05-06 20:56:0540
41 // Creates a new UI-less extension instance. Like CreateView, but not
42 // displayed anywhere.
[email protected]ab4eaf782009-06-10 00:11:2443 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
[email protected]481e1a42009-05-06 20:56:0544
45 // Returns the SiteInstance that the given URL belongs to.
46 SiteInstance* GetSiteInstanceForURL(const GURL& url);
47
[email protected]45776222009-07-15 20:21:5848 // Register an extension process by |extension_id| and specifying which
49 // |process_id| it belongs to.
50 void RegisterExtensionProcess(std::string extension_id, int process_id);
51
52 // Unregister an extension process with specified |process_id|.
53 void UnregisterExtensionProcess(int process_id);
54
[email protected]481e1a42009-05-06 20:56:0555 // NotificationObserver:
56 virtual void Observe(NotificationType type,
57 const NotificationSource& source,
58 const NotificationDetails& details);
59
[email protected]8a17bd52009-06-06 08:19:4960 typedef std::set<ExtensionHost*> ExtensionHostSet;
61 typedef ExtensionHostSet::const_iterator const_iterator;
62 const_iterator begin() const { return all_hosts_.begin(); }
63 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:0664
[email protected]8a17bd52009-06-06 08:19:4965 private:
[email protected]94fe52e2009-06-13 10:09:0666 // Called just after |host| is created so it can be registered in our lists.
67 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
68
[email protected]fc368952009-05-21 21:37:0669 NotificationRegistrar registrar_;
70
[email protected]8a17bd52009-06-06 08:19:4971 // The set of all ExtensionHosts managed by this process manager.
72 ExtensionHostSet all_hosts_;
73
74 // The set of running viewless background extensions.
75 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:0576
77 // The BrowsingInstance shared by all extensions in this profile. This
78 // controls process grouping.
79 scoped_refptr<BrowsingInstance> browsing_instance_;
80
[email protected]45776222009-07-15 20:21:5881 // A map of extension ID to the render_process_id that the extension lives in.
82 typedef std::map<std::string, int> ProcessIDMap;
83 ProcessIDMap process_ids_;
84
[email protected]481e1a42009-05-06 20:56:0585 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
86};
87
88#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_