Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/string16.h" | 14 #include "base/string16.h" |
| 14 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 15 | 16 |
| 16 class PrefService; | 17 class PrefService; |
| 17 class Profile; | 18 class Profile; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class DictionaryValue; | 21 class DictionaryValue; |
| 21 } | 22 } |
| 22 | 23 |
| 24 namespace extensions { | |
| 25 class Extension; | |
| 26 class ExtensionPrefs; | |
| 27 } | |
| 28 | |
| 29 namespace chrome { | |
| 30 | |
| 23 typedef uint64 MediaGalleryPrefId; | 31 typedef uint64 MediaGalleryPrefId; |
| 24 | 32 |
| 25 struct MediaGalleryPermission { | 33 struct MediaGalleryPermission { |
| 26 MediaGalleryPrefId pref_id; | 34 MediaGalleryPrefId pref_id; |
| 27 bool has_permission; | 35 bool has_permission; |
| 28 }; | 36 }; |
| 29 | 37 |
| 30 struct MediaGallery { | 38 struct MediaGalleryPrefInfo { |
| 31 MediaGallery(); | 39 enum Type { |
| 32 ~MediaGallery(); | 40 kAutoDetected, // Auto added to the list of galleries. |
| 41 kUserAdded, // Explicitly added by the user. | |
| 42 kBlackListed, // Auto added but then removed by the user. | |
| 43 }; | |
| 33 | 44 |
| 34 // The ID that uniquely, persistently identifies the gallery. | 45 MediaGalleryPrefInfo(); |
| 35 uint64 id; | 46 ~MediaGalleryPrefInfo(); |
| 36 | 47 |
| 37 // The directory where the gallery is located, relative to the base path | 48 // The ID that identifies this gallery in this Profile. |
| 38 // for the device. | 49 MediaGalleryPrefId pref_id; |
| 39 FilePath path; | |
| 40 | |
| 41 // The base path of the device. | |
| 42 FilePath base_path; | |
| 43 | |
| 44 // A string which identifies the device that the gallery lives on. | |
| 45 std::string identifier; | |
| 46 | 50 |
| 47 // The user-visible name of this gallery. | 51 // The user-visible name of this gallery. |
| 48 string16 display_name; | 52 string16 display_name; |
| 53 | |
| 54 // A string which uniquely and persistently identifies the device that the | |
| 55 // gallery lives on. | |
| 56 std::string device_id; | |
| 57 | |
| 58 // The root of the gallery, relative to the root of the device. | |
| 59 FilePath path; | |
| 60 | |
| 61 // The type of gallery. | |
| 62 Type type; | |
| 49 }; | 63 }; |
| 50 | 64 |
| 51 // A class to manage the media galleries that the user has added, explicitly or | 65 typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo> |
| 52 // otherwise. There is one registry per user profile. | 66 MediaGalleriesPrefInfoMap; |
| 53 // TODO(estade): should MediaFileSystemRegistry be merged into this class? | 67 |
| 68 // A class to manage the media gallery preferences. There is one registry per | |
| 69 // user profile. | |
| 54 class MediaGalleriesPreferences : public ProfileKeyedService { | 70 class MediaGalleriesPreferences : public ProfileKeyedService { |
| 55 public: | 71 public: |
| 56 typedef std::list<MediaGallery> MediaGalleries; | |
| 57 | 72 |
| 58 explicit MediaGalleriesPreferences(Profile* profile); | 73 explicit MediaGalleriesPreferences(Profile* profile); |
| 59 virtual ~MediaGalleriesPreferences(); | 74 virtual ~MediaGalleriesPreferences(); |
| 60 | 75 |
| 61 // Builds |remembered_galleries_| from the persistent store. | 76 // Builds |remembered_galleries_| from the persistent store. |
| 62 void InitFromPrefs(); | 77 void InitFromPrefs(); |
| 63 | 78 |
| 64 // Teaches the registry about a new gallery defined by |path| (which should | 79 // Lookup a gallery and fill in information about it, or return false. |
| 65 // be a directory). | 80 // TODO(vandebo) figure out if we want this to be async, in which case: |
| 66 void AddGalleryByPath(const FilePath& path); | 81 // void LookupGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&)) |
| 82 bool LookupGalleryByPath(const FilePath& path, | |
|
Evan Stade
2012/08/02 17:47:31
I thought we said that this would never fail, rath
vandebo (ex-Chrome)
2012/08/02 17:51:38
Oops... right, I'll fix that.
vandebo (ex-Chrome)
2012/08/02 18:26:02
Done.
| |
| 83 MediaGalleryPrefInfo* gallery) const; | |
| 84 | |
| 85 // Teaches the registry about a new gallery. | |
| 86 MediaGalleryPrefId AddMediaGallery(const std::string& device_id, | |
| 87 const string16& display_name, | |
| 88 const FilePath& path, | |
|
Evan Stade
2012/08/02 17:47:31
why take 3 of the members of a MediaGalleryPrefInf
vandebo (ex-Chrome)
2012/08/02 17:51:38
Because not all the fields can be valid and becaus
Evan Stade
2012/08/02 18:00:54
are these "some callers" real or hypothetical?
vandebo (ex-Chrome)
2012/08/02 18:26:02
Doesn't matter, my point is that I think it's bad
Evan Stade
2012/08/02 18:36:35
Technically, you could get rid of the AddMediaGall
| |
| 89 bool user_added); | |
| 90 | |
| 91 // Teach the registry about a user added registry simply from the path. | |
| 92 MediaGalleryPrefId AddMediaGalleryByPath(const FilePath& path); | |
| 67 | 93 |
| 68 // Removes the gallery identified by |id| from the store. | 94 // Removes the gallery identified by |id| from the store. |
| 69 void ForgetGalleryById(uint64 id); | 95 void ForgetMediaGalleryById(MediaGalleryPrefId id); |
| 70 | 96 |
| 71 const MediaGalleries& remembered_galleries() const { | 97 std::vector<MediaGalleryPrefId> MediaGalleriesForExtension( |
| 72 return remembered_galleries_; | 98 const extensions::Extension& extension) const; |
| 99 | |
| 100 void SetMediaGalleryPermissionForExtension( | |
| 101 const extensions::Extension& extension, | |
| 102 MediaGalleryPrefId pref_id, | |
| 103 bool has_permission); | |
| 104 | |
| 105 const MediaGalleriesPrefInfoMap& known_galleries() const { | |
| 106 return known_galleries_; | |
| 73 } | 107 } |
| 74 | 108 |
| 75 // ProfileKeyedService implementation: | 109 // ProfileKeyedService implementation: |
| 76 virtual void Shutdown() OVERRIDE; | 110 virtual void Shutdown() OVERRIDE; |
| 77 | 111 |
| 78 static void RegisterUserPrefs(PrefService* prefs); | 112 static void RegisterUserPrefs(PrefService* prefs); |
| 79 | 113 |
| 80 // Returns true if the media gallery UI is turned on. | 114 // Returns true if the media gallery UI is turned on. |
| 81 static bool UserInteractionIsEnabled(); | 115 static bool UserInteractionIsEnabled(); |
| 82 | 116 |
| 83 private: | 117 private: |
| 84 // The profile that owns |this|. | 118 // The profile that owns |this|. |
| 85 Profile* profile_; | 119 Profile* profile_; |
| 86 | 120 |
| 87 // An in-memory cache of known galleries. | 121 // An in-memory cache of known galleries. |
| 88 // TODO(estade): either actually use this, or remove it. | 122 MediaGalleriesPrefInfoMap known_galleries_; |
| 89 MediaGalleries remembered_galleries_; | 123 |
| 124 extensions::ExtensionPrefs* GetExtensionPrefs() const; | |
| 90 | 125 |
| 91 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); | 126 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); |
| 92 }; | 127 }; |
| 93 | 128 |
| 129 } // namespace chrome | |
| 130 | |
| 94 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ | 131 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
| OLD | NEW |