OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // 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 | 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 #include "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
6 | 6 |
7 #include "chrome/browser/browsing_instance.h" | 7 #include "chrome/browser/browsing_instance.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extensions_service.h" | 9 #include "chrome/browser/extensions/extensions_service.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
(...skipping 26 matching lines...) Loading... |
37 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 37 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
38 NotificationService::AllSources()); | 38 NotificationService::AllSources()); |
39 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 39 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
40 NotificationService::AllSources()); | 40 NotificationService::AllSources()); |
41 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, | 41 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, |
42 Source<Profile>(profile)); | 42 Source<Profile>(profile)); |
43 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 43 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
44 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
45 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 45 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
46 NotificationService::AllSources()); | 46 NotificationService::AllSources()); |
| 47 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 48 NotificationService::AllSources()); |
47 } | 49 } |
48 | 50 |
49 ExtensionProcessManager::~ExtensionProcessManager() { | 51 ExtensionProcessManager::~ExtensionProcessManager() { |
50 // Copy all_hosts_ to avoid iterator invalidation issues. | 52 DCHECK(background_hosts_.empty()); |
51 ExtensionHostSet to_delete(background_hosts_.begin(), | |
52 background_hosts_.end()); | |
53 ExtensionHostSet::iterator iter; | |
54 for (iter = to_delete.begin(); iter != to_delete.end(); ++iter) | |
55 delete *iter; | |
56 } | 53 } |
57 | 54 |
58 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, | 55 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, |
59 const GURL& url, | 56 const GURL& url, |
60 Browser* browser, | 57 Browser* browser, |
61 ViewType::Type view_type) { | 58 ViewType::Type view_type) { |
62 DCHECK(extension); | 59 DCHECK(extension); |
63 DCHECK(browser); | 60 DCHECK(browser); |
64 ExtensionHost* host = | 61 ExtensionHost* host = |
65 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); | 62 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); |
(...skipping 144 matching lines...) Loading... |
210 break; | 207 break; |
211 } | 208 } |
212 | 209 |
213 case NotificationType::RENDERER_PROCESS_TERMINATED: | 210 case NotificationType::RENDERER_PROCESS_TERMINATED: |
214 case NotificationType::RENDERER_PROCESS_CLOSED: { | 211 case NotificationType::RENDERER_PROCESS_CLOSED: { |
215 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); | 212 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); |
216 UnregisterExtensionProcess(host->id()); | 213 UnregisterExtensionProcess(host->id()); |
217 break; | 214 break; |
218 } | 215 } |
219 | 216 |
| 217 case NotificationType::BROWSER_CLOSED: { |
| 218 // Close background hosts when the last browser is closed so that they |
| 219 // have time to shutdown various objects on different threads. Our |
| 220 // destructor is called too late in the shutdown sequence. |
| 221 bool app_closing = *Details<bool>(details).ptr(); |
| 222 if (app_closing) |
| 223 CloseBackgroundHosts(); |
| 224 break; |
| 225 } |
| 226 |
220 default: | 227 default: |
221 NOTREACHED(); | 228 NOTREACHED(); |
222 } | 229 } |
223 } | 230 } |
224 | 231 |
225 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 232 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
226 bool is_background) { | 233 bool is_background) { |
227 all_hosts_.insert(host); | 234 all_hosts_.insert(host); |
228 if (is_background) | 235 if (is_background) |
229 background_hosts_.insert(host); | 236 background_hosts_.insert(host); |
230 NotificationService::current()->Notify( | 237 NotificationService::current()->Notify( |
231 NotificationType::EXTENSION_HOST_CREATED, | 238 NotificationType::EXTENSION_HOST_CREATED, |
232 Source<ExtensionProcessManager>(this), | 239 Source<ExtensionProcessManager>(this), |
233 Details<ExtensionHost>(host)); | 240 Details<ExtensionHost>(host)); |
234 } | 241 } |
| 242 |
| 243 void ExtensionProcessManager::CloseBackgroundHosts() { |
| 244 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 245 iter != background_hosts_.end(); ) { |
| 246 ExtensionHostSet::iterator current = iter++; |
| 247 delete *current; |
| 248 } |
| 249 } |
OLD | NEW |