OLD | NEW |
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 #include "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/browsing_instance.h" | 9 #include "chrome/browser/browsing_instance.h" |
10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 44 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
45 NotificationService::AllSources()); | 45 NotificationService::AllSources()); |
46 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 46 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
47 NotificationService::AllSources()); | 47 NotificationService::AllSources()); |
48 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, | 48 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, |
49 Source<Profile>(profile)); | 49 Source<Profile>(profile)); |
50 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 50 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
51 NotificationService::AllSources()); | 51 NotificationService::AllSources()); |
52 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 52 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
53 NotificationService::AllSources()); | 53 NotificationService::AllSources()); |
54 #if defined(OS_WIN) || defined(OS_LINUX) | |
55 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | |
56 NotificationService::AllSources()); | |
57 #elif defined(OS_MACOSX) | |
58 registrar_.Add(this, NotificationType::APP_TERMINATING, | 54 registrar_.Add(this, NotificationType::APP_TERMINATING, |
59 NotificationService::AllSources()); | 55 NotificationService::AllSources()); |
60 #endif | |
61 } | 56 } |
62 | 57 |
63 ExtensionProcessManager::~ExtensionProcessManager() { | 58 ExtensionProcessManager::~ExtensionProcessManager() { |
64 CloseBackgroundHosts(); | 59 CloseBackgroundHosts(); |
65 DCHECK(background_hosts_.empty()); | 60 DCHECK(background_hosts_.empty()); |
66 } | 61 } |
67 | 62 |
68 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, | 63 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, |
69 const GURL& url, | 64 const GURL& url, |
70 Browser* browser, | 65 Browser* browser, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 background_hosts_.erase(host); | 273 background_hosts_.erase(host); |
279 break; | 274 break; |
280 } | 275 } |
281 | 276 |
282 case NotificationType::RENDERER_PROCESS_TERMINATED: | 277 case NotificationType::RENDERER_PROCESS_TERMINATED: |
283 case NotificationType::RENDERER_PROCESS_CLOSED: { | 278 case NotificationType::RENDERER_PROCESS_CLOSED: { |
284 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); | 279 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); |
285 UnregisterExtensionProcess(host->id()); | 280 UnregisterExtensionProcess(host->id()); |
286 break; | 281 break; |
287 } | 282 } |
288 #if defined(OS_WIN) || defined(OS_LINUX) | 283 |
289 case NotificationType::BROWSER_CLOSED: { | 284 case NotificationType::APP_TERMINATING: { |
290 // Close background hosts when the last browser is closed so that they | 285 // Close background hosts when the last browser is closed so that they |
291 // have time to shutdown various objects on different threads. Our | 286 // have time to shutdown various objects on different threads. Our |
292 // destructor is called too late in the shutdown sequence. | 287 // destructor is called too late in the shutdown sequence. |
293 bool app_closing = *Details<bool>(details).ptr(); | |
294 if (app_closing) | |
295 CloseBackgroundHosts(); | |
296 break; | |
297 } | |
298 #elif defined(OS_MACOSX) | |
299 case NotificationType::APP_TERMINATING: { | |
300 CloseBackgroundHosts(); | 288 CloseBackgroundHosts(); |
301 break; | 289 break; |
302 } | 290 } |
303 #endif | |
304 | 291 |
305 default: | 292 default: |
306 NOTREACHED(); | 293 NOTREACHED(); |
307 } | 294 } |
308 } | 295 } |
309 | 296 |
310 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 297 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
311 bool is_background) { | 298 bool is_background) { |
312 all_hosts_.insert(host); | 299 all_hosts_.insert(host); |
313 if (is_background) | 300 if (is_background) |
314 background_hosts_.insert(host); | 301 background_hosts_.insert(host); |
315 NotificationService::current()->Notify( | 302 NotificationService::current()->Notify( |
316 NotificationType::EXTENSION_HOST_CREATED, | 303 NotificationType::EXTENSION_HOST_CREATED, |
317 Source<ExtensionProcessManager>(this), | 304 Source<ExtensionProcessManager>(this), |
318 Details<ExtensionHost>(host)); | 305 Details<ExtensionHost>(host)); |
319 } | 306 } |
320 | 307 |
321 void ExtensionProcessManager::CloseBackgroundHosts() { | 308 void ExtensionProcessManager::CloseBackgroundHosts() { |
322 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 309 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
323 iter != background_hosts_.end(); ) { | 310 iter != background_hosts_.end(); ) { |
324 ExtensionHostSet::iterator current = iter++; | 311 ExtensionHostSet::iterator current = iter++; |
325 delete *current; | 312 delete *current; |
326 } | 313 } |
327 } | 314 } |
OLD | NEW |