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

Unified Diff: chrome/browser/extensions/extension_event_router.cc

Issue 9562017: Keep lazy background page alive while there are pending network requests or (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_event_router.cc
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc
index c92521e62aab6f855fac5a107601a458432449c6..7b8e60c73ba2ae6f2aeec37a79d0700ac29070f0 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -361,7 +361,11 @@ void ExtensionEventRouter::LoadLazyBackgroundPagesForEvent(
if (extension && !CanDispatchEventNow(extension)) {
AppendEvent(extension->id(), event);
- pm->CreateBackgroundHost(extension, extension->GetBackgroundURL());
+ if (!pm->GetBackgroundHostForExtension(extension->id())) {
+ // Balanced in DispatchPendingEvents, after the page has loaded.
Yoyo Zhou 2012/03/02 03:10:46 Is it possible for there to be a race between load
Matt Perry 2012/03/02 20:25:21 The only thing that causes a lazy bg page to load
+ pm->IncrementLazyKeepaliveCount(extension);
+ pm->CreateBackgroundHost(extension, extension->GetBackgroundURL());
+ }
}
}
}
@@ -408,14 +412,6 @@ void ExtensionEventRouter::DispatchPendingEvents(
return;
}
- // Temporarily increment the keepalive count while dispatching the events.
- // This also ensures that if no events were dispatched, the extension returns
- // to "idle" and is shut down.
- const Extension* extension =
- profile_->GetExtensionService()->extensions()->GetByID(extension_id);
- ExtensionProcessManager* pm = profile_->GetExtensionProcessManager();
- pm->IncrementLazyKeepaliveCount(extension);
-
PendingEventsList* events_list = map_it->second.get();
for (PendingEventsList::const_iterator it = events_list->begin();
it != events_list->end(); ++it)
@@ -424,6 +420,10 @@ void ExtensionEventRouter::DispatchPendingEvents(
events_list->clear();
pending_events_.erase(extension_id);
+ // Balance the keepalive addref in LoadLazyBackgroundPagesForEvent.
+ const Extension* extension =
+ profile_->GetExtensionService()->extensions()->GetByID(extension_id);
+ ExtensionProcessManager* pm = profile_->GetExtensionProcessManager();
pm->DecrementLazyKeepaliveCount(extension);
}

Powered by Google App Engine
This is Rietveld 408576698