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> |
(...skipping 10 matching lines...) Expand all Loading... |
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 public: | 30 public: |
31 static ExtensionFileBrowserEventRouter* GetInstance(); | 31 explicit ExtensionFileBrowserEventRouter(Profile* profile); |
| 32 virtual ~ExtensionFileBrowserEventRouter(); |
32 | 33 |
33 // Starts/stops observing file system change events. Currently only | 34 void Init(); |
34 // MountLibrary events are being observed. | |
35 void ObserveFileSystemEvents(Profile* profile); | |
36 void StopObservingFileSystemEvents(); | |
37 | 35 |
38 // File watch setup routines. | 36 // File watch setup routines. |
39 bool AddFileWatch(const FilePath& file_path, | 37 bool AddFileWatch(const FilePath& file_path, |
40 const FilePath& virtual_path, | 38 const FilePath& virtual_path, |
41 const std::string& extension_id); | 39 const std::string& extension_id); |
42 void RemoveFileWatch(const FilePath& file_path, | 40 void RemoveFileWatch(const FilePath& file_path, |
43 const std::string& extension_id); | 41 const std::string& extension_id); |
44 | 42 |
45 // MountLibrary::Observer overrides. | 43 // MountLibrary::Observer overrides. |
46 virtual void DiskChanged(chromeos::MountLibraryEventType event, | 44 virtual void DiskChanged(chromeos::MountLibraryEventType event, |
47 const chromeos::MountLibrary::Disk* disk); | 45 const chromeos::MountLibrary::Disk* disk); |
48 virtual void DeviceChanged(chromeos::MountLibraryEventType event, | 46 virtual void DeviceChanged(chromeos::MountLibraryEventType event, |
49 const std::string& device_path); | 47 const std::string& device_path); |
50 | 48 |
51 private: | 49 private: |
52 friend struct DefaultSingletonTraits<ExtensionFileBrowserEventRouter>; | |
53 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > | 50 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > |
54 NotificationMap; | 51 NotificationMap; |
55 typedef std::map<std::string, std::string> MountPointMap; | 52 typedef std::map<std::string, std::string> MountPointMap; |
56 typedef struct FileWatcherExtensions { | 53 typedef struct FileWatcherExtensions { |
57 FileWatcherExtensions(const FilePath& path, const std::string& extension_id)
{ | 54 FileWatcherExtensions(const FilePath& path, const std::string& extension_id)
{ |
58 file_watcher.reset(new base::files::FilePathWatcher()); | 55 file_watcher.reset(new base::files::FilePathWatcher()); |
59 virtual_path = path; | 56 virtual_path = path; |
60 extensions.insert(extension_id); | 57 extensions.insert(extension_id); |
61 } | 58 } |
62 ~FileWatcherExtensions() {} | 59 ~FileWatcherExtensions() {} |
(...skipping 10 matching lines...) Expand all Loading... |
73 FileWatcherDelegate(); | 70 FileWatcherDelegate(); |
74 | 71 |
75 private: | 72 private: |
76 // base::files::FilePathWatcher::Delegate overrides. | 73 // base::files::FilePathWatcher::Delegate overrides. |
77 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; | 74 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
78 virtual void OnFilePathError(const FilePath& path) OVERRIDE; | 75 virtual void OnFilePathError(const FilePath& path) OVERRIDE; |
79 | 76 |
80 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 77 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
81 }; | 78 }; |
82 | 79 |
83 ExtensionFileBrowserEventRouter(); | |
84 virtual ~ExtensionFileBrowserEventRouter(); | |
85 | |
86 // USB mount event handlers. | 80 // USB mount event handlers. |
87 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); | 81 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); |
88 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); | 82 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); |
89 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); | 83 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); |
90 void OnDeviceAdded(const std::string& device_path); | 84 void OnDeviceAdded(const std::string& device_path); |
91 void OnDeviceRemoved(const std::string& device_path); | 85 void OnDeviceRemoved(const std::string& device_path); |
92 void OnDeviceScanned(const std::string& device_path); | 86 void OnDeviceScanned(const std::string& device_path); |
93 | 87 |
94 // Finds first notifications corresponding to the same device. Ensures that | 88 // Finds first notifications corresponding to the same device. Ensures that |
95 // we don't pop up multiple notifications for the same device. | 89 // we don't pop up multiple notifications for the same device. |
(...skipping 28 matching lines...) Expand all Loading... |
124 MountPointMap mounted_devices_; | 118 MountPointMap mounted_devices_; |
125 NotificationMap notifications_; | 119 NotificationMap notifications_; |
126 WatcherMap file_watchers_; | 120 WatcherMap file_watchers_; |
127 Profile* profile_; | 121 Profile* profile_; |
128 base::Lock lock_; | 122 base::Lock lock_; |
129 | 123 |
130 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); | 124 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
131 }; | 125 }; |
132 | 126 |
133 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 127 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |