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

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

Issue 12114019: Media Galleries: Add MediaGalleriesPreferences::GalleryChangeObserver class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/observer_list.h"
14 #include "base/string16.h" 15 #include "base/string16.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h" 16 #include "chrome/browser/profiles/profile_keyed_service.h"
16 17
17 class PrefServiceSyncable; 18 class PrefServiceSyncable;
18 class Profile; 19 class Profile;
19 20
20 namespace base { 21 namespace base {
21 class DictionaryValue; 22 class DictionaryValue;
22 } 23 }
23 24
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 }; 69 };
69 70
70 typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo> 71 typedef std::map<MediaGalleryPrefId, MediaGalleryPrefInfo>
71 MediaGalleriesPrefInfoMap; 72 MediaGalleriesPrefInfoMap;
72 typedef std::set<MediaGalleryPrefId> MediaGalleryPrefIdSet; 73 typedef std::set<MediaGalleryPrefId> MediaGalleryPrefIdSet;
73 74
74 // A class to manage the media gallery preferences. There is one instance per 75 // A class to manage the media gallery preferences. There is one instance per
75 // user profile. 76 // user profile.
76 class MediaGalleriesPreferences : public ProfileKeyedService { 77 class MediaGalleriesPreferences : public ProfileKeyedService {
77 public: 78 public:
79 class GalleryChangeObserver {
80 public:
81 virtual void OnGalleryChanged(MediaGalleriesPreferences* pref) {}
82
83 protected:
84 virtual ~GalleryChangeObserver();
85 };
86
78 explicit MediaGalleriesPreferences(Profile* profile); 87 explicit MediaGalleriesPreferences(Profile* profile);
79 virtual ~MediaGalleriesPreferences(); 88 virtual ~MediaGalleriesPreferences();
80 89
90 void AddGalleryChangeObserver(GalleryChangeObserver* observer);
91 void RemoveGalleryChangeObserver(GalleryChangeObserver* observer);
92
81 // Lookup a media gallery and fill in information about it and return true. 93 // Lookup a media gallery and fill in information about it and return true.
82 // If the media gallery does not already exist, fill in as much of the 94 // If the media gallery does not already exist, fill in as much of the
83 // MediaGalleryPrefInfo struct as we can and return false. 95 // MediaGalleryPrefInfo struct as we can and return false.
84 // TODO(vandebo) figure out if we want this to be async, in which case: 96 // TODO(vandebo) figure out if we want this to be async, in which case:
85 // void LookUpGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&)) 97 // void LookUpGalleryByPath(FilePath&path, callback(const MediaGalleryInfo&))
86 bool LookUpGalleryByPath(const FilePath& path, 98 bool LookUpGalleryByPath(const FilePath& path,
87 MediaGalleryPrefInfo* gallery) const; 99 MediaGalleryPrefInfo* gallery) const;
88 100
89 MediaGalleryPrefIdSet LookUpGalleriesByDeviceId( 101 MediaGalleryPrefIdSet LookUpGalleriesByDeviceId(
90 const std::string& device_id) const; 102 const std::string& device_id) const;
91 103
92 // Teaches the registry about a new gallery. 104 // Teaches the registry about a new gallery.
105 // Returns the gallery's pref id.
93 MediaGalleryPrefId AddGallery(const std::string& device_id, 106 MediaGalleryPrefId AddGallery(const std::string& device_id,
94 const string16& display_name, 107 const string16& display_name,
95 const FilePath& relative_path, 108 const FilePath& relative_path,
96 bool user_added); 109 bool user_added);
97 110
98 // Teach the registry about a user added registry simply from the path. 111 // Teach the registry about a user added registry simply from the path.
112 // Returns the gallery's pref id.
99 MediaGalleryPrefId AddGalleryByPath(const FilePath& path); 113 MediaGalleryPrefId AddGalleryByPath(const FilePath& path);
100 114
101 // Removes the gallery identified by |id| from the store. 115 // Removes the gallery identified by |id| from the store.
102 void ForgetGalleryById(MediaGalleryPrefId id); 116 void ForgetGalleryById(MediaGalleryPrefId id);
103 117
104 MediaGalleryPrefIdSet GalleriesForExtension( 118 MediaGalleryPrefIdSet GalleriesForExtension(
105 const extensions::Extension& extension) const; 119 const extensions::Extension& extension) const;
106 120
107 void SetGalleryPermissionForExtension(const extensions::Extension& extension, 121 void SetGalleryPermissionForExtension(const extensions::Extension& extension,
108 MediaGalleryPrefId pref_id, 122 MediaGalleryPrefId pref_id,
(...skipping 14 matching lines...) Expand all
123 static bool APIHasBeenUsed(Profile* profile); 137 static bool APIHasBeenUsed(Profile* profile);
124 138
125 private: 139 private:
126 typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet> 140 typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet>
127 DeviceIdPrefIdsMap; 141 DeviceIdPrefIdsMap;
128 142
129 // Populates the default galleries if this is a fresh profile. 143 // Populates the default galleries if this is a fresh profile.
130 void AddDefaultGalleriesIfFreshProfile(); 144 void AddDefaultGalleriesIfFreshProfile();
131 145
132 // Builds |known_galleries_| from the persistent store. 146 // Builds |known_galleries_| from the persistent store.
133 void InitFromPrefs(); 147 // Notifies GalleryChangeObservers if |notify_observers| is true.
148 void InitFromPrefs(bool notify_observers);
149
150 // Notifies |gallery_change_observers_| about changes in |known_galleries_|.
151 void NotifyChangeObservers();
152
153 extensions::ExtensionPrefs* GetExtensionPrefs() const;
134 154
135 // The profile that owns |this|. 155 // The profile that owns |this|.
136 Profile* profile_; 156 Profile* profile_;
137 157
138 // An in-memory cache of known galleries. 158 // An in-memory cache of known galleries.
139 MediaGalleriesPrefInfoMap known_galleries_; 159 MediaGalleriesPrefInfoMap known_galleries_;
140 160
141 // A mapping from device id to the set of gallery pref ids on that device. 161 // A mapping from device id to the set of gallery pref ids on that device.
142 // All pref ids in |device_map_| are also in |known_galleries_|. 162 // All pref ids in |device_map_| are also in |known_galleries_|.
143 DeviceIdPrefIdsMap device_map_; 163 DeviceIdPrefIdsMap device_map_;
144 164
145 extensions::ExtensionPrefs* GetExtensionPrefs() const; 165 ObserverList<GalleryChangeObserver> gallery_change_observers_;
146 166
147 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences); 167 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferences);
148 }; 168 };
149 169
150 } // namespace chrome 170 } // namespace chrome
151 171
152 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_ 172 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_PREFERENCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698