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

Side by Side Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_manager.cc

Issue 23727009: Cleanup: Remove chrome namespace for storage monitor and media galleries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit Created 7 years, 3 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 // GalleryWatchManager implementation. 5 // GalleryWatchManager implementation.
6 6
7 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma nager.h" 7 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma nager.h"
8 8
9 #include <list> 9 #include <list>
10 #include <set> 10 #include <set>
(...skipping 18 matching lines...) Expand all
29 // Map to keep track of profile specific GalleryWatchManager objects. 29 // Map to keep track of profile specific GalleryWatchManager objects.
30 // Key: Profile identifier. 30 // Key: Profile identifier.
31 // Value: GalleryWatchManager*. 31 // Value: GalleryWatchManager*.
32 // This map owns the GalleryWatchManager object. 32 // This map owns the GalleryWatchManager object.
33 typedef std::map<void*, extensions::GalleryWatchManager*> WatchManagerMap; 33 typedef std::map<void*, extensions::GalleryWatchManager*> WatchManagerMap;
34 WatchManagerMap* g_gallery_watch_managers = NULL; 34 WatchManagerMap* g_gallery_watch_managers = NULL;
35 35
36 // Dispatches the gallery changed event on the UI thread. 36 // Dispatches the gallery changed event on the UI thread.
37 void SendGalleryChangedEventOnUIThread( 37 void SendGalleryChangedEventOnUIThread(
38 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router, 38 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router,
39 chrome::MediaGalleryPrefId gallery_id, 39 MediaGalleryPrefId gallery_id,
40 const std::set<std::string>& extension_ids) { 40 const std::set<std::string>& extension_ids) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 if (event_router.get()) 42 if (event_router.get())
43 event_router->OnGalleryChanged(gallery_id, extension_ids); 43 event_router->OnGalleryChanged(gallery_id, extension_ids);
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 /////////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////////
49 // GalleryWatchManager::GalleryFilePathWatcher // 49 // GalleryWatchManager::GalleryFilePathWatcher //
50 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
51 51
52 // This class does a recursive watch on the gallery file path and holds a list 52 // This class does a recursive watch on the gallery file path and holds a list
53 // of extensions that are watching the gallery. When there is a file system 53 // of extensions that are watching the gallery. When there is a file system
54 // activity within the gallery, GalleryFilePathWatcher notifies the interested 54 // activity within the gallery, GalleryFilePathWatcher notifies the interested
55 // extensions. This class lives on the file thread. 55 // extensions. This class lives on the file thread.
56 class GalleryWatchManager::GalleryFilePathWatcher 56 class GalleryWatchManager::GalleryFilePathWatcher
57 : public base::RefCounted<GalleryFilePathWatcher> { 57 : public base::RefCounted<GalleryFilePathWatcher> {
58 public: 58 public:
59 // |on_destroyed_callback| is called when the last GalleryFilePathWatcher 59 // |on_destroyed_callback| is called when the last GalleryFilePathWatcher
60 // reference goes away. 60 // reference goes away.
61 GalleryFilePathWatcher( 61 GalleryFilePathWatcher(
62 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router, 62 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router,
63 chrome::MediaGalleryPrefId gallery_id, 63 MediaGalleryPrefId gallery_id,
64 const base::FilePath& path, 64 const base::FilePath& path,
65 const std::string& extension_id, 65 const std::string& extension_id,
66 const base::Closure& on_destroyed_callback); 66 const base::Closure& on_destroyed_callback);
67 67
68 // Adds the extension reference to the watched gallery. 68 // Adds the extension reference to the watched gallery.
69 void AddExtension(const std::string& extension_id); 69 void AddExtension(const std::string& extension_id);
70 70
71 // Removes the extension reference to the watched gallery. 71 // Removes the extension reference to the watched gallery.
72 void RemoveExtension(const std::string& extension_id); 72 void RemoveExtension(const std::string& extension_id);
73 73
(...skipping 23 matching lines...) Expand all
97 void OnFilePathChanged(const base::FilePath& path, bool error); 97 void OnFilePathChanged(const base::FilePath& path, bool error);
98 98
99 // Remove the watch references for the extension specified by the 99 // Remove the watch references for the extension specified by the
100 // |extension_id|. 100 // |extension_id|.
101 void RemoveExtensionReferences(const std::string& extension_id); 101 void RemoveExtensionReferences(const std::string& extension_id);
102 102
103 // Used to notify the interested extensions about the gallery changed event. 103 // Used to notify the interested extensions about the gallery changed event.
104 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router_; 104 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router_;
105 105
106 // The gallery identifier, e.g "1". 106 // The gallery identifier, e.g "1".
107 chrome::MediaGalleryPrefId gallery_id_; 107 MediaGalleryPrefId gallery_id_;
108 108
109 // The gallery file path watcher. 109 // The gallery file path watcher.
110 base::FilePathWatcher file_watcher_; 110 base::FilePathWatcher file_watcher_;
111 111
112 // The gallery file path, e.g "C:\My Pictures". 112 // The gallery file path, e.g "C:\My Pictures".
113 base::FilePath gallery_path_; 113 base::FilePath gallery_path_;
114 114
115 // A callback to call when |this| object is destroyed. 115 // A callback to call when |this| object is destroyed.
116 base::Closure on_destroyed_callback_; 116 base::Closure on_destroyed_callback_;
117 117
118 // Map to keep track of the extension and its corresponding watch count. 118 // Map to keep track of the extension and its corresponding watch count.
119 ExtensionWatchInfoMap extension_watch_info_map_; 119 ExtensionWatchInfoMap extension_watch_info_map_;
120 120
121 // Used to provide a weak pointer to FilePathWatcher callback. 121 // Used to provide a weak pointer to FilePathWatcher callback.
122 base::WeakPtrFactory<GalleryFilePathWatcher> weak_ptr_factory_; 122 base::WeakPtrFactory<GalleryFilePathWatcher> weak_ptr_factory_;
123 123
124 DISALLOW_COPY_AND_ASSIGN(GalleryFilePathWatcher); 124 DISALLOW_COPY_AND_ASSIGN(GalleryFilePathWatcher);
125 }; 125 };
126 126
127 GalleryWatchManager::GalleryFilePathWatcher::GalleryFilePathWatcher( 127 GalleryWatchManager::GalleryFilePathWatcher::GalleryFilePathWatcher(
128 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router, 128 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router,
129 chrome::MediaGalleryPrefId gallery_id, 129 MediaGalleryPrefId gallery_id,
130 const base::FilePath& path, 130 const base::FilePath& path,
131 const std::string& extension_id, 131 const std::string& extension_id,
132 const base::Closure& on_destroyed_callback) 132 const base::Closure& on_destroyed_callback)
133 : event_router_(event_router), 133 : event_router_(event_router),
134 gallery_id_(gallery_id), 134 gallery_id_(gallery_id),
135 on_destroyed_callback_(on_destroyed_callback), 135 on_destroyed_callback_(on_destroyed_callback),
136 weak_ptr_factory_(this) { 136 weak_ptr_factory_(this) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
138 gallery_path_ = path; 138 gallery_path_ = path;
139 AddExtension(extension_id); 139 AddExtension(extension_id);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return; 269 return;
270 delete it->second; 270 delete it->second;
271 g_gallery_watch_managers->erase(it); 271 g_gallery_watch_managers->erase(it);
272 if (g_gallery_watch_managers->empty()) 272 if (g_gallery_watch_managers->empty())
273 delete g_gallery_watch_managers; 273 delete g_gallery_watch_managers;
274 } 274 }
275 275
276 // static 276 // static
277 bool GalleryWatchManager::SetupGalleryWatch( 277 bool GalleryWatchManager::SetupGalleryWatch(
278 void* profile_id, 278 void* profile_id,
279 chrome::MediaGalleryPrefId gallery_id, 279 MediaGalleryPrefId gallery_id,
280 const base::FilePath& watch_path, 280 const base::FilePath& watch_path,
281 const std::string& extension_id, 281 const std::string& extension_id,
282 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router) { 282 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
284 return GalleryWatchManager::GetForProfile(profile_id)->StartGalleryWatch( 284 return GalleryWatchManager::GetForProfile(profile_id)->StartGalleryWatch(
285 gallery_id, watch_path, extension_id, event_router); 285 gallery_id, watch_path, extension_id, event_router);
286 } 286 }
287 287
288 // static 288 // static
289 void GalleryWatchManager::RemoveGalleryWatch(void* profile_id, 289 void GalleryWatchManager::RemoveGalleryWatch(void* profile_id,
(...skipping 18 matching lines...) Expand all
308 GalleryWatchManager::GalleryWatchManager() { 308 GalleryWatchManager::GalleryWatchManager() {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
310 } 310 }
311 311
312 GalleryWatchManager::~GalleryWatchManager() { 312 GalleryWatchManager::~GalleryWatchManager() {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
314 DeleteAllWatchers(); 314 DeleteAllWatchers();
315 } 315 }
316 316
317 bool GalleryWatchManager::StartGalleryWatch( 317 bool GalleryWatchManager::StartGalleryWatch(
318 chrome::MediaGalleryPrefId gallery_id, 318 MediaGalleryPrefId gallery_id,
319 const base::FilePath& watch_path, 319 const base::FilePath& watch_path,
320 const std::string& extension_id, 320 const std::string& extension_id,
321 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router) { 321 base::WeakPtr<MediaGalleriesPrivateEventRouter> event_router) {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
323 WatcherMap::const_iterator iter = gallery_watchers_.find(watch_path); 323 WatcherMap::const_iterator iter = gallery_watchers_.find(watch_path);
324 if (iter != gallery_watchers_.end()) { 324 if (iter != gallery_watchers_.end()) {
325 // Already watched. 325 // Already watched.
326 iter->second->AddExtension(extension_id); 326 iter->second->AddExtension(extension_id);
327 return true; 327 return true;
328 } 328 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 iter->second->RemoveAllWatchReferences(); 384 iter->second->RemoveAllWatchReferences();
385 } 385 }
386 386
387 void GalleryWatchManager::RemoveGalleryFilePathWatcherEntry( 387 void GalleryWatchManager::RemoveGalleryFilePathWatcherEntry(
388 const base::FilePath& watch_path) { 388 const base::FilePath& watch_path) {
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
390 gallery_watchers_.erase(watch_path); 390 gallery_watchers_.erase(watch_path);
391 } 391 }
392 392
393 } // namespace extensions 393 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698