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 <set> |
9 #include <string> | 10 #include <string> |
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; |
| 32 const MediaGalleryPrefId kInvalidMediaGalleryPrefId = 0; |
24 | 33 |
25 struct MediaGalleryPermission { | 34 struct MediaGalleryPermission { |
26 MediaGalleryPrefId pref_id; | 35 MediaGalleryPrefId pref_id; |
27 bool has_permission; | 36 bool has_permission; |
28 }; | 37 }; |
29 | 38 |
30 struct MediaGallery { | 39 struct MediaGalleryPrefInfo { |
31 MediaGallery(); | 40 enum Type { |
32 ~MediaGallery(); | 41 kAutoDetected, // Auto added to the list of galleries. |
| 42 kUserAdded, // Explicitly added by the user. |
| 43 kBlackListed, // Auto added but then removed by the user. |
| 44 }; |
33 | 45 |
34 // The ID that uniquely, persistently identifies the gallery. | 46 MediaGalleryPrefInfo(); |
35 uint64 id; | 47 ~MediaGalleryPrefInfo(); |
36 | 48 |
37 // The directory where the gallery is located, relative to the base path | 49 // The ID that identifies this gallery in this Profile. |
38 // for the device. | 50 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 | 51 |
47 // The user-visible name of this gallery. | 52 // The user-visible name of this gallery. |
48 string16 display_name; | 53 string16 display_name; |
| 54 |
| 55 // A string which uniquely and persistently identifies the device that the |
| 56 // gallery lives on. |
| 57 std::string device_id; |
| 58 |
| 59 // The root of the gallery, relative to the root of the device. |
| 60 FilePath path; |
| 61 |
| 62 // The type of gallery. |
| 63 Type type; |
49 }; | 64 }; |
50 | 65 |
51 // A class to manage the media galleries that the user has added, explicitly or | 66 typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo> |
52 // otherwise. There is one registry per user profile. | 67 MediaGalleriesPrefInfoMap; |
53 // TODO(estade): should MediaFileSystemRegistry be merged into this class? | 68 |
| 69 // A class to manage the media gallery preferences. There is one instance per |
| 70 // user profile. |
54 class MediaGalleriesPreferences : public ProfileKeyedService { | 71 class MediaGalleriesPreferences : public ProfileKeyedService { |
55 public: | 72 public: |
56 typedef std::list<MediaGallery> MediaGalleries; | |
57 | 73 |
58 explicit MediaGalleriesPreferences(Profile* profile); | 74 explicit MediaGalleriesPreferences(Profile* profile); |
59 virtual ~MediaGalleriesPreferences(); | 75 virtual ~MediaGalleriesPreferences(); |
60 | 76 |
61 // Builds |remembered_galleries_| from the persistent store. | 77 // Builds |remembered_galleries_| from the persistent store. |
62 void InitFromPrefs(); | 78 void InitFromPrefs(); |
63 | 79 |
64 // Teaches the registry about a new gallery defined by |path| (which should | 80 // Lookup a media gallery and fill in information about it and return true. |
65 // be a directory). | 81 // If the media gallery does not already exist, fill in as much of the |
66 void AddGalleryByPath(const FilePath& path); | 82 // MediaGalleryPrefInfo struct as we can and return false. |
| 83 // TODO(vandebo) figure out if we want this to be async, in which case: |
| 84 // void LookUpGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&)) |
| 85 bool LookUpGalleryByPath(const FilePath& path, |
| 86 MediaGalleryPrefInfo* gallery) const; |
| 87 |
| 88 // Teaches the registry about a new gallery. |
| 89 MediaGalleryPrefId AddGallery(const std::string& device_id, |
| 90 const string16& display_name, |
| 91 const FilePath& path, |
| 92 bool user_added); |
| 93 |
| 94 // Deprecated: Teach the registry about a user added registry simply from |
| 95 // the path. |
| 96 // TODO(vandebo) remove once webui/options doesn't use this anymore. |
| 97 MediaGalleryPrefId AddGalleryByPath(const FilePath& path); |
67 | 98 |
68 // Removes the gallery identified by |id| from the store. | 99 // Removes the gallery identified by |id| from the store. |
69 void ForgetGalleryById(uint64 id); | 100 void ForgetGalleryById(MediaGalleryPrefId id); |
70 | 101 |
71 const MediaGalleries& remembered_galleries() const { | 102 std::set<MediaGalleryPrefId> GalleriesForExtension( |
72 return remembered_galleries_; | 103 const extensions::Extension& extension) const; |
| 104 |
| 105 void SetGalleryPermissionForExtension(const extensions::Extension& extension, |
| 106 MediaGalleryPrefId pref_id, |
| 107 bool has_permission); |
| 108 |
| 109 const MediaGalleriesPrefInfoMap& known_galleries() const { |
| 110 return known_galleries_; |
73 } | 111 } |
74 | 112 |
75 // ProfileKeyedService implementation: | 113 // ProfileKeyedService implementation: |
76 virtual void Shutdown() OVERRIDE; | 114 virtual void Shutdown() OVERRIDE; |
77 | 115 |
78 static void RegisterUserPrefs(PrefService* prefs); | 116 static void RegisterUserPrefs(PrefService* prefs); |
79 | 117 |
80 // Returns true if the media gallery UI is turned on. | 118 // Returns true if the media gallery UI is turned on. |
81 static bool UserInteractionIsEnabled(); | 119 static bool UserInteractionIsEnabled(); |
82 | 120 |
| 121 protected: |
| 122 // For testing. |
| 123 static string16 ComputeDisplayName(const FilePath& path); |
| 124 |
83 private: | 125 private: |
84 // The profile that owns |this|. | 126 // The profile that owns |this|. |
85 Profile* profile_; | 127 Profile* profile_; |
86 | 128 |
87 // An in-memory cache of known galleries. | 129 // An in-memory cache of known galleries. |
88 // TODO(estade): either actually use this, or remove it. | 130 MediaGalleriesPrefInfoMap known_galleries_; |
89 MediaGalleries remembered_galleries_; | 131 |
| 132 extensions::ExtensionPrefs* GetExtensionPrefs() const; |
90 | 133 |
91 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); | 134 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); |
92 }; | 135 }; |
93 | 136 |
| 137 } // namespace chrome |
| 138 |
94 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ | 139 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ |
OLD | NEW |