+// Sends a notification about an event to the API activity monitor on the
+// UI thread. Can be called from any thread.
+void NotifyApiEventDispatched(void* browser_context_id,
+ const std::string& extension_id,
+ const std::string& event_name,
+ scoped_ptr<ListValue> args) {
+ // The ApiActivityMonitor can only be accessed from the UI thread.
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&NotifyApiEventDispatched,
+ browser_context_id,
+ extension_id,
+ event_name,
+ base::Passed(&args)));
+ return;
+ }
+
+ // Notify the ApiActivityMonitor about the event dispatch.
+ BrowserContext* context = static_cast<BrowserContext*>(browser_context_id);
+ if (!ExtensionsBrowserClient::Get()->IsValidContext(context))
+ return;
+ ApiActivityMonitor* monitor =
+ ExtensionsBrowserClient::Get()->GetApiActivityMonitor(context);
+ if (monitor)
+ monitor->OnApiEventDispatched(extension_id, event_name, args.Pass());
+}
+