| 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_ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class Value; | 25 class Value; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 | 29 |
| 30 // This class is owned by the MediaGalleriesPrivateAPI, and is created on demand | 30 // This class is owned by the MediaGalleriesPrivateAPI, and is created on demand |
| 31 // along with the MediaGalleriesPrivateEventRouter. | 31 // along with the MediaGalleriesPrivateEventRouter. |
| 32 class GalleryWatchStateTracker | 32 class GalleryWatchStateTracker |
| 33 : public content::NotificationObserver, | 33 : public content::NotificationObserver, |
| 34 public base::SupportsWeakPtr<GalleryWatchStateTracker>, | 34 public base::SupportsWeakPtr<GalleryWatchStateTracker>, |
| 35 public chrome::MediaGalleriesPreferences::GalleryChangeObserver { | 35 public MediaGalleriesPreferences::GalleryChangeObserver { |
| 36 public: | 36 public: |
| 37 explicit GalleryWatchStateTracker(Profile* profile); | 37 explicit GalleryWatchStateTracker(Profile* profile); |
| 38 virtual ~GalleryWatchStateTracker(); | 38 virtual ~GalleryWatchStateTracker(); |
| 39 | 39 |
| 40 // Returns the GalleryWatchStateTracker associated with the |profile|. | 40 // Returns the GalleryWatchStateTracker associated with the |profile|. |
| 41 // Returns NULL if GalleryWatchStateTracker does not exists. | 41 // Returns NULL if GalleryWatchStateTracker does not exists. |
| 42 static GalleryWatchStateTracker* GetForProfile(Profile* profile); | 42 static GalleryWatchStateTracker* GetForProfile(Profile* profile); |
| 43 | 43 |
| 44 // Updates the storage for the given extension on the receipt of gallery | 44 // Updates the storage for the given extension on the receipt of gallery |
| 45 // watch added event. | 45 // watch added event. |
| 46 void OnGalleryWatchAdded(const std::string& extension_id, | 46 void OnGalleryWatchAdded(const std::string& extension_id, |
| 47 chrome::MediaGalleryPrefId gallery_id); | 47 MediaGalleryPrefId gallery_id); |
| 48 | 48 |
| 49 // Updates the storage for the given extension on the receipt of gallery | 49 // Updates the storage for the given extension on the receipt of gallery |
| 50 // watch removed event. | 50 // watch removed event. |
| 51 void OnGalleryWatchRemoved(const std::string& extension_id, | 51 void OnGalleryWatchRemoved(const std::string& extension_id, |
| 52 chrome::MediaGalleryPrefId gallery_id); | 52 MediaGalleryPrefId gallery_id); |
| 53 | 53 |
| 54 // Updates the state of the gallery watchers on the receipt of access | 54 // Updates the state of the gallery watchers on the receipt of access |
| 55 // permission changed event for the extension specified by the |extension_id|. | 55 // permission changed event for the extension specified by the |extension_id|. |
| 56 // If |extension_id| is empty, the callback is a global event | 56 // If |extension_id| is empty, the callback is a global event |
| 57 // which this class is not interested in. | 57 // which this class is not interested in. |
| 58 // |has_permission| is set to true if the user granted permission to | 58 // |has_permission| is set to true if the user granted permission to |
| 59 // access the gallery associated with the |gallery_id| and is set to false | 59 // access the gallery associated with the |gallery_id| and is set to false |
| 60 // if the user revoked the gallery permission. | 60 // if the user revoked the gallery permission. |
| 61 virtual void OnGalleryChanged( | 61 virtual void OnGalleryChanged(MediaGalleriesPreferences* pref, |
| 62 chrome::MediaGalleriesPreferences* pref, | 62 const std::string& extension_id, |
| 63 const std::string& extension_id, | 63 MediaGalleryPrefId gallery_id, |
| 64 chrome::MediaGalleryPrefId gallery_id, | 64 bool has_permission) OVERRIDE; |
| 65 bool has_permission) OVERRIDE; | |
| 66 | 65 |
| 67 // Returns a set of watched gallery identifiers for the extension specified | 66 // Returns a set of watched gallery identifiers for the extension specified |
| 68 // by the |extension_id|. | 67 // by the |extension_id|. |
| 69 chrome::MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( | 68 MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( |
| 70 const std::string& extension_id) const; | 69 const std::string& extension_id) const; |
| 71 | 70 |
| 72 // Removes all the gallery watchers associated with the extension specified | 71 // Removes all the gallery watchers associated with the extension specified |
| 73 // by the |extension_id|. | 72 // by the |extension_id|. |
| 74 void RemoveAllGalleryWatchersForExtension( | 73 void RemoveAllGalleryWatchersForExtension( |
| 75 const std::string& extension_id, | 74 const std::string& extension_id, |
| 76 chrome::MediaGalleriesPreferences* preferences); | 75 MediaGalleriesPreferences* preferences); |
| 77 | 76 |
| 78 private: | 77 private: |
| 79 // Key: Gallery identifier. | 78 // Key: Gallery identifier. |
| 80 // Value: True if the watcher is active. Watcher will be active only if | 79 // Value: True if the watcher is active. Watcher will be active only if |
| 81 // the extension has access permission to the watched gallery and a watcher | 80 // the extension has access permission to the watched gallery and a watcher |
| 82 // has been successfully setup. | 81 // has been successfully setup. |
| 83 typedef std::map<chrome::MediaGalleryPrefId, bool> WatchedGalleriesMap; | 82 typedef std::map<MediaGalleryPrefId, bool> WatchedGalleriesMap; |
| 84 | 83 |
| 85 // Key: Extension identifier. | 84 // Key: Extension identifier. |
| 86 // Value: Map of watched gallery information. | 85 // Value: Map of watched gallery information. |
| 87 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap; | 86 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap; |
| 88 | 87 |
| 89 // content::NotificationObserver implementation. | 88 // content::NotificationObserver implementation. |
| 90 virtual void Observe(int type, | 89 virtual void Observe(int type, |
| 91 const content::NotificationSource& source, | 90 const content::NotificationSource& source, |
| 92 const content::NotificationDetails& details) OVERRIDE; | 91 const content::NotificationDetails& details) OVERRIDE; |
| 93 | 92 |
| 94 // Syncs media gallery watch data for the given extension to/from the state | 93 // Syncs media gallery watch data for the given extension to/from the state |
| 95 // storage. | 94 // storage. |
| 96 void WriteToStorage(const std::string& extension_id); | 95 void WriteToStorage(const std::string& extension_id); |
| 97 void ReadFromStorage(const std::string& extension_id, | 96 void ReadFromStorage(const std::string& extension_id, |
| 98 scoped_ptr<base::Value> value); | 97 scoped_ptr<base::Value> value); |
| 99 | 98 |
| 100 // Sets up the gallery watcher on the receipt of granted gallery permission | 99 // Sets up the gallery watcher on the receipt of granted gallery permission |
| 101 // event. | 100 // event. |
| 102 void SetupGalleryWatch(const std::string& extension_id, | 101 void SetupGalleryWatch(const std::string& extension_id, |
| 103 chrome::MediaGalleryPrefId gallery_id, | 102 MediaGalleryPrefId gallery_id, |
| 104 chrome::MediaGalleriesPreferences* preferences); | 103 MediaGalleriesPreferences* preferences); |
| 105 | 104 |
| 106 // Removes the gallery watcher on the receipt of revoked gallery permission | 105 // Removes the gallery watcher on the receipt of revoked gallery permission |
| 107 // event. | 106 // event. |
| 108 void RemoveGalleryWatch(const std::string& extension_id, | 107 void RemoveGalleryWatch(const std::string& extension_id, |
| 109 chrome::MediaGalleryPrefId gallery_id, | 108 MediaGalleryPrefId gallery_id, |
| 110 chrome::MediaGalleriesPreferences* preferences); | 109 MediaGalleriesPreferences* preferences); |
| 111 | 110 |
| 112 // Returns true if a gallery watcher exists for the extension. | 111 // Returns true if a gallery watcher exists for the extension. |
| 113 // Set |has_active_watcher| to true to find if the gallery watcher is active. | 112 // Set |has_active_watcher| to true to find if the gallery watcher is active. |
| 114 bool HasGalleryWatchInfo(const std::string& extension_id, | 113 bool HasGalleryWatchInfo(const std::string& extension_id, |
| 115 chrome::MediaGalleryPrefId gallery_id, | 114 MediaGalleryPrefId gallery_id, |
| 116 bool has_active_watcher); | 115 bool has_active_watcher); |
| 117 | 116 |
| 118 // Handles the setup gallery watch request response. When an extension is | 117 // Handles the setup gallery watch request response. When an extension is |
| 119 // loaded, GalleryWatchStateTracker reads the storage and sends request to | 118 // loaded, GalleryWatchStateTracker reads the storage and sends request to |
| 120 // setup gallery watchers for the known watch paths. | 119 // setup gallery watchers for the known watch paths. |
| 121 void HandleSetupGalleryWatchResponse(const std::string& extension_id, | 120 void HandleSetupGalleryWatchResponse(const std::string& extension_id, |
| 122 chrome::MediaGalleryPrefId gallery_id, | 121 MediaGalleryPrefId gallery_id, |
| 123 bool success); | 122 bool success); |
| 124 | 123 |
| 125 // Adds the watched |gallery_id| in |watched_extensions_map_| for the | 124 // Adds the watched |gallery_id| in |watched_extensions_map_| for the |
| 126 // extension specified by the |extension_id|. Returns true if the |gallery_id| | 125 // extension specified by the |extension_id|. Returns true if the |gallery_id| |
| 127 // is added into the |watched_extensions_map_| and returns false if the | 126 // is added into the |watched_extensions_map_| and returns false if the |
| 128 // |gallery_id| already exists in the |watched_extensions_map_|. | 127 // |gallery_id| already exists in the |watched_extensions_map_|. |
| 129 bool AddWatchedGalleryIdInfoForExtension( | 128 bool AddWatchedGalleryIdInfoForExtension(const std::string& extension_id, |
| 130 const std::string& extension_id, | 129 MediaGalleryPrefId gallery_id); |
| 131 chrome::MediaGalleryPrefId gallery_id); | |
| 132 | 130 |
| 133 // Current profile. | 131 // Current profile. |
| 134 Profile* profile_; | 132 Profile* profile_; |
| 135 | 133 |
| 136 // Used to listen for NOTIFICATION_EXTENSION_LOADED and | 134 // Used to listen for NOTIFICATION_EXTENSION_LOADED and |
| 137 // NOTIFICATION_EXTENSION_UNLOADED events. | 135 // NOTIFICATION_EXTENSION_UNLOADED events. |
| 138 content::NotificationRegistrar registrar_; | 136 content::NotificationRegistrar registrar_; |
| 139 | 137 |
| 140 // A map of watched gallery details, per extension. | 138 // A map of watched gallery details, per extension. |
| 141 WatchedExtensionsMap watched_extensions_map_; | 139 WatchedExtensionsMap watched_extensions_map_; |
| 142 | 140 |
| 143 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); | 141 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); |
| 144 }; | 142 }; |
| 145 | 143 |
| 146 } // namespace extensions | 144 } // namespace extensions |
| 147 | 145 |
| 148 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S
TATE_TRACKER_H_ | 146 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S
TATE_TRACKER_H_ |
| OLD | NEW |