Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 class Profile; | 27 class Profile; |
| 28 | 28 |
| 29 namespace drive { | 29 namespace drive { |
| 30 class DriveEntryProto; | 30 class DriveEntryProto; |
| 31 class DriveFileSystemInterface; | 31 class DriveFileSystemInterface; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Monitors changes in disk mounts, network connection state and preferences | 34 // Monitors changes in disk mounts, network connection state and preferences |
| 35 // affecting File Manager. Dispatches appropriate File Browser events. | 35 // affecting File Manager. Dispatches appropriate File Browser events. |
| 36 class FileBrowserEventRouter | 36 class FileBrowserEventRouter |
| 37 : public base::RefCountedThreadSafe<FileBrowserEventRouter>, | 37 : public chromeos::disks::DiskMountManager::Observer, |
| 38 public chromeos::disks::DiskMountManager::Observer, | |
| 39 public chromeos::ConnectivityStateHelperObserver, | 38 public chromeos::ConnectivityStateHelperObserver, |
| 40 public chromeos::SystemKeyEventListener::ModifiersObserver, | 39 public chromeos::SystemKeyEventListener::ModifiersObserver, |
| 41 public drive::DriveFileSystemObserver, | 40 public drive::DriveFileSystemObserver, |
| 42 public google_apis::DriveServiceObserver { | 41 public google_apis::DriveServiceObserver { |
| 43 public: | 42 public: |
| 44 // Interface that should keep track of the system state in regards to system | 43 // Interface that should keep track of the system state in regards to system |
| 45 // suspend and resume events. | 44 // suspend and resume events. |
| 46 // When the |IsResuming()| returns true, it should be able to check if a | 45 // When the |IsResuming()| returns true, it should be able to check if a |
| 47 // removable device was present before the was system suspended. | 46 // removable device was present before the was system suspended. |
| 48 class SuspendStateDelegate { | 47 class SuspendStateDelegate { |
| 49 public: | 48 public: |
| 50 virtual ~SuspendStateDelegate() {} | 49 virtual ~SuspendStateDelegate() {} |
| 51 | 50 |
| 52 // Returns true if the system has recently woken up. | 51 // Returns true if the system has recently woken up. |
| 53 virtual bool SystemIsResuming() const = 0; | 52 virtual bool SystemIsResuming() const = 0; |
| 54 // If system is resuming, returns true if the disk was present before the | 53 // If system is resuming, returns true if the disk was present before the |
| 55 // system suspend. Should return false if the system is not resuming. | 54 // system suspend. Should return false if the system is not resuming. |
| 56 virtual bool DiskWasPresentBeforeSuspend( | 55 virtual bool DiskWasPresentBeforeSuspend( |
| 57 const chromeos::disks::DiskMountManager::Disk& disk) const = 0; | 56 const chromeos::disks::DiskMountManager::Disk& disk) const = 0; |
| 58 }; | 57 }; |
| 59 | 58 |
| 59 explicit FileBrowserEventRouter(Profile* profile); | |
| 60 virtual ~FileBrowserEventRouter(); | |
| 61 | |
| 60 void Shutdown(); | 62 void Shutdown(); |
| 61 | 63 |
| 62 // Starts observing file system change events. | 64 // Starts observing file system change events. |
| 63 void ObserveFileSystemEvents(); | 65 void ObserveFileSystemEvents(); |
| 64 | 66 |
| 65 // File watch setup routines. | 67 typedef base::Callback<void(bool success)> BoolCallback; |
| 66 bool AddFileWatch(const base::FilePath& file_path, | 68 |
| 69 // Adds a file watch at |local_path|, associated with |virtual_path|, for | |
| 70 // an extension with |extension_id|. | |
| 71 // | |
| 72 // |callback| will be called with true on success, or false on failure. | |
| 73 // |callback| must not be null. | |
| 74 bool AddFileWatch(const base::FilePath& local_path, | |
|
hashimoto
2013/04/08 11:10:26
A method returning bool while taking BoolCallback
satorux1
2013/04/09 01:24:38
Done.
| |
| 67 const base::FilePath& virtual_path, | 75 const base::FilePath& virtual_path, |
| 68 const std::string& extension_id); | 76 const std::string& extension_id, |
| 69 void RemoveFileWatch(const base::FilePath& file_path, | 77 const BoolCallback& callback); |
| 78 | |
| 79 // Removes a file watch at |local_path| for an extension with |extension_id|. | |
| 80 void RemoveFileWatch(const base::FilePath& local_path, | |
| 70 const std::string& extension_id); | 81 const std::string& extension_id); |
| 71 | 82 |
| 72 // Mounts Drive on File browser. |callback| will be called after raising a | 83 // Mounts Drive on File browser. |callback| will be called after raising a |
| 73 // mount request event to file manager on JS-side. | 84 // mount request event to file manager on JS-side. |
| 74 void MountDrive(const base::Closure& callback); | 85 void MountDrive(const base::Closure& callback); |
| 75 | 86 |
| 76 // CrosDisksClient::Observer overrides. | 87 // CrosDisksClient::Observer overrides. |
| 77 virtual void OnDiskEvent( | 88 virtual void OnDiskEvent( |
| 78 chromeos::disks::DiskMountManager::DiskEvent event, | 89 chromeos::disks::DiskMountManager::DiskEvent event, |
| 79 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; | 90 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 102 virtual void OnDirectoryChanged( | 113 virtual void OnDirectoryChanged( |
| 103 const base::FilePath& directory_path) OVERRIDE; | 114 const base::FilePath& directory_path) OVERRIDE; |
| 104 virtual void OnResourceListFetched(int num_accumulated_entries) OVERRIDE; | 115 virtual void OnResourceListFetched(int num_accumulated_entries) OVERRIDE; |
| 105 virtual void OnFileSystemMounted() OVERRIDE; | 116 virtual void OnFileSystemMounted() OVERRIDE; |
| 106 virtual void OnFileSystemBeingUnmounted() OVERRIDE; | 117 virtual void OnFileSystemBeingUnmounted() OVERRIDE; |
| 107 | 118 |
| 108 // chromeos::SystemKeyEventListener::ModifiersObserver overrides. | 119 // chromeos::SystemKeyEventListener::ModifiersObserver overrides. |
| 109 virtual void OnModifiersChange(int pressed_modifiers) OVERRIDE; | 120 virtual void OnModifiersChange(int pressed_modifiers) OVERRIDE; |
| 110 | 121 |
| 111 private: | 122 private: |
| 112 friend class FileBrowserPrivateAPI; | |
| 113 friend class base::RefCountedThreadSafe<FileBrowserEventRouter>; | |
| 114 | |
| 115 typedef std::map<std::string, int> ExtensionUsageRegistry; | 123 typedef std::map<std::string, int> ExtensionUsageRegistry; |
| 116 | 124 |
| 125 // This class is used to remember what extensions are watching |virtual_path|. | |
| 117 class FileWatcherExtensions { | 126 class FileWatcherExtensions { |
| 118 public: | 127 public: |
| 119 FileWatcherExtensions(const base::FilePath& path, | 128 FileWatcherExtensions(const base::FilePath& virtual_path, |
| 120 const std::string& extension_id, | 129 const std::string& extension_id, |
| 121 bool is_remote_file_system); | 130 bool is_remote_file_system); |
| 122 | 131 |
| 123 ~FileWatcherExtensions(); | 132 ~FileWatcherExtensions(); |
| 124 | 133 |
| 125 void AddExtension(const std::string& extension_id); | 134 void AddExtension(const std::string& extension_id); |
| 126 | 135 |
| 127 void RemoveExtension(const std::string& extension_id); | 136 void RemoveExtension(const std::string& extension_id); |
| 128 | 137 |
| 129 const ExtensionUsageRegistry& GetExtensions() const; | 138 const ExtensionUsageRegistry& GetExtensions() const; |
| 130 | 139 |
| 131 unsigned int GetRefCount() const; | 140 unsigned int GetRefCount() const; |
| 132 | 141 |
| 133 const base::FilePath& GetVirtualPath() const; | 142 const base::FilePath& GetVirtualPath() const; |
| 134 | 143 |
| 135 bool Watch(const base::FilePath& path, | 144 // Starts a file watch at |local_path|. |file_path_watcher| will be |
| 136 const base::FilePathWatcher::Callback& callback); | 145 // called when changes are notified. |
| 146 // | |
| 147 // |callback| will be called with true, if the file watch is started | |
| 148 // |successfully, or false if failed. |callback| must not be null. | |
| 149 void Watch(const base::FilePath& local_path, | |
| 150 const base::FilePathWatcher::Callback& file_watcher_callback, | |
| 151 const BoolCallback& callback); | |
| 137 | 152 |
| 138 private: | 153 private: |
| 139 linked_ptr<base::FilePathWatcher> file_watcher_; | 154 // Called when a FilePathWatcher is created and started. |
| 155 // |file_path_watcher| is NULL, if the watcher wasn't started successfully. | |
| 156 void OnWatcherStarted(const BoolCallback& callback, | |
| 157 base::FilePathWatcher* file_path_watcher); | |
| 158 | |
| 159 base::FilePathWatcher* file_watcher_; | |
| 140 base::FilePath local_path_; | 160 base::FilePath local_path_; |
| 141 base::FilePath virtual_path_; | 161 base::FilePath virtual_path_; |
| 142 ExtensionUsageRegistry extensions_; | 162 ExtensionUsageRegistry extensions_; |
| 143 unsigned int ref_count_; | 163 unsigned int ref_count_; |
| 144 bool is_remote_file_system_; | 164 bool is_remote_file_system_; |
| 165 | |
| 166 // Note: This should remain the last member so it'll be destroyed and | |
| 167 // invalidate the weak pointers before any other members are destroyed. | |
| 168 base::WeakPtrFactory<FileWatcherExtensions> weak_ptr_factory_; | |
| 145 }; | 169 }; |
| 146 | 170 |
| 147 typedef std::map<base::FilePath, FileWatcherExtensions*> WatcherMap; | 171 typedef std::map<base::FilePath, FileWatcherExtensions*> WatcherMap; |
| 148 | 172 |
| 149 explicit FileBrowserEventRouter(Profile* profile); | |
| 150 virtual ~FileBrowserEventRouter(); | |
| 151 | |
| 152 // USB mount event handlers. | 173 // USB mount event handlers. |
| 153 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); | 174 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); |
| 154 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); | 175 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); |
| 155 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); | 176 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); |
| 156 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); | 177 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); |
| 157 void OnDeviceAdded(const std::string& device_path); | 178 void OnDeviceAdded(const std::string& device_path); |
| 158 void OnDeviceRemoved(const std::string& device_path); | 179 void OnDeviceRemoved(const std::string& device_path); |
| 159 void OnDeviceScanned(const std::string& device_path); | 180 void OnDeviceScanned(const std::string& device_path); |
| 160 void OnFormatStarted(const std::string& device_path, bool success); | 181 void OnFormatStarted(const std::string& device_path, bool success); |
| 161 void OnFormatCompleted(const std::string& device_path, bool success); | 182 void OnFormatCompleted(const std::string& device_path, bool success); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 int num_remote_update_requests_; | 230 int num_remote_update_requests_; |
| 210 | 231 |
| 211 // Event router behavior depends on shift modifier status. This is designed | 232 // Event router behavior depends on shift modifier status. This is designed |
| 212 // for power users. | 233 // for power users. |
| 213 bool shift_pressed_; | 234 bool shift_pressed_; |
| 214 | 235 |
| 215 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter); | 236 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter); |
| 216 }; | 237 }; |
| 217 | 238 |
| 218 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 239 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |