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/disks/disk_mount_manager.h" |
19 | 19 |
20 class FileBrowserNotifications; | 20 class FileBrowserNotifications; |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 // Used to monitor disk mount changes and signal when new mounted usb device is | 23 // Used to monitor disk mount changes and signal when new mounted usb device is |
24 // found. | 24 // found. |
25 class ExtensionFileBrowserEventRouter | 25 class ExtensionFileBrowserEventRouter |
26 : public chromeos::MountLibrary::Observer { | 26 : public chromeos::disks::DiskMountManager::Observer { |
27 public: | 27 public: |
28 explicit ExtensionFileBrowserEventRouter(Profile* profile); | 28 explicit ExtensionFileBrowserEventRouter(Profile* profile); |
29 virtual ~ExtensionFileBrowserEventRouter(); | 29 virtual ~ExtensionFileBrowserEventRouter(); |
30 // Starts observing file system change events. Currently only | 30 // Starts observing file system change events. Currently only |
31 // MountLibrary events are being observed. | 31 // CrosDisksClient events are being observed. |
32 void ObserveFileSystemEvents(); | 32 void ObserveFileSystemEvents(); |
33 | 33 |
34 // File watch setup routines. | 34 // File watch setup routines. |
35 bool AddFileWatch(const FilePath& file_path, | 35 bool AddFileWatch(const FilePath& file_path, |
36 const FilePath& virtual_path, | 36 const FilePath& virtual_path, |
37 const std::string& extension_id); | 37 const std::string& extension_id); |
38 void RemoveFileWatch(const FilePath& file_path, | 38 void RemoveFileWatch(const FilePath& file_path, |
39 const std::string& extension_id); | 39 const std::string& extension_id); |
40 | 40 |
41 // MountLibrary::Observer overrides. | 41 // CrosDisksClient::Observer overrides. |
42 virtual void DiskChanged(chromeos::MountLibraryEventType event, | 42 virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event, |
43 const chromeos::MountLibrary::Disk* disk) OVERRIDE; | 43 const chromeos::disks::DiskMountManager::Disk* disk) |
44 virtual void DeviceChanged(chromeos::MountLibraryEventType event, | 44 OVERRIDE; |
| 45 virtual void DeviceChanged(chromeos::disks::DiskMountManagerEventType event, |
45 const std::string& device_path) OVERRIDE; | 46 const std::string& device_path) OVERRIDE; |
46 virtual void MountCompleted(chromeos::MountLibrary::MountEvent event_type, | 47 virtual void MountCompleted( |
| 48 chromeos::disks::DiskMountManager::MountEvent event_type, |
47 chromeos::MountError error_code, | 49 chromeos::MountError error_code, |
48 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE; | 50 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) |
| 51 OVERRIDE; |
49 | 52 |
50 private: | 53 private: |
51 // Helper class for passing through file watch notification events. | 54 // Helper class for passing through file watch notification events. |
52 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { | 55 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { |
53 public: | 56 public: |
54 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router); | 57 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router); |
55 | 58 |
56 private: | 59 private: |
57 // base::files::FilePathWatcher::Delegate overrides. | 60 // base::files::FilePathWatcher::Delegate overrides. |
58 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; | 61 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
(...skipping 29 matching lines...) Expand all Loading... |
88 linked_ptr<base::files::FilePathWatcher> file_watcher; | 91 linked_ptr<base::files::FilePathWatcher> file_watcher; |
89 FilePath local_path; | 92 FilePath local_path; |
90 FilePath virtual_path; | 93 FilePath virtual_path; |
91 ExtensionUsageRegistry extensions; | 94 ExtensionUsageRegistry extensions; |
92 unsigned int ref_count; | 95 unsigned int ref_count; |
93 }; | 96 }; |
94 | 97 |
95 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; | 98 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; |
96 | 99 |
97 // USB mount event handlers. | 100 // USB mount event handlers. |
98 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 101 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); |
99 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 102 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); |
100 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); | 103 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); |
101 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); | 104 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); |
102 void OnDeviceAdded(const std::string& device_path); | 105 void OnDeviceAdded(const std::string& device_path); |
103 void OnDeviceRemoved(const std::string& device_path); | 106 void OnDeviceRemoved(const std::string& device_path); |
104 void OnDeviceScanned(const std::string& device_path); | 107 void OnDeviceScanned(const std::string& device_path); |
105 void OnFormattingStarted(const std::string& device_path, bool success); | 108 void OnFormattingStarted(const std::string& device_path, bool success); |
106 void OnFormattingFinished(const std::string& device_path, bool success); | 109 void OnFormattingFinished(const std::string& device_path, bool success); |
107 | 110 |
108 // Process file watch notifications. | 111 // Process file watch notifications. |
109 void HandleFileWatchNotification(const FilePath& path, | 112 void HandleFileWatchNotification(const FilePath& path, |
110 bool got_error); | 113 bool got_error); |
111 | 114 |
112 // Sends folder change event. | 115 // Sends folder change event. |
113 void DispatchFolderChangeEvent(const FilePath& path, bool error, | 116 void DispatchFolderChangeEvent(const FilePath& path, bool error, |
114 const ExtensionUsageRegistry& extensions); | 117 const ExtensionUsageRegistry& extensions); |
115 | 118 |
116 // Sends filesystem changed extension message to all renderers. | 119 // Sends filesystem changed extension message to all renderers. |
117 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added); | 120 void DispatchDiskEvent(const chromeos::disks::DiskMountManager::Disk* disk, |
| 121 bool added); |
118 | 122 |
119 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, | 123 void DispatchMountCompletedEvent( |
| 124 chromeos::disks::DiskMountManager::MountEvent event, |
120 chromeos::MountError error_code, | 125 chromeos::MountError error_code, |
121 const chromeos::MountLibrary::MountPointInfo& mount_info); | 126 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info); |
122 | 127 |
123 void RemoveBrowserFromVector(const std::string& path); | 128 void RemoveBrowserFromVector(const std::string& path); |
124 | 129 |
125 // Used to create a window of a standard size, and add it to a list | 130 // Used to create a window of a standard size, and add it to a list |
126 // of tracked browser windows in case that device goes away. | 131 // of tracked browser windows in case that device goes away. |
127 void OpenFileBrowse(const std::string& url, | 132 void OpenFileBrowse(const std::string& url, |
128 const std::string& device_path, | 133 const std::string& device_path, |
129 bool small); | 134 bool small); |
130 | 135 |
131 scoped_refptr<FileWatcherDelegate> delegate_; | 136 scoped_refptr<FileWatcherDelegate> delegate_; |
132 WatcherMap file_watchers_; | 137 WatcherMap file_watchers_; |
133 scoped_ptr<FileBrowserNotifications> notifications_; | 138 scoped_ptr<FileBrowserNotifications> notifications_; |
134 Profile* profile_; | 139 Profile* profile_; |
135 base::Lock lock_; | 140 base::Lock lock_; |
136 | 141 |
137 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 142 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
138 }; | 143 }; |
139 | 144 |
140 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 145 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |