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/dbus/cros_disks_client.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::CrosDisksClient::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::CrosDisksClientEventType event, |
43 const chromeos::MountLibrary::Disk* disk) OVERRIDE; | 43 const chromeos::CrosDisksClient::Disk* disk) |
44 virtual void DeviceChanged(chromeos::MountLibraryEventType event, | 44 OVERRIDE; |
| 45 virtual void DeviceChanged(chromeos::CrosDisksClientEventType 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(chromeos::CrosDisksClient::MountEvent event_type, |
47 chromeos::MountError error_code, | 48 chromeos::MountError error_code, |
48 const chromeos::MountLibrary::MountPointInfo& mount_info) OVERRIDE; | 49 const chromeos::CrosDisksClient::MountPointInfo& mount_info) OVERRIDE; |
49 | 50 |
50 private: | 51 private: |
51 typedef struct FileWatcherExtensions { | 52 typedef struct FileWatcherExtensions { |
52 FileWatcherExtensions(const FilePath& path, | 53 FileWatcherExtensions(const FilePath& path, |
53 const std::string& extension_id) { | 54 const std::string& extension_id) { |
54 file_watcher.reset(new base::files::FilePathWatcher()); | 55 file_watcher.reset(new base::files::FilePathWatcher()); |
55 virtual_path = path; | 56 virtual_path = path; |
56 extensions.insert(extension_id); | 57 extensions.insert(extension_id); |
57 } | 58 } |
58 ~FileWatcherExtensions() {} | 59 ~FileWatcherExtensions() {} |
(...skipping 13 matching lines...) Expand all Loading... |
72 // base::files::FilePathWatcher::Delegate overrides. | 73 // base::files::FilePathWatcher::Delegate overrides. |
73 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; | 74 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
74 virtual void OnFilePathError(const FilePath& path) OVERRIDE; | 75 virtual void OnFilePathError(const FilePath& path) OVERRIDE; |
75 | 76 |
76 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 77 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
77 | 78 |
78 ExtensionFileBrowserEventRouter* router_; | 79 ExtensionFileBrowserEventRouter* router_; |
79 }; | 80 }; |
80 | 81 |
81 // USB mount event handlers. | 82 // USB mount event handlers. |
82 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 83 void OnDiskAdded(const chromeos::CrosDisksClient::Disk* disk); |
83 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 84 void OnDiskRemoved(const chromeos::CrosDisksClient::Disk* disk); |
84 void OnDiskMounted(const chromeos::MountLibrary::Disk* disk); | 85 void OnDiskMounted(const chromeos::CrosDisksClient::Disk* disk); |
85 void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk); | 86 void OnDiskUnmounted(const chromeos::CrosDisksClient::Disk* disk); |
86 void OnDeviceAdded(const std::string& device_path); | 87 void OnDeviceAdded(const std::string& device_path); |
87 void OnDeviceRemoved(const std::string& device_path); | 88 void OnDeviceRemoved(const std::string& device_path); |
88 void OnDeviceScanned(const std::string& device_path); | 89 void OnDeviceScanned(const std::string& device_path); |
89 void OnFormattingStarted(const std::string& device_path, bool success); | 90 void OnFormattingStarted(const std::string& device_path, bool success); |
90 void OnFormattingFinished(const std::string& device_path, bool success); | 91 void OnFormattingFinished(const std::string& device_path, bool success); |
91 | 92 |
92 // Process file watch notifications. | 93 // Process file watch notifications. |
93 void HandleFileWatchNotification(const FilePath& path, | 94 void HandleFileWatchNotification(const FilePath& path, |
94 bool got_error); | 95 bool got_error); |
95 | 96 |
96 // Sends folder change event. | 97 // Sends folder change event. |
97 void DispatchFolderChangeEvent(const FilePath& path, bool error, | 98 void DispatchFolderChangeEvent(const FilePath& path, bool error, |
98 const std::set<std::string>& extensions); | 99 const std::set<std::string>& extensions); |
99 | 100 |
100 // Sends filesystem changed extension message to all renderers. | 101 // Sends filesystem changed extension message to all renderers. |
101 void DispatchDiskEvent(const chromeos::MountLibrary::Disk* disk, bool added); | 102 void DispatchDiskEvent(const chromeos::CrosDisksClient::Disk* disk, |
| 103 bool added); |
102 | 104 |
103 void DispatchMountCompletedEvent(chromeos::MountLibrary::MountEvent event, | 105 void DispatchMountCompletedEvent(chromeos::CrosDisksClient::MountEvent event, |
104 chromeos::MountError error_code, | 106 chromeos::MountError error_code, |
105 const chromeos::MountLibrary::MountPointInfo& mount_info); | 107 const chromeos::CrosDisksClient::MountPointInfo& mount_info); |
106 | 108 |
107 void RemoveBrowserFromVector(const std::string& path); | 109 void RemoveBrowserFromVector(const std::string& path); |
108 | 110 |
109 // Used to create a window of a standard size, and add it to a list | 111 // 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. | 112 // of tracked browser windows in case that device goes away. |
111 void OpenFileBrowse(const std::string& url, | 113 void OpenFileBrowse(const std::string& url, |
112 const std::string& device_path, | 114 const std::string& device_path, |
113 bool small); | 115 bool small); |
114 | 116 |
115 scoped_refptr<FileWatcherDelegate> delegate_; | 117 scoped_refptr<FileWatcherDelegate> delegate_; |
116 WatcherMap file_watchers_; | 118 WatcherMap file_watchers_; |
117 scoped_ptr<FileBrowserNotifications> notifications_; | 119 scoped_ptr<FileBrowserNotifications> notifications_; |
118 Profile* profile_; | 120 Profile* profile_; |
119 base::Lock lock_; | 121 base::Lock lock_; |
120 | 122 |
121 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 123 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
122 }; | 124 }; |
123 | 125 |
124 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 126 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |