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

Side by Side Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h

Issue 15742010: Use MediaGalleryPreferences directly in GalleryWatchStateTracker interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get preferences for win call Created 7 years, 7 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 // 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 extensions { 28 namespace extensions {
29 29
30 // This class is owned by the MeidaGalleriesPrivateAPI, and is created on demand
Finnur 2013/05/24 09:27:41 nit: s/Meida/Media/
Greg Billock 2013/05/29 16:33:48 Done.
31 // along with the MediaGalleriesPrivateEventRouter.
30 class GalleryWatchStateTracker 32 class GalleryWatchStateTracker
31 : public content::NotificationObserver, 33 : public content::NotificationObserver,
32 public base::SupportsWeakPtr<GalleryWatchStateTracker> { 34 public base::SupportsWeakPtr<GalleryWatchStateTracker> {
33 public: 35 public:
34 explicit GalleryWatchStateTracker(Profile* profile); 36 explicit GalleryWatchStateTracker(Profile* profile);
35 virtual ~GalleryWatchStateTracker(); 37 virtual ~GalleryWatchStateTracker();
36 38
37 // Returns the GalleryWatchStateTracker associated with the |profile|. 39 // Returns the GalleryWatchStateTracker associated with the |profile|.
38 // Returns NULL if GalleryWatchStateTracker does not exists. 40 // Returns NULL if GalleryWatchStateTracker does not exists.
39 static GalleryWatchStateTracker* GetForProfile(Profile* profile); 41 static GalleryWatchStateTracker* GetForProfile(Profile* profile);
40 42
41 // Updates the storage for the given extension on the receipt of gallery 43 // Updates the storage for the given extension on the receipt of gallery
42 // watch added event. 44 // watch added event.
43 void OnGalleryWatchAdded(const std::string& extension_id, 45 void OnGalleryWatchAdded(const std::string& extension_id,
44 chrome::MediaGalleryPrefId gallery_id); 46 chrome::MediaGalleryPrefId gallery_id);
45 47
46 // Updates the storage for the given extension on the receipt of gallery 48 // Updates the storage for the given extension on the receipt of gallery
47 // watch removed event. 49 // watch removed event.
48 void OnGalleryWatchRemoved(const std::string& extension_id, 50 void OnGalleryWatchRemoved(const std::string& extension_id,
49 chrome::MediaGalleryPrefId gallery_id); 51 chrome::MediaGalleryPrefId gallery_id);
50 52
51 // Updates the state of the gallery watchers on the receipt of access 53 // Updates the state of the gallery watchers on the receipt of access
52 // permission changed event for the extension specified by the |extension_id|. 54 // permission changed event for the extension specified by the |extension_id|.
53 // |has_permission| is set to true if the user granted permission to 55 // |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 56 // access the gallery associated with the |gallery_id| and is set to false
55 // if the user revoked the gallery permission. 57 // if the user revoked the gallery permission.
56 void OnGalleryPermissionChanged(const std::string& extension_id, 58 void OnGalleryPermissionChanged(
57 chrome::MediaGalleryPrefId gallery_id, 59 const std::string& extension_id,
58 bool has_permission); 60 chrome::MediaGalleryPrefId gallery_id,
61 bool has_permission,
62 chrome::MediaGalleriesPreferences* preferences);
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(
72 const std::string& extension_id,
73 chrome::MediaGalleriesPreferences* preferences);
68 74
69 private: 75 private:
70 // Key: Gallery identifier. 76 // Key: Gallery identifier.
71 // Value: True if the watcher is active. Watcher will be active only if 77 // 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 78 // the extension has access permission to the watched gallery and a watcher
73 // has been successfully setup. 79 // has been successfully setup.
74 typedef std::map<chrome::MediaGalleryPrefId, bool> WatchedGalleriesMap; 80 typedef std::map<chrome::MediaGalleryPrefId, bool> WatchedGalleriesMap;
75 81
76 // Key: Extension identifier. 82 // Key: Extension identifier.
77 // Value: Map of watched gallery information. 83 // Value: Map of watched gallery information.
78 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap; 84 typedef std::map<std::string, WatchedGalleriesMap> WatchedExtensionsMap;
79 85
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);
90 96
91 // Sets up the gallery watcher on the receipt of granted gallery permission 97 // Sets up the gallery watcher on the receipt of granted gallery permission
92 // event. 98 // event.
93 void SetupGalleryWatch(const std::string& extension_id, 99 void SetupGalleryWatch(const std::string& extension_id,
94 chrome::MediaGalleryPrefId gallery_id); 100 chrome::MediaGalleryPrefId gallery_id,
101 chrome::MediaGalleriesPreferences* preferences);
95 102
96 // Removes the gallery watcher on the receipt of revoked gallery permission 103 // Removes the gallery watcher on the receipt of revoked gallery permission
97 // event. 104 // event.
98 void RemoveGalleryWatch(const std::string& extension_id, 105 void RemoveGalleryWatch(const std::string& extension_id,
99 chrome::MediaGalleryPrefId gallery_id); 106 chrome::MediaGalleryPrefId gallery_id,
107 chrome::MediaGalleriesPreferences* preferences);
100 108
101 // Returns true if a gallery watcher exists for the extension. 109 // 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. 110 // Set |has_active_watcher| to true to find if the gallery watcher is active.
103 bool HasGalleryWatchInfo(const std::string& extension_id, 111 bool HasGalleryWatchInfo(const std::string& extension_id,
104 chrome::MediaGalleryPrefId gallery_id, 112 chrome::MediaGalleryPrefId gallery_id,
105 bool has_active_watcher); 113 bool has_active_watcher);
106 114
107 // Handles the setup gallery watch request response. When an extension is 115 // Handles the setup gallery watch request response. When an extension is
108 // loaded, GalleryWatchStateTracker reads the storage and sends request to 116 // loaded, GalleryWatchStateTracker reads the storage and sends request to
109 // setup gallery watchers for the known watch paths. 117 // setup gallery watchers for the known watch paths.
(...skipping 18 matching lines...) Expand all
128 136
129 // A map of watched gallery details, per extension. 137 // A map of watched gallery details, per extension.
130 WatchedExtensionsMap watched_extensions_map_; 138 WatchedExtensionsMap watched_extensions_map_;
131 139
132 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker); 140 DISALLOW_COPY_AND_ASSIGN(GalleryWatchStateTracker);
133 }; 141 };
134 142
135 } // namespace extensions 143 } // namespace extensions
136 144
137 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S TATE_TRACKER_H_ 145 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_GALLERY_WATCH_S TATE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698