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

Unified Diff: chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc

Issue 11535008: Implement mediaGalleriesPrivate api to notify extensions about gallery changed events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable SetupGalleryWatch browser test on ChromeOS Created 7 years, 11 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/api/media_galleries_private/media_galleries_private_event_router.cc
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
index b270fad6a5104d53cc21f0fafd6feb3abd8f8256..fe7f002400fa54aefbba4d7cab4efa70adc33eb7 100644
--- a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
+++ b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
@@ -9,6 +9,7 @@
#include <map>
#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
@@ -16,6 +17,7 @@
#include "chrome/browser/media_gallery/media_file_system_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/media_galleries_private.h"
+#include "content/public/browser/browser_thread.h"
namespace extensions {
@@ -31,27 +33,59 @@ std::string GetTransientIdForDeviceId(const std::string& device_id) {
using extensions::api::media_galleries_private::DeviceAttachmentDetails;
using extensions::api::media_galleries_private::DeviceDetachmentDetails;
+using extensions::api::media_galleries_private::GalleryChangeDetails;
MediaGalleriesPrivateEventRouter::MediaGalleriesPrivateEventRouter(
Profile* profile)
: profile_(profile) {
- CHECK(profile_);
-
+ DCHECK(profile_);
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
if (system_monitor)
system_monitor->AddDevicesChangedObserver(this);
}
MediaGalleriesPrivateEventRouter::~MediaGalleriesPrivateEventRouter() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
if (system_monitor)
system_monitor->RemoveDevicesChangedObserver(this);
}
+void MediaGalleriesPrivateEventRouter::OnGalleryChanged(
+ chrome::MediaGalleryPrefId gallery_id,
+ const std::set<std::string>& extension_ids) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ EventRouter* router =
+ extensions::ExtensionSystem::Get(profile_)->event_router();
+ if (!router->HasEventListener(event_names::kOnGalleryChangedEventName))
+ return;
+
+ for (std::set<std::string>::const_iterator it = extension_ids.begin();
+ it != extension_ids.end(); ++it) {
+ GalleryChangeDetails details;
+ details.gallery_id = gallery_id;
+ scoped_ptr<ListValue> args(new ListValue());
+ args->Append(details.ToValue().release());
+ scoped_ptr<extensions::Event> event(new extensions::Event(
+ event_names::kOnGalleryChangedEventName,
+ args.Pass()));
+ // Use DispatchEventToExtension() instead of BroadcastEvent().
+ // BroadcastEvent() sends the gallery changed events to all the extensions
+ // who have added a listener to the onGalleryChanged event. There is a
+ // chance that an extension might have added an onGalleryChanged() listener
+ // without calling addGalleryWatch(). Therefore, use
+ // DispatchEventToExtension() to dispatch the gallery changed event only to
+ // the watching extensions.
+ router->DispatchEventToExtension(*it, event.Pass());
+ }
+}
+
void MediaGalleriesPrivateEventRouter::OnRemovableStorageAttached(
const std::string& id,
const string16& name,
const FilePath::StringType& location) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
EventRouter* router =
extensions::ExtensionSystem::Get(profile_)->event_router();
if (!router->HasEventListener(event_names::kOnAttachEventName))
@@ -68,6 +102,7 @@ void MediaGalleriesPrivateEventRouter::OnRemovableStorageAttached(
void MediaGalleriesPrivateEventRouter::OnRemovableStorageDetached(
const std::string& id) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
EventRouter* router =
extensions::ExtensionSystem::Get(profile_)->event_router();
if (!router->HasEventListener(event_names::kOnDetachEventName))
@@ -84,6 +119,7 @@ void MediaGalleriesPrivateEventRouter::OnRemovableStorageDetached(
void MediaGalleriesPrivateEventRouter::DispatchEvent(
const std::string& event_name,
scoped_ptr<base::ListValue> event_args) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
EventRouter* router =
extensions::ExtensionSystem::Get(profile_)->event_router();
if (!router)

Powered by Google App Engine
This is Rietveld 408576698