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, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 virtual void OnFilePathError(const FilePath& path) OVERRIDE; | 85 virtual void OnFilePathError(const FilePath& path) OVERRIDE; |
81 | 86 |
82 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 87 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
83 | 88 |
84 ExtensionFileBrowserEventRouter* router_; | 89 ExtensionFileBrowserEventRouter* router_; |
85 }; | 90 }; |
86 | 91 |
87 // USB mount event handlers. | 92 // USB mount event handlers. |
88 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 93 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); |
89 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 94 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); |
| 95 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); |
| 96 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); |
90 void OnDeviceAdded(const std::string& device_path); | 97 void OnDeviceAdded(const std::string& device_path); |
91 void OnDeviceRemoved(const std::string& device_path); | 98 void OnDeviceRemoved(const std::string& device_path); |
92 void OnDeviceScanned(const std::string& device_path); | 99 void OnDeviceScanned(const std::string& device_path); |
| 100 void OnFormattingStarted(const std::string& device_path); |
| 101 void OnFormattingFinished(const std::string& device_path); |
93 | 102 |
94 // Finds first notifications corresponding to the same device. Ensures that | 103 // Finds first notifications corresponding to the same device. Ensures that |
95 // we don't pop up multiple notifications for the same device. | 104 // we don't pop up multiple notifications for the same device. |
96 NotificationMap::iterator FindNotificationForPath(const std::string& path); | 105 NotificationMap::iterator FindNotificationForId(const std::string& path); |
97 | 106 |
98 // Process file watch notifications. | 107 // Process file watch notifications. |
99 void HandleFileWatchNotification(const FilePath& path, | 108 void HandleFileWatchNotification(const FilePath& path, |
100 bool got_error); | 109 bool got_error); |
101 | 110 |
102 // Sends folder change event. | 111 // Sends folder change event. |
103 void DispatchFolderChangeEvent(const FilePath& path, bool error, | 112 void DispatchFolderChangeEvent(const FilePath& path, bool error, |
104 const std::set<std::string>& extensions); | 113 const std::set<std::string>& extensions); |
105 | 114 |
106 // Sends filesystem changed extension message to all renderers. | 115 // Sends filesystem changed extension message to all renderers. |
107 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added); | 116 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added); |
108 | 117 |
109 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, | 118 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, |
110 chromeos::MountError error_code, | 119 chromeos::MountError error_code, |
111 const chromeos::MountLibrary::MountPointInfo& mount_info); | 120 const chromeos::MountLibrary::MountPointInfo& mount_info); |
112 | 121 |
113 void RemoveBrowserFromVector(const std::string& path); | 122 void RemoveBrowserFromVector(const std::string& path); |
114 | 123 |
115 // Used to create a window of a standard size, and add it to a list | 124 // Used to create a window of a standard size, and add it to a list |
116 // of tracked browser windows in case that device goes away. | 125 // of tracked browser windows in case that device goes away. |
117 void OpenFileBrowse(const std::string& url, | 126 void OpenFileBrowse(const std::string& url, |
118 const std::string& device_path, | 127 const std::string& device_path, |
119 bool small); | 128 bool small); |
120 | 129 |
121 // Show/hide desktop notifications. | 130 // Show/hide desktop notifications. |
122 void ShowDeviceNotification(const std::string& system_path, | 131 void ShowFileBrowserNotification(const std::string& category, |
123 int icon_resource_id, | 132 const std::string& system_path, |
124 const string16& message); | 133 int icon_resource_id, |
125 void HideDeviceNotification(const std::string& system_path); | 134 const string16& title, |
| 135 const string16& message); |
| 136 void HideFileBrowserNotification(const std::string& category, |
| 137 const std::string& system_path); |
126 | 138 |
127 scoped_refptr<FileWatcherDelegate> delegate_; | 139 scoped_refptr<FileWatcherDelegate> delegate_; |
128 MountPointMap mounted_devices_; | 140 MountPointMap mounted_devices_; |
129 NotificationMap notifications_; | 141 NotificationMap notifications_; |
130 WatcherMap file_watchers_; | 142 WatcherMap file_watchers_; |
131 Profile* profile_; | 143 Profile* profile_; |
132 base::Lock lock_; | 144 base::Lock lock_; |
133 | 145 |
134 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 146 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
135 }; | 147 }; |
136 | 148 |
137 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 149 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |