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 // GalleryWatchStateTracker tracks the gallery watchers, updates the | 5 // GalleryWatchStateTracker tracks the gallery watchers, updates the |
6 // extension state storage and observes the notification events. | 6 // extension state storage and observes the notification events. |
7 // GalleryWatchStateTracker lives on the UI thread. | 7 // GalleryWatchStateTracker lives on the UI thread. |
8 | 8 |
9 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_STAT E_TRACKER_H_ | 9 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_STAT E_TRACKER_H_ |
10 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_STAT E_TRACKER_H_ | 10 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_STAT E_TRACKER_H_ |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 18 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 | 21 |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class Value; | 25 class Value; |
26 } | 26 } |
27 | 27 |
28 namespace chrome { | |
29 class MediaGalleriesPreferences; | |
30 } | |
31 | |
28 namespace extensions { | 32 namespace extensions { |
29 | 33 |
30 class GalleryWatchStateTracker | 34 class GalleryWatchStateTracker |
31 : public content::NotificationObserver, | 35 : public content::NotificationObserver, |
32 public base::SupportsWeakPtr<GalleryWatchStateTracker> { | 36 public base::SupportsWeakPtr<GalleryWatchStateTracker> { |
33 public: | 37 public: |
34 explicit GalleryWatchStateTracker(Profile* profile); | 38 explicit GalleryWatchStateTracker(Profile* profile); |
35 virtual ~GalleryWatchStateTracker(); | 39 virtual ~GalleryWatchStateTracker(); |
36 | 40 |
37 // Returns the GalleryWatchStateTracker associated with the |profile|. | 41 // Returns the GalleryWatchStateTracker associated with the |profile|. |
(...skipping 21 matching lines...) Expand all Loading... | |
59 | 63 |
60 // Returns a set of watched gallery identifiers for the extension specified | 64 // Returns a set of watched gallery identifiers for the extension specified |
61 // by the |extension_id|. | 65 // by the |extension_id|. |
62 chrome::MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( | 66 chrome::MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( |
63 const std::string& extension_id) const; | 67 const std::string& extension_id) const; |
64 | 68 |
65 // Removes all the gallery watchers associated with the extension specified | 69 // Removes all the gallery watchers associated with the extension specified |
66 // by the |extension_id|. | 70 // by the |extension_id|. |
67 void RemoveAllGalleryWatchersForExtension(const std::string& extension_id); | 71 void RemoveAllGalleryWatchersForExtension(const std::string& extension_id); |
68 | 72 |
73 // Once we learn the preferences, set them in the tracker. | |
74 void SetPreferences(chrome::MediaGalleriesPreferences* preferences); | |
75 | |
69 private: | 76 private: |
70 // Key: Gallery identifier. | 77 // Key: Gallery identifier. |
71 // Value: True if the watcher is active. Watcher will be active only if | 78 // Value: True if the watcher is active. Watcher will be active only if |
72 // the extension has access permission to the watched gallery and a watcher | 79 // the extension has access permission to the watched gallery and a watcher |
73 // has been successfully setup. | 80 // has been successfully setup. |
74 typedef std::map<chrome::MediaGalleryPrefId, bool> WatchedGalleriesMap; | 81 typedef std::map<chrome::MediaGalleryPrefId, bool> WatchedGalleriesMap; |
75 | 82 |
76 // Key: Extension identifier. | 83 // Key: Extension identifier. |
77 // Value: Map of watched gallery information. | 84 // Value: Map of watched gallery information. |
78 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap; | 85 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap; |
79 | 86 |
80 // content::NotificationObserver implementation. | 87 // content::NotificationObserver implementation. |
81 virtual void Observe(int type, | 88 virtual void Observe(int type, |
82 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) OVERRIDE; | 90 const content::NotificationDetails& details) OVERRIDE; |
84 | 91 |
85 // Syncs media gallery watch data for the given extension to/from the state | 92 // Syncs media gallery watch data for the given extension to/from the state |
86 // storage. | 93 // storage. |
87 void WriteToStorage(const std::string& extension_id); | 94 void WriteToStorage(const std::string& extension_id); |
88 void ReadFromStorage(const std::string& extension_id, | 95 void ReadFromStorage(const std::string& extension_id, |
89 scoped_ptr<base::Value> value); | 96 scoped_ptr<base::Value> value); |
97 void ReadFromStorageWithPreferences( | |
98 const std::string& extension_id, | |
99 chrome::MediaGalleryPrefIdSet gallery_ids, | |
100 chrome::MediaGalleriesPreferences* preferences); | |
90 | 101 |
91 // Sets up the gallery watcher on the receipt of granted gallery permission | 102 // Sets up the gallery watcher on the receipt of granted gallery permission |
92 // event. | 103 // event. |
93 void SetupGalleryWatch(const std::string& extension_id, | 104 void SetupGalleryWatch(const std::string& extension_id, |
94 chrome::MediaGalleryPrefId gallery_id); | 105 chrome::MediaGalleryPrefId gallery_id); |
95 | 106 |
96 // Removes the gallery watcher on the receipt of revoked gallery permission | 107 // Removes the gallery watcher on the receipt of revoked gallery permission |
97 // event. | 108 // event. |
98 void RemoveGalleryWatch(const std::string& extension_id, | 109 void RemoveGalleryWatch(const std::string& extension_id, |
99 chrome::MediaGalleryPrefId gallery_id); | 110 chrome::MediaGalleryPrefId gallery_id); |
(...skipping 15 matching lines...) Expand all Loading... | |
115 // extension specified by the |extension_id|. Returns true if the |gallery_id| | 126 // extension specified by the |extension_id|. Returns true if the |gallery_id| |
116 // is added into the |watched_extensions_map_| and returns false if the | 127 // is added into the |watched_extensions_map_| and returns false if the |
117 // |gallery_id| already exists in the |watched_extensions_map_|. | 128 // |gallery_id| already exists in the |watched_extensions_map_|. |
118 bool AddWatchedGalleryIdInfoForExtension( | 129 bool AddWatchedGalleryIdInfoForExtension( |
119 const std::string& extension_id, | 130 const std::string& extension_id, |
120 chrome::MediaGalleryPrefId gallery_id); | 131 chrome::MediaGalleryPrefId gallery_id); |
121 | 132 |
122 // Current profile. | 133 // Current profile. |
123 Profile* profile_; | 134 Profile* profile_; |
124 | 135 |
136 // The preferences object from which we get gallery information. | |
vandebo (ex-Chrome)
2013/05/16 18:56:27
I assume the lifetime of this class is such that w
Greg Billock
2013/05/16 23:27:55
Both are effectively profile scoped, but there may
| |
137 chrome::MediaGalleriesPreferences* preferences_; | |
138 | |
125 // Used to listen for NOTIFICATION_EXTENSION_LOADED and | 139 // Used to listen for NOTIFICATION_EXTENSION_LOADED and |
126 // NOTIFICATION_EXTENSION_UNLOADED events. | 140 // NOTIFICATION_EXTENSION_UNLOADED events. |
127 content::NotificationRegistrar registrar_; | 141 content::NotificationRegistrar registrar_; |
128 | 142 |
129 // A map of watched gallery details, per extension. | 143 // A map of watched gallery details, per extension. |
130 WatchedExtensionsMap watched_extensions_map_; | 144 WatchedExtensionsMap watched_extensions_map_; |
131 | 145 |
132 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); | 146 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); |
133 }; | 147 }; |
134 | 148 |
135 } // namespace extensions | 149 } // namespace extensions |
136 | 150 |
137 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S TATE_TRACKER_H_ | 151 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S TATE_TRACKER_H_ |
OLD | NEW |