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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.h

Issue 7745051: Added refresh on filesystem change (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Flacky test Created 9 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 30 matching lines...) Expand all
41 // MountLibrary::Observer overrides. 41 // MountLibrary::Observer overrides.
42 virtual void DiskChanged(chromeos::MountLibraryEventType event, 42 virtual void DiskChanged(chromeos::MountLibraryEventType event,
43 const chromeos::MountLibrary::Disk* disk) OVERRIDE; 43 const chromeos::MountLibrary::Disk* disk) OVERRIDE;
44 virtual void DeviceChanged(chromeos::MountLibraryEventType event, 44 virtual void DeviceChanged(chromeos::MountLibraryEventType event,
45 const std::string& device_path) OVERRIDE; 45 const std::string& device_path) OVERRIDE;
46 virtual void MountCompleted(chromeos::MountLibrary::MountEvent event_type, 46 virtual void MountCompleted(chromeos::MountLibrary::MountEvent event_type,
47 chromeos::MountError error_code, 47 chromeos::MountError error_code,
48 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE; 48 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE;
49 49
50 private: 50 private:
51 typedef struct FileWatcherExtensions {
52 FileWatcherExtensions(const FilePath& path,
53 const std::string& extension_id) {
54 file_watcher.reset(new base::files::FilePathWatcher());
55 virtual_path = path;
56 extensions.insert(extension_id);
57 }
58 ~FileWatcherExtensions() {}
59 linked_ptr<base::files::FilePathWatcher> file_watcher;
60 FilePath local_path;
61 FilePath virtual_path;
62 std::set<std::string> extensions;
63 } FileWatcherProcess;
64 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap;
65
66 // Helper class for passing through file watch notification events. 51 // Helper class for passing through file watch notification events.
67 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { 52 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate {
68 public: 53 public:
69 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router); 54 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router);
70 55
71 private: 56 private:
72 // base::files::FilePathWatcher::Delegate overrides. 57 // base::files::FilePathWatcher::Delegate overrides.
73 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; 58 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
74 virtual void OnFilePathError(const FilePath& path) OVERRIDE; 59 virtual void OnFilePathError(const FilePath& path) OVERRIDE;
75 60
76 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); 61 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error);
77 62
78 ExtensionFileBrowserEventRouter* router_; 63 ExtensionFileBrowserEventRouter* router_;
79 }; 64 };
80 65
66 typedef std::map<std::string, int> ExtensionUsageRegistry;
67
68 class FileWatcherExtensions {
69 public:
70 FileWatcherExtensions(const FilePath& path,
71 const std::string& extension_id);
72
73 ~FileWatcherExtensions() {}
74
75 void AddExtension(const std::string& extension_id);
76
77 void RemoveExtension(const std::string& extension_id);
78
79 const ExtensionUsageRegistry& GetExtensions() const;
80
81 unsigned int GetRefCount() const;
82
83 const FilePath& GetVirtualPath() const;
84
85 bool Watch(const FilePath& path, FileWatcherDelegate* delegate);
86
87 private:
88 linked_ptr<base::files::FilePathWatcher> file_watcher;
89 FilePath local_path;
90 FilePath virtual_path;
91 ExtensionUsageRegistry extensions;
92 unsigned int ref_count;
93 };
94
95 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap;
96
81 // USB mount event handlers. 97 // USB mount event handlers.
82 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); 98 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk);
83 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); 99 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk);
84 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); 100 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk);
85 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); 101 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk);
86 void OnDeviceAdded(const std::string& device_path); 102 void OnDeviceAdded(const std::string& device_path);
87 void OnDeviceRemoved(const std::string& device_path); 103 void OnDeviceRemoved(const std::string& device_path);
88 void OnDeviceScanned(const std::string& device_path); 104 void OnDeviceScanned(const std::string& device_path);
89 void OnFormattingStarted(const std::string& device_path, bool success); 105 void OnFormattingStarted(const std::string& device_path, bool success);
90 void OnFormattingFinished(const std::string& device_path, bool success); 106 void OnFormattingFinished(const std::string& device_path, bool success);
91 107
92 // Process file watch notifications. 108 // Process file watch notifications.
93 void HandleFileWatchNotification(const FilePath& path, 109 void HandleFileWatchNotification(const FilePath& path,
94 bool got_error); 110 bool got_error);
95 111
96 // Sends folder change event. 112 // Sends folder change event.
97 void DispatchFolderChangeEvent(const FilePath& path, bool error, 113 void DispatchFolderChangeEvent(const FilePath& path, bool error,
98 const std::set<std::string>& extensions); 114 const ExtensionUsageRegistry& extensions);
99 115
100 // Sends filesystem changed extension message to all renderers. 116 // Sends filesystem changed extension message to all renderers.
101 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added); 117 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added);
102 118
103 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, 119 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event,
104 chromeos::MountError error_code, 120 chromeos::MountError error_code,
105 const chromeos::MountLibrary::MountPointInfo& mount_info); 121 const chromeos::MountLibrary::MountPointInfo& mount_info);
106 122
107 void RemoveBrowserFromVector(const std::string& path); 123 void RemoveBrowserFromVector(const std::string& path);
108 124
109 // Used to create a window of a standard size, and add it to a list 125 // Used to create a window of a standard size, and add it to a list
110 // of tracked browser windows in case that device goes away. 126 // of tracked browser windows in case that device goes away.
111 void OpenFileBrowse(const std::string& url, 127 void OpenFileBrowse(const std::string& url,
112 const std::string& device_path, 128 const std::string& device_path,
113 bool small); 129 bool small);
114 130
115 scoped_refptr<FileWatcherDelegate> delegate_; 131 scoped_refptr<FileWatcherDelegate> delegate_;
116 WatcherMap file_watchers_; 132 WatcherMap file_watchers_;
117 scoped_ptr<FileBrowserNotifications> notifications_; 133 scoped_ptr<FileBrowserNotifications> notifications_;
118 Profile* profile_; 134 Profile* profile_;
119 base::Lock lock_; 135 base::Lock lock_;
120 136
121 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); 137 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter);
122 }; 138 };
123 139
124 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 140 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698