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

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

Issue 10804020: Introduce runtime.onSuspendCanceled() event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comments Created 8 years, 5 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 9d4d97c7e123bce7d7d02c01eb26b3d9e2586ac0..56c2e67601e42165066619be2f055e8e32c863fb 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -374,6 +374,23 @@ void ExtensionEventRouter::DispatchEventImpl(
std::set<const EventListener*> listeners(
listeners_.GetEventListeners(*event));
+
+ // We dispatch events for lazy background pages first because attempting to do
+ // so will cause those that are being suspended to cancel that suspension.
+ // As canceling a suspension entails sending an event to the affected
+ // background page, and as that event needs to be delivered before we dispatch
+ // the event we are dispatching here, we dispatch to the lazy listeners here
+ // first.
+ for (std::set<const EventListener*>::iterator it = listeners.begin();
+ it != listeners.end(); it++) {
+ const EventListener* listener = *it;
+ if (restrict_to_extension_id.empty() ||
+ restrict_to_extension_id == listener->extension_id) {
+ if (!listener->process)
+ DispatchLazyEvent(listener->extension_id, event);
+ }
+ }
+
for (std::set<const EventListener*>::iterator it = listeners.begin();
it != listeners.end(); it++) {
const EventListener* listener = *it;
@@ -382,8 +399,6 @@ void ExtensionEventRouter::DispatchEventImpl(
if (listener->process) {
DispatchEventToProcess(listener->extension_id, listener->process,
event);
- } else {
- DispatchLazyEvent(listener->extension_id, event);
}
}
}
@@ -436,16 +451,11 @@ void ExtensionEventRouter::DispatchEventToProcess(
return;
}
- // We need to call IncrementInFlightEvents() before DispatchEvent() because
- // the former may prevent this extension from getting suspended and so send
- // the onSuspendCanceled() to the extension, which needs to arrive before the
- // event that DispatchEvent() is dispatching.
- IncrementInFlightEvents(listener_profile, extension);
-
DispatchEvent(process, extension_id,
event->event_name, *event_args,
event->event_url, event->user_gesture,
event->info);
+ IncrementInFlightEvents(listener_profile, extension);
}
bool ExtensionEventRouter::CanDispatchEventToProfile(
@@ -498,8 +508,7 @@ void ExtensionEventRouter::IncrementInFlightEvents(
extensions::ExtensionSystem::Get(profile)->process_manager();
ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id());
if (host)
- pm->IncrementLazyKeepaliveCount(
- extension, ExtensionProcessManager::CANCEL_SUSPEND);
+ pm->IncrementLazyKeepaliveCount(extension);
}
}

Powered by Google App Engine
This is Rietveld 408576698