| 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_MANAGER_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path_watcher.h" | 14 #include "base/files/file_path_watcher.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system_observer.h" | 17 #include "chrome/browser/chromeos/drive/file_system_observer.h" |
| 18 #include "chrome/browser/chromeos/drive/job_list.h" | |
| 19 #include "chrome/browser/chromeos/drive/sync_client.h" | 18 #include "chrome/browser/chromeos/drive/sync_client.h" |
| 19 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" |
| 20 #include "chrome/browser/chromeos/extensions/file_manager/job_event_router.h" |
| 20 #include "chrome/browser/chromeos/file_manager/file_watcher.h" | 21 #include "chrome/browser/chromeos/file_manager/file_watcher.h" |
| 21 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 22 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 22 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 23 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 23 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 24 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
| 24 #include "chrome/browser/drive/drive_service_interface.h" | 25 #include "chrome/browser/drive/drive_service_interface.h" |
| 25 #include "chrome/common/extensions/api/file_manager_private.h" | 26 #include "chrome/common/extensions/api/file_manager_private.h" |
| 26 #include "chromeos/disks/disk_mount_manager.h" | 27 #include "chromeos/disks/disk_mount_manager.h" |
| 27 #include "chromeos/network/network_state_handler_observer.h" | 28 #include "chromeos/network/network_state_handler_observer.h" |
| 28 #include "components/keyed_service/core/keyed_service.h" | 29 #include "components/keyed_service/core/keyed_service.h" |
| 29 #include "storage/browser/fileapi/file_system_operation.h" | 30 #include "storage/browser/fileapi/file_system_operation.h" |
| 30 | 31 |
| 31 class PrefChangeRegistrar; | 32 class PrefChangeRegistrar; |
| 32 class Profile; | 33 class Profile; |
| 33 | 34 |
| 34 using file_manager::util::EntryDefinition; | 35 using file_manager::util::EntryDefinition; |
| 35 | 36 |
| 36 namespace base { | 37 namespace base { |
| 37 class ListValue; | 38 class ListValue; |
| 38 } | 39 } |
| 39 | 40 |
| 40 namespace chromeos { | 41 namespace chromeos { |
| 41 class NetworkState; | 42 class NetworkState; |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace drive { | 45 namespace drive { |
| 45 class FileChange; | 46 class FileChange; |
| 46 } | 47 } |
| 47 | 48 |
| 48 namespace file_manager { | 49 namespace file_manager { |
| 49 class DeviceEventRouter; | |
| 50 | 50 |
| 51 // Monitors changes in disk mounts, network connection state and preferences | 51 // Monitors changes in disk mounts, network connection state and preferences |
| 52 // affecting File Manager. Dispatches appropriate File Browser events. | 52 // affecting File Manager. Dispatches appropriate File Browser events. |
| 53 class EventRouter : public KeyedService, | 53 class EventRouter : public KeyedService, |
| 54 public chromeos::NetworkStateHandlerObserver, | 54 public chromeos::NetworkStateHandlerObserver, |
| 55 public drive::FileSystemObserver, | 55 public drive::FileSystemObserver, |
| 56 public drive::JobListObserver, | |
| 57 public drive::DriveServiceObserver, | 56 public drive::DriveServiceObserver, |
| 58 public VolumeManagerObserver { | 57 public VolumeManagerObserver { |
| 59 public: | 58 public: |
| 60 typedef base::Callback<void(const base::FilePath& virtual_path, | 59 typedef base::Callback<void(const base::FilePath& virtual_path, |
| 61 const drive::FileChange* list, | 60 const drive::FileChange* list, |
| 62 bool got_error, | 61 bool got_error, |
| 63 const std::vector<std::string>& extension_ids)> | 62 const std::vector<std::string>& extension_ids)> |
| 64 DispatchDirectoryChangeEventImplCallback; | 63 DispatchDirectoryChangeEventImplCallback; |
| 65 | 64 |
| 66 explicit EventRouter(Profile* profile); | 65 explicit EventRouter(Profile* profile); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 104 |
| 106 // Called when a notification from a watcher manager arrives. | 105 // Called when a notification from a watcher manager arrives. |
| 107 void OnWatcherManagerNotification( | 106 void OnWatcherManagerNotification( |
| 108 const storage::FileSystemURL& file_system_url, | 107 const storage::FileSystemURL& file_system_url, |
| 109 const std::string& extension_id, | 108 const std::string& extension_id, |
| 110 storage::WatcherManager::ChangeType change_type); | 109 storage::WatcherManager::ChangeType change_type); |
| 111 | 110 |
| 112 // chromeos::NetworkStateHandlerObserver overrides. | 111 // chromeos::NetworkStateHandlerObserver overrides. |
| 113 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; | 112 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; |
| 114 | 113 |
| 115 // drive::JobListObserver overrides. | |
| 116 void OnJobAdded(const drive::JobInfo& job_info) override; | |
| 117 void OnJobUpdated(const drive::JobInfo& job_info) override; | |
| 118 void OnJobDone(const drive::JobInfo& job_info, | |
| 119 drive::FileError error) override; | |
| 120 | |
| 121 // drive::DriveServiceObserver overrides. | 114 // drive::DriveServiceObserver overrides. |
| 122 void OnRefreshTokenInvalid() override; | 115 void OnRefreshTokenInvalid() override; |
| 123 void OnReadyToSendRequests() override; | 116 void OnReadyToSendRequests() override; |
| 124 | 117 |
| 125 // drive::FileSystemObserver overrides. | 118 // drive::FileSystemObserver overrides. |
| 126 void OnDirectoryChanged(const base::FilePath& drive_path) override; | 119 void OnDirectoryChanged(const base::FilePath& drive_path) override; |
| 127 void OnFileChanged(const drive::FileChange& changed_files) override; | 120 void OnFileChanged(const drive::FileChange& changed_files) override; |
| 128 void OnDriveSyncError(drive::file_system::DriveSyncErrorType type, | 121 void OnDriveSyncError(drive::file_system::DriveSyncErrorType type, |
| 129 const base::FilePath& drive_path) override; | 122 const base::FilePath& drive_path) override; |
| 130 | 123 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 extensions::api::file_manager_private::MountCompletedEventType event_type, | 183 extensions::api::file_manager_private::MountCompletedEventType event_type, |
| 191 chromeos::MountError error, | 184 chromeos::MountError error, |
| 192 const VolumeInfo& volume_info); | 185 const VolumeInfo& volume_info); |
| 193 | 186 |
| 194 // If needed, opens a file manager window for the removable device mounted at | 187 // If needed, opens a file manager window for the removable device mounted at |
| 195 // |mount_path|. Disk.mount_path() is empty, since it is being filled out | 188 // |mount_path|. Disk.mount_path() is empty, since it is being filled out |
| 196 // after calling notifying observers by DiskMountManager. | 189 // after calling notifying observers by DiskMountManager. |
| 197 void ShowRemovableDeviceInFileManager(VolumeType type, | 190 void ShowRemovableDeviceInFileManager(VolumeType type, |
| 198 const base::FilePath& mount_path); | 191 const base::FilePath& mount_path); |
| 199 | 192 |
| 200 // Manages the list of currently active Drive file transfer jobs. | |
| 201 struct DriveJobInfoWithStatus { | |
| 202 DriveJobInfoWithStatus(); | |
| 203 DriveJobInfoWithStatus(const drive::JobInfo& info, | |
| 204 const std::string& status); | |
| 205 drive::JobInfo job_info; | |
| 206 std::string status; | |
| 207 }; | |
| 208 | |
| 209 // Sends onFileTransferUpdate event right now if |immediate| is set. Otherwise | 193 // Sends onFileTransferUpdate event right now if |immediate| is set. Otherwise |
| 210 // it refrains from sending for a short while, and after that it sends the | 194 // it refrains from sending for a short while, and after that it sends the |
| 211 // most recently scheduled event once. | 195 // most recently scheduled event once. |
| 212 // The delay is for waiting subsequent 'added' events to come after the first | 196 // The delay is for waiting subsequent 'added' events to come after the first |
| 213 // one when multiple tasks are added. This way, we can avoid frequent UI | 197 // one when multiple tasks are added. This way, we can avoid frequent UI |
| 214 // update caused by differences between singular and plural cases. | 198 // update caused by differences between singular and plural cases. |
| 215 void ScheduleDriveFileTransferEvent(const drive::JobInfo& job_info, | 199 void ScheduleDriveFileTransferEvent(const drive::JobInfo& job_info, |
| 216 const std::string& status, | 200 const std::string& status, |
| 217 bool immediate); | 201 bool immediate); |
| 218 | 202 |
| 219 // Sends the most recently scheduled onFileTransferUpdated event to | 203 // Sends the most recently scheduled onFileTransferUpdated event to |
| 220 // extensions. | 204 // extensions. |
| 221 // This is used for implementing ScheduledDriveFileTransferEvent(). | 205 // This is used for implementing ScheduledDriveFileTransferEvent(). |
| 222 void SendDriveFileTransferEvent(); | 206 void SendDriveFileTransferEvent(); |
| 223 | 207 |
| 224 std::map<drive::JobID, DriveJobInfoWithStatus> drive_jobs_; | |
| 225 scoped_ptr<DriveJobInfoWithStatus> drive_job_info_for_scheduled_event_; | |
| 226 base::Time last_copy_progress_event_; | 208 base::Time last_copy_progress_event_; |
| 227 base::Time next_send_file_transfer_event_; | |
| 228 | 209 |
| 229 WatcherMap file_watchers_; | 210 WatcherMap file_watchers_; |
| 230 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 211 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 231 Profile* profile_; | 212 Profile* profile_; |
| 232 | 213 |
| 233 scoped_ptr<DeviceEventRouter> device_event_router_; | 214 scoped_ptr<DeviceEventRouter> device_event_router_; |
| 215 scoped_ptr<JobEventRouter> job_event_router_; |
| 234 | 216 |
| 235 DispatchDirectoryChangeEventImplCallback | 217 DispatchDirectoryChangeEventImplCallback |
| 236 dispatch_directory_change_event_impl_; | 218 dispatch_directory_change_event_impl_; |
| 237 | 219 |
| 238 // Note: This should remain the last member so it'll be destroyed and | 220 // Note: This should remain the last member so it'll be destroyed and |
| 239 // invalidate the weak pointers before any other members are destroyed. | 221 // invalidate the weak pointers before any other members are destroyed. |
| 240 base::WeakPtrFactory<EventRouter> weak_factory_; | 222 base::WeakPtrFactory<EventRouter> weak_factory_; |
| 241 | 223 |
| 242 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 224 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
| 243 }; | 225 }; |
| 244 | 226 |
| 245 } // namespace file_manager | 227 } // namespace file_manager |
| 246 | 228 |
| 247 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ | 229 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
| OLD | NEW |