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

Unified Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager_factory.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: '' Created 8 years 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/gallery_watch_manager_factory.cc
diff --git a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager_factory.cc b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..26143efba8900f4849e5053e5ba6ca6f4da4bc98
--- /dev/null
+++ b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager_factory.cc
@@ -0,0 +1,60 @@
+// 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.
+//
+// GalleryWatchManagerFactory implementation.
+
+#include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager_factory.h"
+
+#include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace extensions {
+
+namespace {
+
+base::LazyInstance<GalleryWatchManagerFactory>::Leaky
Lei Zhang 2012/12/15 04:13:21 Why does this have to leak?
kmadhusu 2012/12/17 23:58:05 This class is operated on the file thread. The des
+ g_gallery_watch_manager_factory = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+// static
+GalleryWatchManagerFactory* GalleryWatchManagerFactory::GetInstance() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ return g_gallery_watch_manager_factory.Pointer();
+}
+
+bool GalleryWatchManagerFactory::HasForProfile(const Profile* profile) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ WatchManagerMap::const_iterator it = gallery_watch_managers_.find(profile);
+ return (it != gallery_watch_managers_.end());
+}
+
+GalleryWatchManager* GalleryWatchManagerFactory::GetForProfile(
+ const Profile* profile) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ WatchManagerMap::iterator it = gallery_watch_managers_.find(profile);
+ if (it == gallery_watch_managers_.end())
+ gallery_watch_managers_[profile] = new GalleryWatchManager(profile);
+ return gallery_watch_managers_[profile];
+}
+
+void GalleryWatchManagerFactory::OnProfileShutdown(const Profile* profile) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ WatchManagerMap::iterator it = gallery_watch_managers_.find(profile);
+ if (it == gallery_watch_managers_.end())
+ return;
+ delete it->second;
+ gallery_watch_managers_.erase(it);
+}
+
+GalleryWatchManagerFactory::GalleryWatchManagerFactory() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+}
+
+GalleryWatchManagerFactory::~GalleryWatchManagerFactory() {
+ // This is a leaky lazy instance. Destructor should not be called.
+ NOTREACHED();
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698