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

Unified Diff: chrome/browser/extensions/api/media_galleries_private/media_gallery_extension_notification_observer.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_gallery_extension_notification_observer.cc
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_gallery_extension_notification_observer.cc b/chrome/browser/extensions/api/media_galleries_private/media_gallery_extension_notification_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e7eee23a29f7d4f2098c721e509501730e65190
--- /dev/null
+++ b/chrome/browser/extensions/api/media_galleries_private/media_gallery_extension_notification_observer.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// MediaGalleryExtensionNotificationObserver implementation.
+
+#include "chrome/browser/extensions/api/media_galleries_private/media_gallery_extension_notification_observer.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+
+namespace extensions {
+
+using content::BrowserThread;
+
+namespace {
+
+// Handles the extension destroyed event on the file thread.
+void HandleExtensionDestroyedOnFileThread(void* profile_id,
+ const std::string& extension_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ if (!GalleryWatchManager::HasForProfile(profile_id))
+ return;
+ GalleryWatchManager::GetForProfile(profile_id)->OnExtensionDestroyed(
+ extension_id);
+}
+
+} // namespace
+
+MediaGalleryExtensionNotificationObserver::
+MediaGalleryExtensionNotificationObserver(Profile* profile)
+ : profile_(profile) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(profile_);
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
+ content::Source<Profile>(profile_->GetOriginalProfile()));
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::Source<Profile>(profile_->GetOriginalProfile()));
+}
+
+MediaGalleryExtensionNotificationObserver::
+~MediaGalleryExtensionNotificationObserver() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+void MediaGalleryExtensionNotificationObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Extension* extension = NULL;
+ if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
+ extension = const_cast<Extension*>(
+ content::Details<extensions::UnloadedExtensionInfo>(
+ details)->extension);
+ } else {
+ DCHECK(type == chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED);
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
+ extension = const_cast<Extension*>(host->extension());
+ }
+ DCHECK(extension);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&HandleExtensionDestroyedOnFileThread,
+ profile_,
+ extension->id()));
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698