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

Side by Side Diff: chrome/browser/media_gallery/media_galleries_preferences.h

Issue 10821077: Add gallery permissions to Media Galleries Preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Media from method names and fix LookUpGalleryById Created 8 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 static const MediaGalleryPrefId kInvalidPrefId = 0;
35 uint64 id;
36 46
37 // The directory where the gallery is located, relative to the base path 47 MediaGalleryPrefInfo();
38 // for the device. 48 ~MediaGalleryPrefInfo();
39 FilePath path;
40 49
41 // The base path of the device. 50 // The ID that identifies this gallery in this Profile.
42 FilePath base_path; 51 MediaGalleryPrefId pref_id;
43
44 // A string which identifies the device that the gallery lives on.
45 std::string identifier;
46 52
47 // The user-visible name of this gallery. 53 // The user-visible name of this gallery.
48 string16 display_name; 54 string16 display_name;
55
56 // A string which uniquely and persistently identifies the device that the
57 // gallery lives on.
58 std::string device_id;
59
60 // The root of the gallery, relative to the root of the device.
61 FilePath path;
62
63 // The type of gallery.
64 Type type;
49 }; 65 };
50 66
51 // A class to manage the media galleries that the user has added, explicitly or 67 typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo>
52 // otherwise. There is one registry per user profile. 68 MediaGalleriesPrefInfoMap;
53 // TODO(estade): should MediaFileSystemRegistry be merged into this class? 69
70 // A class to manage the media gallery preferences. There is one registry per
71 // user profile.
54 class MediaGalleriesPreferences : public ProfileKeyedService { 72 class MediaGalleriesPreferences : public ProfileKeyedService {
55 public: 73 public:
56 typedef std::list<MediaGallery> MediaGalleries;
57 74
58 explicit MediaGalleriesPreferences(Profile* profile); 75 explicit MediaGalleriesPreferences(Profile* profile);
59 virtual ~MediaGalleriesPreferences(); 76 virtual ~MediaGalleriesPreferences();
60 77
61 // Builds |remembered_galleries_| from the persistent store. 78 // Builds |remembered_galleries_| from the persistent store.
62 void InitFromPrefs(); 79 void InitFromPrefs();
63 80
64 // Teaches the registry about a new gallery defined by |path| (which should 81 // Lookup a media gallery and fill in information about it and return true.
65 // be a directory). 82 // If the media gallery does not already exist, fill in as much of the
66 void AddGalleryByPath(const FilePath& path); 83 // MediaGalleryPrefInfo struct as we can and return false.
84 // TODO(vandebo) figure out if we want this to be async, in which case:
85 // void LookUpGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&))
86 bool LookUpGalleryByPath(const FilePath& path,
87 MediaGalleryPrefInfo* gallery) const;
88
89 // Teaches the registry about a new gallery.
90 MediaGalleryPrefId AddGallery(const std::string& device_id,
91 const string16& display_name,
92 const FilePath& path,
93 bool user_added);
94
95 // Teach the registry about a user added registry simply from the path.
96 MediaGalleryPrefId AddGalleryByPath(const FilePath& path);
67 97
68 // Removes the gallery identified by |id| from the store. 98 // Removes the gallery identified by |id| from the store.
69 void ForgetGalleryById(uint64 id); 99 void ForgetGalleryById(MediaGalleryPrefId id);
70 100
71 const MediaGalleries& remembered_galleries() const { 101 std::vector<MediaGalleryPrefId> GalleriesForExtension(
72 return remembered_galleries_; 102 const extensions::Extension& extension) const;
103
104 void SetGalleryPermissionForExtension(const extensions::Extension& extension,
105 MediaGalleryPrefId pref_id,
106 bool has_permission);
107
108 const MediaGalleriesPrefInfoMap& known_galleries() const {
109 return known_galleries_;
73 } 110 }
74 111
75 // ProfileKeyedService implementation: 112 // ProfileKeyedService implementation:
76 virtual void Shutdown() OVERRIDE; 113 virtual void Shutdown() OVERRIDE;
77 114
78 static void RegisterUserPrefs(PrefService* prefs); 115 static void RegisterUserPrefs(PrefService* prefs);
79 116
80 // Returns true if the media gallery UI is turned on. 117 // Returns true if the media gallery UI is turned on.
81 static bool UserInteractionIsEnabled(); 118 static bool UserInteractionIsEnabled();
82 119
83 private: 120 private:
84 // The profile that owns |this|. 121 // The profile that owns |this|.
85 Profile* profile_; 122 Profile* profile_;
86 123
87 // An in-memory cache of known galleries. 124 // An in-memory cache of known galleries.
88 // TODO(estade): either actually use this, or remove it. 125 MediaGalleriesPrefInfoMap known_galleries_;
89 MediaGalleries remembered_galleries_; 126
127 extensions::ExtensionPrefs* GetExtensionPrefs() const;
90 128
91 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); 129 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences);
92 }; 130 };
93 131
132 } // namespace chrome
133
94 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ 134 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698