Index: chrome/browser/media_gallery/media_galleries_preferences.h |
diff --git a/chrome/browser/media_gallery/media_galleries_preferences.h b/chrome/browser/media_gallery/media_galleries_preferences.h |
index 076606ec792be90e2f2f6a065ee8929bbd53c501..20aa036ef0ffc1fad79c7a8cac233268fc03841e 100644 |
--- a/chrome/browser/media_gallery/media_galleries_preferences.h |
+++ b/chrome/browser/media_gallery/media_galleries_preferences.h |
@@ -5,7 +5,8 @@ |
#ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
#define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
-#include <list> |
+#include <map> |
+#include <set> |
#include <string> |
#include "base/basictypes.h" |
@@ -20,40 +21,55 @@ namespace base { |
class DictionaryValue; |
} |
+namespace extensions { |
+class Extension; |
+class ExtensionPrefs; |
+} |
+ |
+namespace chrome { |
+ |
typedef uint64 MediaGalleryPrefId; |
+const MediaGalleryPrefId kInvalidMediaGalleryPrefId = 0; |
struct MediaGalleryPermission { |
MediaGalleryPrefId pref_id; |
bool has_permission; |
}; |
-struct MediaGallery { |
- MediaGallery(); |
- ~MediaGallery(); |
+struct MediaGalleryPrefInfo { |
+ enum Type { |
+ kAutoDetected, // Auto added to the list of galleries. |
+ kUserAdded, // Explicitly added by the user. |
+ kBlackListed, // Auto added but then removed by the user. |
+ }; |
- // The ID that uniquely, persistently identifies the gallery. |
- uint64 id; |
- |
- // The directory where the gallery is located, relative to the base path |
- // for the device. |
- FilePath path; |
+ MediaGalleryPrefInfo(); |
+ ~MediaGalleryPrefInfo(); |
- // The base path of the device. |
- FilePath base_path; |
- |
- // A string which identifies the device that the gallery lives on. |
- std::string identifier; |
+ // The ID that identifies this gallery in this Profile. |
+ MediaGalleryPrefId pref_id; |
// The user-visible name of this gallery. |
string16 display_name; |
+ |
+ // A string which uniquely and persistently identifies the device that the |
+ // gallery lives on. |
+ std::string device_id; |
+ |
+ // The root of the gallery, relative to the root of the device. |
+ FilePath path; |
+ |
+ // The type of gallery. |
+ Type type; |
}; |
-// A class to manage the media galleries that the user has added, explicitly or |
-// otherwise. There is one registry per user profile. |
-// TODO(estade): should MediaFileSystemRegistry be merged into this class? |
+typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo> |
+ MediaGalleriesPrefInfoMap; |
+ |
+// A class to manage the media gallery preferences. There is one instance per |
+// user profile. |
class MediaGalleriesPreferences : public ProfileKeyedService { |
public: |
- typedef std::list<MediaGallery> MediaGalleries; |
explicit MediaGalleriesPreferences(Profile* profile); |
virtual ~MediaGalleriesPreferences(); |
@@ -61,15 +77,37 @@ class MediaGalleriesPreferences : public ProfileKeyedService { |
// Builds |remembered_galleries_| from the persistent store. |
void InitFromPrefs(); |
- // Teaches the registry about a new gallery defined by |path| (which should |
- // be a directory). |
- void AddGalleryByPath(const FilePath& path); |
+ // Lookup a media gallery and fill in information about it and return true. |
+ // If the media gallery does not already exist, fill in as much of the |
+ // MediaGalleryPrefInfo struct as we can and return false. |
+ // TODO(vandebo) figure out if we want this to be async, in which case: |
+ // void LookUpGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&)) |
+ bool LookUpGalleryByPath(const FilePath& path, |
+ MediaGalleryPrefInfo* gallery) const; |
+ |
+ // Teaches the registry about a new gallery. |
+ MediaGalleryPrefId AddGallery(const std::string& device_id, |
+ const string16& display_name, |
+ const FilePath& path, |
+ bool user_added); |
+ |
+ // Deprecated: Teach the registry about a user added registry simply from |
+ // the path. |
+ // TODO(vandebo) remove once webui/options doesn't use this anymore. |
+ MediaGalleryPrefId AddGalleryByPath(const FilePath& path); |
// Removes the gallery identified by |id| from the store. |
- void ForgetGalleryById(uint64 id); |
+ void ForgetGalleryById(MediaGalleryPrefId id); |
+ |
+ std::set<MediaGalleryPrefId> GalleriesForExtension( |
+ const extensions::Extension& extension) const; |
- const MediaGalleries& remembered_galleries() const { |
- return remembered_galleries_; |
+ void SetGalleryPermissionForExtension(const extensions::Extension& extension, |
+ MediaGalleryPrefId pref_id, |
+ bool has_permission); |
+ |
+ const MediaGalleriesPrefInfoMap& known_galleries() const { |
+ return known_galleries_; |
} |
// ProfileKeyedService implementation: |
@@ -80,15 +118,22 @@ class MediaGalleriesPreferences : public ProfileKeyedService { |
// Returns true if the media gallery UI is turned on. |
static bool UserInteractionIsEnabled(); |
+ protected: |
+ // For testing. |
+ static string16 ComputeDisplayName(const FilePath& path); |
+ |
private: |
// The profile that owns |this|. |
Profile* profile_; |
// An in-memory cache of known galleries. |
- // TODO(estade): either actually use this, or remove it. |
- MediaGalleries remembered_galleries_; |
+ MediaGalleriesPrefInfoMap known_galleries_; |
+ |
+ extensions::ExtensionPrefs* GetExtensionPrefs() const; |
DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); |
}; |
+} // namespace chrome |
+ |
#endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |