Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/files/file_path_watcher.h" | 13 #include "base/files/file_path_watcher.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "chrome/browser/chromeos/cros/mount_library.h" | 18 #include "chrome/browser/chromeos/cros/mount_library.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 class SystemNotification; | 23 class SystemNotification; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Used to monitor disk mount changes and signal when new mounted usb device is | 26 // Used to monitor disk mount changes and signal when new mounted usb device is |
| 27 // found. | 27 // found. |
| 28 class ExtensionFileBrowserEventRouter | 28 class ExtensionFileBrowserEventRouter |
| 29 : public chromeos::MountLibrary::Observer { | 29 : public chromeos::MountLibrary::Observer { |
| 30 | |
| 31 friend void HideFileBrowserNotificationExternally( | |
| 32 const std::string& cathegory, const std::string& system_path, | |
| 33 ExtensionFileBrowserEventRouter* that); | |
| 34 | |
| 30 public: | 35 public: |
| 31 static ExtensionFileBrowserEventRouter* GetInstance(); | 36 static ExtensionFileBrowserEventRouter* GetInstance(); |
| 32 | 37 |
| 33 // Starts/stops observing file system change events. Currently only | 38 // Starts/stops observing file system change events. Currently only |
| 34 // MountLibrary events are being observed. | 39 // MountLibrary events are being observed. |
| 35 void ObserveFileSystemEvents(Profile* profile); | 40 void ObserveFileSystemEvents(Profile* profile); |
| 36 void StopObservingFileSystemEvents(); | 41 void StopObservingFileSystemEvents(); |
| 37 | 42 |
| 38 // File watch setup routines. | 43 // File watch setup routines. |
| 39 bool AddFileWatch(const FilePath& file_path, | 44 bool AddFileWatch(const FilePath& file_path, |
| 40 const FilePath& virtual_path, | 45 const FilePath& virtual_path, |
| 41 const std::string& extension_id); | 46 const std::string& extension_id); |
| 42 void RemoveFileWatch(const FilePath& file_path, | 47 void RemoveFileWatch(const FilePath& file_path, |
| 43 const std::string& extension_id); | 48 const std::string& extension_id); |
| 44 | 49 |
| 45 // MountLibrary::Observer overrides. | 50 // MountLibrary::Observer overrides. |
| 46 virtual void DiskChanged(chromeos::MountLibraryEventType event, | 51 virtual void DiskChanged(chromeos::MountLibraryEventType event, |
| 47 const chromeos::MountLibrary::Disk* disk); | 52 const chromeos::MountLibrary::Disk* disk); |
| 48 virtual void DeviceChanged(chromeos::MountLibraryEventType event, | 53 virtual void DeviceChanged(chromeos::MountLibraryEventType event, |
| 49 const std::string& device_path); | 54 const std::string& device_path); |
| 50 | 55 |
| 51 private: | 56 private: |
| 52 friend struct DefaultSingletonTraits<ExtensionFileBrowserEventRouter>; | 57 friend struct DefaultSingletonTraits<ExtensionFileBrowserEventRouter>; |
| 53 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > | 58 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > |
| 54 NotificationMap; | 59 NotificationMap; |
| 55 typedef std::map<std::string, std::string> MountPointMap; | 60 typedef std::map<std::string, std::string> MountPointMap; |
| 56 typedef struct FileWatcherExtensions { | 61 typedef struct FileWatcherExtensions { |
| 57 FileWatcherExtensions(const FilePath& path, const std::string& extension_id) { | 62 FileWatcherExtensions(const FilePath& path, |
| 63 const std::string& extension_id) { | |
| 58 file_watcher.reset(new base::files::FilePathWatcher()); | 64 file_watcher.reset(new base::files::FilePathWatcher()); |
| 59 virtual_path = path; | 65 virtual_path = path; |
| 60 extensions.insert(extension_id); | 66 extensions.insert(extension_id); |
| 61 } | 67 } |
| 62 ~FileWatcherExtensions() {} | 68 ~FileWatcherExtensions() {} |
| 63 linked_ptr<base::files::FilePathWatcher> file_watcher; | 69 linked_ptr<base::files::FilePathWatcher> file_watcher; |
| 64 FilePath local_path; | 70 FilePath local_path; |
| 65 FilePath virtual_path; | 71 FilePath virtual_path; |
| 66 std::set<std::string> extensions; | 72 std::set<std::string> extensions; |
| 67 } FileWatcherProcess; | 73 } FileWatcherProcess; |
| 68 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; | 74 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; |
| 69 | 75 |
| 70 // Helper class for passing through file watch notification events. | 76 // Helper class for passing through file watch notification events. |
| 71 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { | 77 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { |
| 72 public: | 78 public: |
| 73 FileWatcherDelegate(); | 79 FileWatcherDelegate(); |
| 74 | 80 |
| 75 private: | 81 private: |
| 76 // base::files::FilePathWatcher::Delegate overrides. | 82 // base::files::FilePathWatcher::Delegate overrides. |
| 77 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; | 83 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
| 78 virtual void OnFilePathError(const FilePath& path) OVERRIDE; | 84 virtual void OnFilePathError(const FilePath& path) OVERRIDE; |
| 79 | 85 |
| 80 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 86 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
| 81 }; | 87 }; |
| 82 | 88 |
| 83 ExtensionFileBrowserEventRouter(); | 89 ExtensionFileBrowserEventRouter(); |
| 84 virtual ~ExtensionFileBrowserEventRouter(); | 90 virtual ~ExtensionFileBrowserEventRouter(); |
| 85 | 91 |
| 86 // USB mount event handlers. | 92 // USB mount event handlers. |
| 87 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 93 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); |
|
achuithb
2011/07/21 00:58:21
These should all be virtual with OVERRIDE, I belie
sidor
2011/07/21 18:24:15
I didn't write this piece of code, I just added th
achuithb
2011/07/21 22:02:32
https://groups.google.com/a/chromium.org/group/chr
| |
| 88 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 94 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); |
| 89 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); | 95 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); |
| 96 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); | |
| 97 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); | |
| 90 void OnDeviceAdded(const std::string& device_path); | 98 void OnDeviceAdded(const std::string& device_path); |
| 91 void OnDeviceRemoved(const std::string& device_path); | 99 void OnDeviceRemoved(const std::string& device_path); |
| 92 void OnDeviceScanned(const std::string& device_path); | 100 void OnDeviceScanned(const std::string& device_path); |
| 101 void OnFormattingStarted(const std::string& device_path); | |
| 102 void OnFormattingFinished(const std::string& device_path); | |
| 93 | 103 |
| 94 // Finds first notifications corresponding to the same device. Ensures that | 104 // Finds first notifications corresponding to the same device. Ensures that |
| 95 // we don't pop up multiple notifications for the same device. | 105 // we don't pop up multiple notifications for the same device. |
| 96 NotificationMap::iterator FindNotificationForPath(const std::string& path); | 106 NotificationMap::iterator FindNotificationForPath(const std::string& path); |
| 97 | 107 |
| 98 // Process file watch notifications. | 108 // Process file watch notifications. |
| 99 void HandleFileWatchNotification(const FilePath& path, | 109 void HandleFileWatchNotification(const FilePath& path, |
| 100 bool got_error); | 110 bool got_error); |
| 101 | 111 |
| 102 // Sends folder change event. | 112 // Sends folder change event. |
| 103 void DispatchFolderChangeEvent(const FilePath& path, bool error, | 113 void DispatchFolderChangeEvent(const FilePath& path, bool error, |
| 104 const std::set<std::string>& extensions); | 114 const std::set<std::string>& extensions); |
| 105 | 115 |
| 106 // Sends filesystem changed extension message to all renderers. | 116 // Sends filesystem changed extension message to all renderers. |
| 107 void DispatchMountEvent(const chromeos::MountLibrary::Disk* disk, bool added); | 117 void DispatchMountEvent(const chromeos::MountLibrary::Disk* disk, bool added); |
| 108 | 118 |
| 109 void RemoveBrowserFromVector(const std::string& path); | 119 void RemoveBrowserFromVector(const std::string& path); |
| 110 | 120 |
| 111 // Used to create a window of a standard size, and add it to a list | 121 // Used to create a window of a standard size, and add it to a list |
| 112 // of tracked browser windows in case that device goes away. | 122 // of tracked browser windows in case that device goes away. |
| 113 void OpenFileBrowse(const std::string& url, | 123 void OpenFileBrowse(const std::string& url, |
| 114 const std::string& device_path, | 124 const std::string& device_path, |
| 115 bool small); | 125 bool small); |
| 116 | 126 |
| 117 // Show/hide desktop notifications. | 127 // Show/hide desktop notifications. |
| 118 void ShowDeviceNotification(const std::string& system_path, | 128 void ShowFileBrowserNotification(const std::string& cathegory, |
|
achuithb
2011/07/21 00:58:21
category
sidor
2011/07/21 18:24:15
Done.
| |
| 119 int icon_resource_id, | 129 const std::string& system_path, |
| 120 const string16& message); | 130 int icon_resource_id, |
| 121 void HideDeviceNotification(const std::string& system_path); | 131 const string16& title, |
| 132 const string16& message); | |
| 133 void HideFileBrowserNotification(const std::string& cathegory, | |
| 134 const std::string& system_path); | |
| 122 | 135 |
| 123 scoped_refptr<FileWatcherDelegate> delegate_; | 136 scoped_refptr<FileWatcherDelegate> delegate_; |
| 124 MountPointMap mounted_devices_; | 137 MountPointMap mounted_devices_; |
| 125 NotificationMap notifications_; | 138 NotificationMap notifications_; |
| 126 WatcherMap file_watchers_; | 139 WatcherMap file_watchers_; |
| 127 Profile* profile_; | 140 Profile* profile_; |
| 128 base::Lock lock_; | 141 base::Lock lock_; |
| 129 | 142 |
| 130 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 143 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
| 131 }; | 144 }; |
| 132 | 145 |
| 133 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 146 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |