Fix extension event dispatch for split mode extensions.
Previously extensions with loaded background pages that were also split
mode (i.e. with an unloaded incognito mode background page) would not
receive events.
BUG=156484
TEST=on ChromeOS, the calculator app can be closed and immediately reopened
Review URL: https://chromiumcodereview.appspot.com/11260041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164339 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/event_router.h b/chrome/browser/extensions/event_router.h
index 0196df9e..cbfb1b8 100644
--- a/chrome/browser/extensions/event_router.h
+++ b/chrome/browser/extensions/event_router.h
@@ -8,6 +8,7 @@
#include <map>
#include <set>
#include <string>
+#include <utility>
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
@@ -15,6 +16,7 @@
#include "base/values.h"
#include "chrome/browser/extensions/event_listener_map.h"
#include "chrome/common/extensions/event_filtering_info.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ipc/ipc_sender.h"
@@ -169,6 +171,11 @@
// to that event.
typedef std::map<std::string, std::set<ListenerProcess> > ListenerMap;
+ // An identifier for an event dispatch that is used to prevent double dispatch
+ // due to race conditions between the direct and lazy dispatch paths.
+ typedef std::pair<const content::BrowserContext*, std::string>
+ EventDispatchIdentifier;
+
// TODO(gdk): Document this.
static void DispatchExtensionMessage(
IPC::Sender* ipc_sender,
@@ -198,10 +205,11 @@
// Ensures that all lazy background pages that are interested in the given
// event are loaded, and queues the event if the page is not ready yet.
- // Returns true if the event was queued for subsequent dispatch, false
- // otherwise.
- bool DispatchLazyEvent(const std::string& extension_id,
- const linked_ptr<Event>& event);
+ // Inserts an EventDispatchIdentifier into |already_dispatched| for each lazy
+ // event dispatch that is queued.
+ void DispatchLazyEvent(const std::string& extension_id,
+ const linked_ptr<Event>& event,
+ std::set<EventDispatchIdentifier>* already_dispatched);
// Dispatches the event to the specified extension running in |process|.
void DispatchEventToProcess(const std::string& extension_id,