Index: chrome/browser/extensions/lazy_background_task_queue.cc |
diff --git a/chrome/browser/extensions/lazy_background_task_queue.cc b/chrome/browser/extensions/lazy_background_task_queue.cc |
index 4691c47fedc2d93c8d60804630d1a7c27126f204..bcf7d1c4f18d88b90ae84b4f818c9abfd3d93a44 100644 |
--- a/chrome/browser/extensions/lazy_background_task_queue.cc |
+++ b/chrome/browser/extensions/lazy_background_task_queue.cc |
@@ -29,6 +29,8 @@ LazyBackgroundTaskQueue::LazyBackgroundTaskQueue(Profile* profile) |
: profile_(profile) { |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
content::NotificationService::AllBrowserContextsAndSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
content::Source<Profile>(profile)); |
} |
@@ -66,7 +68,7 @@ void LazyBackgroundTaskQueue::AddPendingTask( |
const Extension* extension = profile->GetExtensionService()-> |
extensions()->GetByID(extension_id); |
DCHECK(extension->has_lazy_background_page()); |
- ExtensionProcessManager* pm = profile->GetExtensionProcessManager(); |
+ ExtensionProcessManager* pm = profile->GetExtensionProcessManager(); |
pm->IncrementLazyKeepaliveCount(extension); |
pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); |
} else { |
@@ -116,6 +118,19 @@ void LazyBackgroundTaskQueue::Observe( |
} |
break; |
} |
+ case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
+ // Clear pending tasks when the background host dies. This can happen |
+ // if the extension crashes. This is not strictly necessary, since we |
+ // also unload the extension in that case (which clears the tasks below), |
+ // but is a good extra precaution. |
+ Profile* profile = content::Source<Profile>(source).ptr(); |
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
+ if (host->extension_host_type() == |
+ chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
+ pending_tasks_.erase(PendingTasksKey(profile, host->extension()->id())); |
+ } |
+ break; |
+ } |
case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
// Clear pending tasks for this extension. |
Profile* profile = content::Source<Profile>(source).ptr(); |