Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/extensions/extension_process_manager.h

Issue 3210007: Add support for a "split" incognito behavior for extensions. (Closed)
Patch Set: latest Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "chrome/common/notification_observer.h" 14 #include "chrome/common/notification_observer.h"
15 #include "chrome/common/notification_registrar.h" 15 #include "chrome/common/notification_registrar.h"
16 #include "chrome/common/view_types.h" 16 #include "chrome/common/view_types.h"
17 17
18 class Browser; 18 class Browser;
19 class BrowsingInstance; 19 class BrowsingInstance;
20 class Extension; 20 class Extension;
21 class ExtensionHost; 21 class ExtensionHost;
22 class GURL; 22 class GURL;
23 class Profile; 23 class Profile;
24 class RenderProcessHost; 24 class RenderProcessHost;
25 class SiteInstance; 25 class SiteInstance;
26 26
27 // Manages dynamic state of running Chromium extensions. There is one instance 27 // Manages dynamic state of running Chromium extensions. There is one instance
28 // of this class per Profile (including OTR). 28 // of this class per Profile. OTR Profiles have a separate instance that keeps
29 // track of split-mode extensions only.
29 class ExtensionProcessManager : public NotificationObserver { 30 class ExtensionProcessManager : public NotificationObserver {
30 public: 31 public:
31 explicit ExtensionProcessManager(Profile* profile); 32 static ExtensionProcessManager* Create(Profile* profile);
32 ~ExtensionProcessManager(); 33 virtual ~ExtensionProcessManager();
33 34
34 // Creates a new ExtensionHost with its associated view, grouping it in the 35 // Creates a new ExtensionHost with its associated view, grouping it in the
35 // appropriate SiteInstance (and therefore process) based on the URL and 36 // appropriate SiteInstance (and therefore process) based on the URL and
36 // profile. 37 // profile.
37 ExtensionHost* CreateView(Extension* extension, 38 virtual ExtensionHost* CreateView(Extension* extension,
38 const GURL& url, 39 const GURL& url,
39 Browser* browser, 40 Browser* browser,
40 ViewType::Type view_type); 41 ViewType::Type view_type);
41 ExtensionHost* CreateView(const GURL& url, 42 ExtensionHost* CreateView(const GURL& url,
42 Browser* browser, 43 Browser* browser,
43 ViewType::Type view_type); 44 ViewType::Type view_type);
44 ExtensionHost* CreatePopup(Extension* extension, 45 ExtensionHost* CreatePopup(Extension* extension,
45 const GURL& url, 46 const GURL& url,
46 Browser* browser); 47 Browser* browser);
47 ExtensionHost* CreatePopup(const GURL& url, Browser* browser); 48 ExtensionHost* CreatePopup(const GURL& url, Browser* browser);
48 ExtensionHost* CreateInfobar(Extension* extension, 49 ExtensionHost* CreateInfobar(Extension* extension,
49 const GURL& url, 50 const GURL& url,
50 Browser* browser); 51 Browser* browser);
51 ExtensionHost* CreateInfobar(const GURL& url, 52 ExtensionHost* CreateInfobar(const GURL& url,
52 Browser* browser); 53 Browser* browser);
53 54
55 // Open the extension's options page.
56 void OpenOptionsPage(Extension* extension, Browser* browser);
57
54 // Creates a new UI-less extension instance. Like CreateView, but not 58 // Creates a new UI-less extension instance. Like CreateView, but not
55 // displayed anywhere. 59 // displayed anywhere.
56 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url); 60 virtual void CreateBackgroundHost(Extension* extension, const GURL& url);
57
58 // Open the extension's options page.
59 void OpenOptionsPage(Extension* extension, Browser* browser);
60 61
61 // Gets the ExtensionHost for the background page for an extension, or NULL if 62 // Gets the ExtensionHost for the background page for an extension, or NULL if
62 // the extension isn't running or doesn't have a background page. 63 // the extension isn't running or doesn't have a background page.
63 ExtensionHost* GetBackgroundHostForExtension(Extension* extension); 64 ExtensionHost* GetBackgroundHostForExtension(Extension* extension);
64 65
65 // Returns the SiteInstance that the given URL belongs to. 66 // Returns the SiteInstance that the given URL belongs to.
66 SiteInstance* GetSiteInstanceForURL(const GURL& url); 67 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url);
67 68
68 // Registers an extension process by |extension_id| and specifying which 69 // Registers an extension process by |extension_id| and specifying which
69 // |process_id| it belongs to. 70 // |process_id| it belongs to.
70 void RegisterExtensionProcess(const std::string& extension_id, 71 void RegisterExtensionProcess(const std::string& extension_id,
71 int process_id); 72 int process_id);
72 73
73 // Unregisters an extension process with specified |process_id|. 74 // Unregisters an extension process with specified |process_id|.
74 void UnregisterExtensionProcess(int process_id); 75 void UnregisterExtensionProcess(int process_id);
75 76
76 // Returns the extension process that |url| is associated with if it exists. 77 // Returns the extension process that |url| is associated with if it exists.
77 RenderProcessHost* GetExtensionProcess(const GURL& url); 78 virtual RenderProcessHost* GetExtensionProcess(const GURL& url);
78 79
79 // Returns the process that the extension with the given ID is running in. 80 // Returns the process that the extension with the given ID is running in.
80 // NOTE: This does not currently handle app processes with no
81 // ExtensionFunctionDispatcher objects.
82 RenderProcessHost* GetExtensionProcess(const std::string& extension_id); 81 RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
83 82
84 // Returns true if |host| is managed by this process manager. 83 // Returns true if |host| is managed by this process manager.
85 bool HasExtensionHost(ExtensionHost* host) const; 84 bool HasExtensionHost(ExtensionHost* host) const;
86 85
86 typedef std::set<ExtensionHost*> ExtensionHostSet;
87 typedef ExtensionHostSet::const_iterator const_iterator;
88 const_iterator begin() const { return all_hosts_.begin(); }
89 const_iterator end() const { return all_hosts_.end(); }
90
91 protected:
92 explicit ExtensionProcessManager(Profile* profile);
93
94 // Called just after |host| is created so it can be registered in our lists.
95 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
96
97 // Called on browser shutdown to close our extension hosts.
98 void CloseBackgroundHosts();
99
87 // NotificationObserver: 100 // NotificationObserver:
88 virtual void Observe(NotificationType type, 101 virtual void Observe(NotificationType type,
89 const NotificationSource& source, 102 const NotificationSource& source,
90 const NotificationDetails& details); 103 const NotificationDetails& details);
91 104
92 typedef std::set<ExtensionHost*> ExtensionHostSet;
93 typedef ExtensionHostSet::const_iterator const_iterator;
94 const_iterator begin() const { return all_hosts_.begin(); }
95 const_iterator end() const { return all_hosts_.end(); }
96
97 private:
98 // Called just after |host| is created so it can be registered in our lists.
99 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
100
101 // Called on browser shutdown to close our extension hosts.
102 void CloseBackgroundHosts();
103
104 NotificationRegistrar registrar_; 105 NotificationRegistrar registrar_;
105 106
106 // The set of all ExtensionHosts managed by this process manager. 107 // The set of all ExtensionHosts managed by this process manager.
107 ExtensionHostSet all_hosts_; 108 ExtensionHostSet all_hosts_;
108 109
109 // The set of running viewless background extensions. 110 // The set of running viewless background extensions.
110 ExtensionHostSet background_hosts_; 111 ExtensionHostSet background_hosts_;
111 112
112 // The BrowsingInstance shared by all extensions in this profile. This 113 // The BrowsingInstance shared by all extensions in this profile. This
113 // controls process grouping. 114 // controls process grouping.
114 scoped_refptr<BrowsingInstance> browsing_instance_; 115 scoped_refptr<BrowsingInstance> browsing_instance_;
115 116
116 // A map of extension ID to the render_process_id that the extension lives in. 117 // A map of extension ID to the render_process_id that the extension lives in.
117 typedef std::map<std::string, int> ProcessIDMap; 118 typedef std::map<std::string, int> ProcessIDMap;
118 ProcessIDMap process_ids_; 119 ProcessIDMap process_ids_;
119 120
120 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); 121 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
121 }; 122 };
122 123
123 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_popup_api.cc ('k') | chrome/browser/extensions/extension_process_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698