| 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& category, const std::string& system_path, |
| 33 ExtensionFileBrowserEventRouter* that); |
| 34 |
| 30 public: | 35 public: |
| 31 explicit ExtensionFileBrowserEventRouter(Profile* profile); | 36 explicit ExtensionFileBrowserEventRouter(Profile* profile); |
| 32 virtual ~ExtensionFileBrowserEventRouter(); | 37 virtual ~ExtensionFileBrowserEventRouter(); |
| 33 // Starts observing file system change events. Currently only | 38 // Starts observing file system change events. Currently only |
| 34 // MountLibrary events are being observed. | 39 // MountLibrary events are being observed. |
| 35 void ObserveFileSystemEvents(); | 40 void ObserveFileSystemEvents(); |
| 36 | 41 |
| 37 // File watch setup routines. | 42 // File watch setup routines. |
| 38 bool AddFileWatch(const FilePath& file_path, | 43 bool AddFileWatch(const FilePath& file_path, |
| 39 const FilePath& virtual_path, | 44 const FilePath& virtual_path, |
| 40 const std::string& extension_id); | 45 const std::string& extension_id); |
| 41 void RemoveFileWatch(const FilePath& file_path, | 46 void RemoveFileWatch(const FilePath& file_path, |
| 42 const std::string& extension_id); | 47 const std::string& extension_id); |
| 43 | 48 |
| 44 // MountLibrary::Observer overrides. | 49 // MountLibrary::Observer overrides. |
| 45 virtual void DiskChanged(chromeos::MountLibraryEventType event, | 50 virtual void DiskChanged(chromeos::MountLibraryEventType event, |
| 46 const chromeos::MountLibrary::Disk* disk) OVERRIDE; | 51 const chromeos::MountLibrary::Disk* disk) OVERRIDE; |
| 47 virtual void DeviceChanged(chromeos::MountLibraryEventType event, | 52 virtual void DeviceChanged(chromeos::MountLibraryEventType event, |
| 48 const std::string& device_path) OVERRIDE; | 53 const std::string& device_path) OVERRIDE; |
| 49 | 54 |
| 50 virtual void MountCompleted(chromeos::MountLibrary::MountEvent event_type, | 55 virtual void MountCompleted(chromeos::MountLibrary::MountEvent event_type, |
| 51 chromeos::MountError error_code, | 56 chromeos::MountError error_code, |
| 52 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE; | 57 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE; |
| 53 | 58 |
| 54 private: | 59 private: |
| 55 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > | 60 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > |
| 56 NotificationMap; | 61 NotificationMap; |
| 57 typedef std::map<std::string, std::string> MountPointMap; | 62 typedef std::map<std::string, std::string> MountPointMap; |
| 58 typedef struct FileWatcherExtensions { | 63 typedef struct FileWatcherExtensions { |
| 59 FileWatcherExtensions(const FilePath& path, const std::string& extension_id)
{ | 64 FileWatcherExtensions(const FilePath& path, |
| 65 const std::string& extension_id) { |
| 60 file_watcher.reset(new base::files::FilePathWatcher()); | 66 file_watcher.reset(new base::files::FilePathWatcher()); |
| 61 virtual_path = path; | 67 virtual_path = path; |
| 62 extensions.insert(extension_id); | 68 extensions.insert(extension_id); |
| 63 } | 69 } |
| 64 ~FileWatcherExtensions() {} | 70 ~FileWatcherExtensions() {} |
| 65 linked_ptr<base::files::FilePathWatcher> file_watcher; | 71 linked_ptr<base::files::FilePathWatcher> file_watcher; |
| 66 FilePath local_path; | 72 FilePath local_path; |
| 67 FilePath virtual_path; | 73 FilePath virtual_path; |
| 68 std::set<std::string> extensions; | 74 std::set<std::string> extensions; |
| 69 } FileWatcherProcess; | 75 } FileWatcherProcess; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 | 87 |
| 82 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 88 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
| 83 | 89 |
| 84 ExtensionFileBrowserEventRouter* router_; | 90 ExtensionFileBrowserEventRouter* router_; |
| 85 }; | 91 }; |
| 86 | 92 |
| 87 // USB mount event handlers. | 93 // USB mount event handlers. |
| 88 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 94 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); |
| 89 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 95 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); |
| 90 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); | 96 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); |
| 97 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); |
| 98 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); |
| 91 void OnDeviceAdded(const std::string& device_path); | 99 void OnDeviceAdded(const std::string& device_path); |
| 92 void OnDeviceRemoved(const std::string& device_path); | 100 void OnDeviceRemoved(const std::string& device_path); |
| 93 void OnDeviceScanned(const std::string& device_path); | 101 void OnDeviceScanned(const std::string& device_path); |
| 102 void OnFormattingStarted(const std::string& device_path); |
| 103 void OnFormattingFinished(const std::string& device_path); |
| 94 | 104 |
| 95 // Finds first notifications corresponding to the same device. Ensures that | 105 // Finds first notifications corresponding to the same device. Ensures that |
| 96 // we don't pop up multiple notifications for the same device. | 106 // we don't pop up multiple notifications for the same device. |
| 97 NotificationMap::iterator FindNotificationForPath(const std::string& path); | 107 NotificationMap::iterator FindNotificationForId(const std::string& path); |
| 98 | 108 |
| 99 // Process file watch notifications. | 109 // Process file watch notifications. |
| 100 void HandleFileWatchNotification(const FilePath& path, | 110 void HandleFileWatchNotification(const FilePath& path, |
| 101 bool got_error); | 111 bool got_error); |
| 102 | 112 |
| 103 // Sends folder change event. | 113 // Sends folder change event. |
| 104 void DispatchFolderChangeEvent(const FilePath& path, bool error, | 114 void DispatchFolderChangeEvent(const FilePath& path, bool error, |
| 105 const std::set<std::string>& extensions); | 115 const std::set<std::string>& extensions); |
| 106 | 116 |
| 107 // Sends filesystem changed extension message to all renderers. | 117 // Sends filesystem changed extension message to all renderers. |
| 108 void DispatchMountEvent(const chromeos::MountLibrary::Disk* disk, bool added); | 118 void DispatchMountEvent(const chromeos::MountLibrary::Disk* disk, bool added); |
| 109 | 119 |
| 110 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, | 120 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, |
| 111 chromeos::MountError error_code, | 121 chromeos::MountError error_code, |
| 112 const chromeos::MountLibrary::MountPointInfo& mount_info); | 122 const chromeos::MountLibrary::MountPointInfo& mount_info); |
| 113 | 123 |
| 114 void RemoveBrowserFromVector(const std::string& path); | 124 void RemoveBrowserFromVector(const std::string& path); |
| 115 | 125 |
| 116 // Used to create a window of a standard size, and add it to a list | 126 // Used to create a window of a standard size, and add it to a list |
| 117 // of tracked browser windows in case that device goes away. | 127 // of tracked browser windows in case that device goes away. |
| 118 void OpenFileBrowse(const std::string& url, | 128 void OpenFileBrowse(const std::string& url, |
| 119 const std::string& device_path, | 129 const std::string& device_path, |
| 120 bool small); | 130 bool small); |
| 121 | 131 |
| 122 // Show/hide desktop notifications. | 132 // Show/hide desktop notifications. |
| 123 void ShowDeviceNotification(const std::string& system_path, | 133 void ShowFileBrowserNotification(const std::string& category, |
| 124 int icon_resource_id, | 134 const std::string& system_path, |
| 125 const string16& message); | 135 int icon_resource_id, |
| 126 void HideDeviceNotification(const std::string& system_path); | 136 const string16& title, |
| 137 const string16& message); |
| 138 void HideFileBrowserNotification(const std::string& category, |
| 139 const std::string& system_path); |
| 127 | 140 |
| 128 scoped_refptr<FileWatcherDelegate> delegate_; | 141 scoped_refptr<FileWatcherDelegate> delegate_; |
| 129 MountPointMap mounted_devices_; | 142 MountPointMap mounted_devices_; |
| 130 NotificationMap notifications_; | 143 NotificationMap notifications_; |
| 131 WatcherMap file_watchers_; | 144 WatcherMap file_watchers_; |
| 132 Profile* profile_; | 145 Profile* profile_; |
| 133 base::Lock lock_; | 146 base::Lock lock_; |
| 134 | 147 |
| 135 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 148 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
| 136 }; | 149 }; |
| 137 | 150 |
| 138 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 151 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |