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

Unified Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h

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.h
diff --git a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..c231d1831ba3ae87e26f211af86947c26b8b7514
--- /dev/null
+++ b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.h
@@ -0,0 +1,141 @@
+// 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.
+
+// Manages all the gallery file watchers for the associated profile. This
+// is temporary and will be moved to a permanent, public place in the near
+// future.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_MANAGER_H_
+#define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_MANAGER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/file_path.h"
+#include "base/files/file_path_watcher.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/time.h"
+
+class Profile;
+
+namespace extensions {
+
+// The profile-keyed service that manages the gallery watchers. This class is
+// constructed, destructed and operated on the FILE thread.
Lei Zhang 2012/12/15 01:11:54 You can just say "this class lives on the foo thre
kmadhusu 2012/12/17 23:58:05 Done.
+class GalleryWatchManager {
+ public:
+ typedef std::set<std::string> ExtensionIdSet;
Lei Zhang 2012/12/15 01:11:54 This seems to be used in 1 place inside the .cc fi
kmadhusu 2012/12/17 23:58:05 Removed typedef.
+
+ explicit GalleryWatchManager(const Profile* profile);
+ ~GalleryWatchManager();
+
+ // Initiates a gallery watch operation for the extension specified by
+ // the |extension_id|. |gallery_id| specifies the gallery identifier and
+ // |watch_path| specifies the absolute path of the gallery. Returns true,
+ // if the watch was set successfully.
+ bool StartGalleryWatch(const std::string& gallery_id,
+ const FilePath& watch_path,
+ const std::string& extension_id);
+
+ // Cancels the gallery watch operation for the extension specified by the
+ // |extension_id|. |watch_path| specifies the gallery absolute path.
+ void StopGalleryWatch(const FilePath& watch_path,
+ const std::string& extension_id);
+
+ // Handles the extension unloaded/uninstalled/destroyed event.
+ void OnExtensionDestroyed(const std::string& extension_id);
+
+ private:
+ typedef std::map<std::string, int> ExtensionUsageRegistry;
Lei Zhang 2012/12/15 04:13:21 This map is too wimpy to a registry.
kmadhusu 2012/12/17 23:58:05 ExtensionUsageRegistry => ExtensionWatchCountMap
+
+ class GalleryFilePathWatcher;
+ typedef std::map<FilePath, GalleryFilePathWatcher*> WatcherMap;
+
+ // Gallery file path watcher delegate to handle the gallery change
Lei Zhang 2012/12/15 04:13:21 You should mention this class does recursive watch
kmadhusu 2012/12/17 23:58:05 Done.
+ // notifications. This class manages all the extension usage and forwards
+ // the gallery change notifications to the extensions.
+ // This class is constructed, destructed and operated on the FILE thread.
+ // This class is instantiated per gallery watch path.
+ class GalleryFilePathWatcher {
Lei Zhang 2012/12/15 04:13:21 Can this go in the .cc file instead?
kmadhusu 2012/12/17 23:58:05 Done.
+ public:
+ GalleryFilePathWatcher(const Profile* profile,
+ const std::string& gallery_id,
+ const FilePath& path,
+ const std::string& extension_id);
+
+ ~GalleryFilePathWatcher();
+
+ // Adds the extension specified by the |extension_id| to the
+ // ExtensionUsageRegistry and initiate the watch operation.
+ void AddExtension(const std::string& extension_id);
+
+ // Cancels the watch for the extension specified by the |extension_id|.
+ void RemoveExtension(const std::string& extension_id);
+
+ // Handles the extension unloaded/uninstalled/destroyed event.
+ void OnExtensionDestroyed(const std::string& extension_id);
+
+ // Returns the total number of watchers for the |gallery_path_|.
+ unsigned int GetRefCount() const;
+
+ // Sets up the watch operation for the specified |gallery_path_|. On
+ // success, returns true.
+ bool SetupWatch();
+
+ private:
+ // FilePathWatcher callback.
+ void OnFilePathChanged(const FilePath& path, bool error);
+
+ // Current profile.
+ const Profile* profile_;
+
+ // The gallery identifier, e.g "1".
+ const std::string gallery_id_;
+
+ // The gallery file path watcher.
+ scoped_ptr<base::files::FilePathWatcher> file_watcher_;
Lei Zhang 2012/12/15 04:13:21 Does this need to be a scoped_ptr?
kmadhusu 2012/12/17 23:58:05 Not needed.
+
+ // The gallery file path, e.g "C:/My Pictures".
Lei Zhang 2012/12/15 04:13:21 nit: C:\, not C:/
kmadhusu 2012/12/17 23:58:05 Done.
+ FilePath gallery_path_;
+
+ // Map to keep track of the extension and its corresponding watch count.
+ // Key: Extension identifier, e.g "qoueruoweuroiwueroiwujkshdf".
+ // Value: Number of watchers in this extension, e.g "3".
+ ExtensionUsageRegistry extensions_;
Lei Zhang 2012/12/15 04:13:21 |extensions_watch_count_map_| ?
kmadhusu 2012/12/17 23:58:05 Done.
+
+ // Total number of watchers.
+ unsigned int ref_count_;
Lei Zhang 2012/12/15 04:13:21 Do you have to manually refcount?
kmadhusu 2012/12/17 23:58:05 Fixed. GalleryFilePathWatch inherits from RefCount
+
+ // Used to manage the gallery changed events.
+ base::Time last_gallery_changed_event_;
Lei Zhang 2012/12/15 04:13:21 This should be per-extension. Extension AA has a
kmadhusu 2012/12/17 23:58:05 Done.
+
+ // Make sure all the member functions are called on the right thread.
+ base::ThreadChecker thread_check_;
+
+ // Used to provide a weak pointer to FilePathWatcher callback.
+ base::WeakPtrFactory<GalleryFilePathWatcher> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GalleryFilePathWatcher);
+ };
+
+ // Current profile.
+ const Profile* profile_;
+
+ // Map to manage the gallery file path watchers.
+ // Key: Gallery watch path.
+ // Value: GalleryFilePathWatcher*.
+ WatcherMap gallery_watchers_;
+
+ // Make sure all the member functions are called on the right thread.
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(GalleryWatchManager);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698