OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace content { | 25 namespace content { |
26 class RenderViewHost; | 26 class RenderViewHost; |
27 class SiteInstance; | 27 class SiteInstance; |
28 }; | 28 }; |
29 | 29 |
30 // Manages dynamic state of running Chromium extensions. There is one instance | 30 // Manages dynamic state of running Chromium extensions. There is one instance |
31 // of this class per Profile. OTR Profiles have a separate instance that keeps | 31 // of this class per Profile. OTR Profiles have a separate instance that keeps |
32 // track of split-mode extensions only. | 32 // track of split-mode extensions only. |
33 class ExtensionProcessManager : public content::NotificationObserver { | 33 class ExtensionProcessManager : public content::NotificationObserver { |
34 public: | 34 public: |
| 35 typedef std::set<ExtensionHost*> ExtensionHostSet; |
| 36 typedef ExtensionHostSet::const_iterator const_iterator; |
| 37 |
35 static ExtensionProcessManager* Create(Profile* profile); | 38 static ExtensionProcessManager* Create(Profile* profile); |
36 virtual ~ExtensionProcessManager(); | 39 virtual ~ExtensionProcessManager(); |
37 | 40 |
| 41 const ExtensionHostSet& background_hosts() const { |
| 42 return background_hosts_; |
| 43 } |
| 44 |
| 45 const ExtensionHostSet& platform_app_hosts() const { |
| 46 return platform_app_hosts_; |
| 47 } |
| 48 |
| 49 typedef std::set<content::RenderViewHost*> ViewSet; |
| 50 const ViewSet GetAllViews() const; |
| 51 |
38 // Creates a new ExtensionHost with its associated view, grouping it in the | 52 // Creates a new ExtensionHost with its associated view, grouping it in the |
39 // appropriate SiteInstance (and therefore process) based on the URL and | 53 // appropriate SiteInstance (and therefore process) based on the URL and |
40 // profile. | 54 // profile. |
41 virtual ExtensionHost* CreateViewHost(const Extension* extension, | 55 virtual ExtensionHost* CreateViewHost(const Extension* extension, |
42 const GURL& url, | 56 const GURL& url, |
43 Browser* browser, | 57 Browser* browser, |
44 content::ViewType view_type); | 58 content::ViewType view_type); |
45 ExtensionHost* CreateViewHost(const GURL& url, | 59 ExtensionHost* CreateViewHost(const GURL& url, |
46 Browser* browser, | 60 Browser* browser, |
47 content::ViewType view_type); | 61 content::ViewType view_type); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const Extension* extension); | 93 const Extension* extension); |
80 | 94 |
81 // Unregisters a RenderViewHost as hosting any extension. | 95 // Unregisters a RenderViewHost as hosting any extension. |
82 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); | 96 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); |
83 | 97 |
84 // Returns all RenderViewHosts that are registered for the specified | 98 // Returns all RenderViewHosts that are registered for the specified |
85 // extension. | 99 // extension. |
86 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( | 100 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( |
87 const std::string& extension_id); | 101 const std::string& extension_id); |
88 | 102 |
89 // Returns true if |host| is managed by this process manager. | 103 // Returns the extension associated with the specified RenderViewHost, or |
90 bool HasExtensionHost(ExtensionHost* host) const; | 104 // NULL. |
| 105 const Extension* GetExtensionForRenderViewHost( |
| 106 content::RenderViewHost* render_view_host); |
91 | 107 |
92 // Returns true if the (lazy) background host for the given extension has | 108 // Returns true if the (lazy) background host for the given extension has |
93 // already been sent the unload event and is shutting down. | 109 // already been sent the unload event and is shutting down. |
94 bool IsBackgroundHostClosing(const std::string& extension_id); | 110 bool IsBackgroundHostClosing(const std::string& extension_id); |
95 | 111 |
96 // Getter and setter for the lazy background page's keepalive count. This is | 112 // Getter and setter for the lazy background page's keepalive count. This is |
97 // the count of how many outstanding "things" are keeping the page alive. | 113 // the count of how many outstanding "things" are keeping the page alive. |
98 // When this reaches 0, we will begin the process of shutting down the page. | 114 // When this reaches 0, we will begin the process of shutting down the page. |
99 // "Things" include pending events, resource loads, and API calls. | 115 // "Things" include pending events, resource loads, and API calls. |
100 int GetLazyKeepaliveCount(const Extension* extension); | 116 int GetLazyKeepaliveCount(const Extension* extension); |
101 int IncrementLazyKeepaliveCount(const Extension* extension); | 117 int IncrementLazyKeepaliveCount(const Extension* extension); |
102 int DecrementLazyKeepaliveCount(const Extension* extension); | 118 int DecrementLazyKeepaliveCount(const Extension* extension); |
103 | 119 |
104 // Handles a response to the ShouldUnload message, used for lazy background | 120 // Handles a response to the ShouldUnload message, used for lazy background |
105 // pages. | 121 // pages. |
106 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); | 122 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); |
107 | 123 |
108 // Same as above, for the Unload message. | 124 // Same as above, for the Unload message. |
109 void OnUnloadAck(const std::string& extension_id); | 125 void OnUnloadAck(const std::string& extension_id); |
110 | 126 |
111 // Tracks network requests for a given RenderViewHost, used to know | 127 // Tracks network requests for a given RenderViewHost, used to know |
112 // when network activity is idle for lazy background pages. | 128 // when network activity is idle for lazy background pages. |
113 void OnNetworkRequestStarted(content::RenderViewHost* render_view_host); | 129 void OnNetworkRequestStarted(content::RenderViewHost* render_view_host); |
114 void OnNetworkRequestDone(content::RenderViewHost* render_view_host); | 130 void OnNetworkRequestDone(content::RenderViewHost* render_view_host); |
115 | 131 |
116 typedef std::set<ExtensionHost*> ExtensionHostSet; | |
117 typedef ExtensionHostSet::const_iterator const_iterator; | |
118 const_iterator begin() const { return all_hosts_.begin(); } | |
119 const_iterator end() const { return all_hosts_.end(); } | |
120 | |
121 protected: | 132 protected: |
122 explicit ExtensionProcessManager(Profile* profile); | 133 explicit ExtensionProcessManager(Profile* profile); |
123 | 134 |
124 // Called just after |host| is created so it can be registered in our lists. | 135 // Called just after |host| is created so it can be registered in our lists. |
125 void OnExtensionHostCreated(ExtensionHost* host, bool is_background); | 136 void OnExtensionHostCreated(ExtensionHost* host, bool is_background); |
126 | 137 |
127 // Called on browser shutdown to close our extension hosts. | 138 // Called on browser shutdown to close our extension hosts. |
128 void CloseBackgroundHosts(); | 139 void CloseBackgroundHosts(); |
129 | 140 |
130 // content::NotificationObserver: | 141 // content::NotificationObserver: |
131 virtual void Observe(int type, | 142 virtual void Observe(int type, |
132 const content::NotificationSource& source, | 143 const content::NotificationSource& source, |
133 const content::NotificationDetails& details) OVERRIDE; | 144 const content::NotificationDetails& details) OVERRIDE; |
134 | 145 |
135 // Gets the profile associated with site_instance_ and all other | 146 // Gets the profile associated with site_instance_ and all other |
136 // related SiteInstances. | 147 // related SiteInstances. |
137 Profile* GetProfile() const; | 148 Profile* GetProfile() const; |
138 | 149 |
139 content::NotificationRegistrar registrar_; | 150 content::NotificationRegistrar registrar_; |
140 | 151 |
141 // The set of all ExtensionHosts managed by this process manager. | 152 // The set of ExtensionHosts running viewless background extensions. |
142 ExtensionHostSet all_hosts_; | 153 ExtensionHostSet background_hosts_; |
143 | 154 |
144 // The set of running viewless background extensions. | 155 // The set of ExtensionHosts running platform apps. |
145 ExtensionHostSet background_hosts_; | 156 ExtensionHostSet platform_app_hosts_; |
146 | 157 |
147 // A SiteInstance related to the SiteInstance for all extensions in | 158 // A SiteInstance related to the SiteInstance for all extensions in |
148 // this profile. We create it in such a way that a new | 159 // this profile. We create it in such a way that a new |
149 // browsing instance is created. This controls process grouping. | 160 // browsing instance is created. This controls process grouping. |
150 scoped_refptr<content::SiteInstance> site_instance_; | 161 scoped_refptr<content::SiteInstance> site_instance_; |
151 | 162 |
152 private: | 163 private: |
153 // Extra information we keep for each extension's background page. | 164 // Extra information we keep for each extension's background page. |
154 struct BackgroundPageData; | 165 struct BackgroundPageData; |
155 typedef std::string ExtensionId; | 166 typedef std::string ExtensionId; |
(...skipping 22 matching lines...) Expand all Loading... |
178 // associated with a WebContents. This allows us to gather information that | 189 // associated with a WebContents. This allows us to gather information that |
179 // was not available when the host was first registered. | 190 // was not available when the host was first registered. |
180 void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host); | 191 void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host); |
181 | 192 |
182 BackgroundPageDataMap background_page_data_; | 193 BackgroundPageDataMap background_page_data_; |
183 | 194 |
184 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 195 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
185 }; | 196 }; |
186 | 197 |
187 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 198 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
OLD | NEW |