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|. |
38 // Returns NULL if GalleryWatchStateTracker does not exists. | 42 // Returns NULL if GalleryWatchStateTracker does not exists. |
39 static GalleryWatchStateTracker* GetForProfile(Profile* profile); | 43 static GalleryWatchStateTracker* GetForProfile(Profile* profile); |
40 | 44 |
41 // Updates the storage for the given extension on the receipt of gallery | 45 // Updates the storage for the given extension on the receipt of gallery |
42 // watch added event. | 46 // watch added event. |
43 void OnGalleryWatchAdded(const std::string& extension_id, | 47 void OnGalleryWatchAdded(const std::string& extension_id, |
44 chrome::MediaGalleryPrefId gallery_id); | 48 chrome::MediaGalleryPrefId gallery_id); |
45 | 49 |
46 // Updates the storage for the given extension on the receipt of gallery | 50 // Updates the storage for the given extension on the receipt of gallery |
47 // watch removed event. | 51 // watch removed event. |
48 void OnGalleryWatchRemoved(const std::string& extension_id, | 52 void OnGalleryWatchRemoved(const std::string& extension_id, |
49 chrome::MediaGalleryPrefId gallery_id); | 53 chrome::MediaGalleryPrefId gallery_id); |
50 | 54 |
51 // Updates the state of the gallery watchers on the receipt of access | 55 // Updates the state of the gallery watchers on the receipt of access |
52 // permission changed event for the extension specified by the |extension_id|. | 56 // permission changed event for the extension specified by the |extension_id|. |
53 // |has_permission| is set to true if the user granted permission to | 57 // |has_permission| is set to true if the user granted permission to |
54 // access the gallery associated with the |gallery_id| and is set to false | 58 // access the gallery associated with the |gallery_id| and is set to false |
55 // if the user revoked the gallery permission. | 59 // if the user revoked the gallery permission. |
56 void OnGalleryPermissionChanged(const std::string& extension_id, | 60 void OnGalleryPermissionChanged( |
57 chrome::MediaGalleryPrefId gallery_id, | 61 const std::string& extension_id, |
58 bool has_permission); | 62 chrome::MediaGalleryPrefId gallery_id, |
| 63 bool has_permission, |
| 64 chrome::MediaGalleriesPreferences* preferences); |
59 | 65 |
60 // Returns a set of watched gallery identifiers for the extension specified | 66 // Returns a set of watched gallery identifiers for the extension specified |
61 // by the |extension_id|. | 67 // by the |extension_id|. |
62 chrome::MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( | 68 chrome::MediaGalleryPrefIdSet GetAllWatchedGalleryIDsForExtension( |
63 const std::string& extension_id) const; | 69 const std::string& extension_id) const; |
64 | 70 |
65 // Removes all the gallery watchers associated with the extension specified | 71 // Removes all the gallery watchers associated with the extension specified |
66 // by the |extension_id|. | 72 // by the |extension_id|. |
67 void RemoveAllGalleryWatchersForExtension(const std::string& extension_id); | 73 void RemoveAllGalleryWatchersForExtension(const std::string& extension_id); |
68 | 74 |
(...skipping 11 matching lines...) Expand all Loading... |
80 // content::NotificationObserver implementation. | 86 // content::NotificationObserver implementation. |
81 virtual void Observe(int type, | 87 virtual void Observe(int type, |
82 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) OVERRIDE; | 89 const content::NotificationDetails& details) OVERRIDE; |
84 | 90 |
85 // Syncs media gallery watch data for the given extension to/from the state | 91 // Syncs media gallery watch data for the given extension to/from the state |
86 // storage. | 92 // storage. |
87 void WriteToStorage(const std::string& extension_id); | 93 void WriteToStorage(const std::string& extension_id); |
88 void ReadFromStorage(const std::string& extension_id, | 94 void ReadFromStorage(const std::string& extension_id, |
89 scoped_ptr<base::Value> value); | 95 scoped_ptr<base::Value> value); |
| 96 void ReadFromStorageWithPreferences( |
| 97 const std::string& extension_id, |
| 98 chrome::MediaGalleryPrefIdSet gallery_ids, |
| 99 chrome::MediaGalleriesPreferences* preferences); |
| 100 |
| 101 // Bottom half of |RemoveAllGalleryWatchersForExtension| called |
| 102 // after we retrieve the preferences for the profile. |
| 103 void RemoveAllGalleryWatchersWithPreferences( |
| 104 const std::string& extension_id, |
| 105 chrome::MediaGalleriesPreferences* preferences); |
90 | 106 |
91 // Sets up the gallery watcher on the receipt of granted gallery permission | 107 // Sets up the gallery watcher on the receipt of granted gallery permission |
92 // event. | 108 // event. |
93 void SetupGalleryWatch(const std::string& extension_id, | 109 void SetupGalleryWatch(const std::string& extension_id, |
94 chrome::MediaGalleryPrefId gallery_id); | 110 chrome::MediaGalleryPrefId gallery_id, |
| 111 chrome::MediaGalleriesPreferences* preferences); |
95 | 112 |
96 // Removes the gallery watcher on the receipt of revoked gallery permission | 113 // Removes the gallery watcher on the receipt of revoked gallery permission |
97 // event. | 114 // event. |
98 void RemoveGalleryWatch(const std::string& extension_id, | 115 void RemoveGalleryWatch(const std::string& extension_id, |
99 chrome::MediaGalleryPrefId gallery_id); | 116 chrome::MediaGalleryPrefId gallery_id, |
| 117 chrome::MediaGalleriesPreferences* preferences); |
100 | 118 |
101 // Returns true if a gallery watcher exists for the extension. | 119 // Returns true if a gallery watcher exists for the extension. |
102 // Set |has_active_watcher| to true to find if the gallery watcher is active. | 120 // Set |has_active_watcher| to true to find if the gallery watcher is active. |
103 bool HasGalleryWatchInfo(const std::string& extension_id, | 121 bool HasGalleryWatchInfo(const std::string& extension_id, |
104 chrome::MediaGalleryPrefId gallery_id, | 122 chrome::MediaGalleryPrefId gallery_id, |
105 bool has_active_watcher); | 123 bool has_active_watcher); |
106 | 124 |
107 // Handles the setup gallery watch request response. When an extension is | 125 // Handles the setup gallery watch request response. When an extension is |
108 // loaded, GalleryWatchStateTracker reads the storage and sends request to | 126 // loaded, GalleryWatchStateTracker reads the storage and sends request to |
109 // setup gallery watchers for the known watch paths. | 127 // setup gallery watchers for the known watch paths. |
(...skipping 18 matching lines...) Expand all Loading... |
128 | 146 |
129 // A map of watched gallery details, per extension. | 147 // A map of watched gallery details, per extension. |
130 WatchedExtensionsMap watched_extensions_map_; | 148 WatchedExtensionsMap watched_extensions_map_; |
131 | 149 |
132 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); | 150 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); |
133 }; | 151 }; |
134 | 152 |
135 } // namespace extensions | 153 } // namespace extensions |
136 | 154 |
137 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S
TATE_TRACKER_H_ | 155 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S
TATE_TRACKER_H_ |
OLD | NEW |