Chromium Code Reviews| Index: chrome/browser/chromeos/cros/mount_library.cc |
| =================================================================== |
| --- chrome/browser/chromeos/cros/mount_library.cc (revision 93425) |
| +++ chrome/browser/chromeos/cros/mount_library.cc (working copy) |
| @@ -90,31 +90,29 @@ |
| observers_.RemoveObserver(observer); |
| } |
| - virtual void MountPath(const char* device_path) OVERRIDE { |
| + virtual void MountPath(const char* source_path, |
| + MountType type, |
| + const MountPathOptions& options) OVERRIDE { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!CrosLibrary::Get()->EnsureLoaded()) { |
| - OnMountRemovableDevice(device_path, |
| - NULL, |
| - MOUNT_METHOD_ERROR_LOCAL, |
| - kLibraryNotLoaded); |
| + OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, |
| + source_path, |
| + type, |
| + NULL); |
| return; |
| } |
| - MountRemovableDevice(device_path, |
| - &MountLibraryImpl::MountRemovableDeviceCallback, |
| - this); |
| + MountSourcePath(source_path, type, options, &MountCompletedHandler, this); |
| } |
| - virtual void UnmountPath(const char* device_path) OVERRIDE { |
| + virtual void UnmountPath(const char* path) OVERRIDE { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!CrosLibrary::Get()->EnsureLoaded()) { |
| - OnUnmountRemovableDevice(device_path, |
| - MOUNT_METHOD_ERROR_LOCAL, |
| - kLibraryNotLoaded); |
| + OnUnmountPath(path, |
| + MOUNT_METHOD_ERROR_LOCAL, |
| + kLibraryNotLoaded); |
| return; |
| } |
| - UnmountRemovableDevice(device_path, |
| - &MountLibraryImpl::UnmountRemovableDeviceCallback, |
| - this); |
| + UnmountMountPoint(path, &MountLibraryImpl::UnmountMountPointCallback, this); |
| } |
| virtual void UnmountDeviceRecursive(const char* device_path, |
| @@ -151,9 +149,10 @@ |
| cb_data = new UnmountDeviceRecursiveCallbackData(this, user_data, |
| callback, devices_to_unmount.size()); |
| for (std::vector<const char*>::iterator it = devices_to_unmount.begin(); |
| - it != devices_to_unmount.end(); |
| - ++it) { |
| - UnmountRemovableDevice(*it, |
| + it != devices_to_unmount.end(); |
| + ++it) { |
| + UnmountMountPoint( |
| + *it, |
| &MountLibraryImpl::UnmountDeviceRecursiveCallback, |
| cb_data); |
| } |
| @@ -178,39 +177,37 @@ |
| } |
| const DiskMap& disks() const OVERRIDE { return disks_; } |
| + const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } |
| private: |
| - // Callback for MountRemovableDevice method. |
| - static void MountRemovableDeviceCallback(void* object, |
| - const char* device_path, |
| - const char* mount_path, |
| - MountMethodErrorType error, |
| - const char* error_message) { |
| + // Callback for MountComplete signal and MountSourcePath method. |
| + static void MountCompletedHandler(void* object, |
| + MountError error_code, |
| + const char* source_path, |
| + MountType type, |
| + const char* mount_path) { |
| +LOG(WARNING) <<"MountCompleted" <<error_code<<source_path<<mount_path; |
| DCHECK(object); |
| MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
| - self->OnMountRemovableDevice(device_path, |
| - mount_path, |
| - error, |
| - error_message); |
| + self->OnMountCompleted(static_cast<MountError>(error_code), |
| + source_path, |
| + static_cast<MountType>(type), |
| + mount_path); |
| } |
| // Callback for UnmountRemovableDevice method. |
| - static void UnmountRemovableDeviceCallback(void* object, |
| - const char* device_path, |
| - const char* mount_path, |
| - MountMethodErrorType error, |
| - const char* error_message) { |
| + static void UnmountMountPointCallback(void* object, |
| + const char* device_path, |
| + MountMethodErrorType error, |
| + const char* error_message) { |
| DCHECK(object); |
| MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
| - self->OnUnmountRemovableDevice(device_path, |
| - error, |
| - error_message); |
| + self->OnUnmountPath(device_path, error, error_message); |
| } |
| // Callback for UnmountDeviceRecursive. |
| static void UnmountDeviceRecursiveCallback(void* object, |
| const char* device_path, |
| - const char* mount_path, |
| MountMethodErrorType error, |
| const char* error_message) { |
| DCHECK(object); |
| @@ -218,9 +215,9 @@ |
| static_cast<UnmountDeviceRecursiveCallbackData*>(object); |
| // Do standard processing for Unmount event. |
| - cb_data->object->OnUnmountRemovableDevice(device_path, |
| - error, |
| - error_message); |
| + cb_data->object->OnUnmountPath(device_path, |
| + error, |
| + error_message); |
| if (error == MOUNT_METHOD_ERROR_LOCAL) { |
| cb_data->success = false; |
| } else if (error == MOUNT_METHOD_ERROR_NONE) { |
| @@ -275,14 +272,23 @@ |
| } |
| - void OnMountRemovableDevice(const char* device_path, |
| - const char* mount_path, |
| - MountMethodErrorType error, |
| - const char* error_message) { |
| - DCHECK(device_path); |
| + void OnMountCompleted(MountError error_code, |
| + const char* source_path, |
| + MountType type, |
| + const char* mount_path) { |
| + DCHECK(source_path); |
| - if (error == MOUNT_METHOD_ERROR_NONE && device_path && mount_path) { |
| - std::string path(device_path); |
| + FireMountCompleted(error_code, source_path, type, mount_path); |
| + |
| + if (error_code == MOUNT_ERROR_NONE && |
| + mount_points_.find(source_path) == mount_points_.end()) { |
| + mount_points_.insert(MountPointMap::value_type(source_path, |
| + MountPointInfo(mount_path, type))); |
| + } |
| + |
| + if (error_code == MOUNT_ERROR_NONE && type == MOUNT_TYPE_DEVICE && |
| + source_path && mount_path) { |
| + std::string path(source_path); |
| DiskMap::iterator iter = disks_.find(path); |
| if (iter == disks_.end()) { |
| // disk might have been removed by now? |
| @@ -292,19 +298,18 @@ |
| DCHECK(disk); |
| disk->set_mount_path(mount_path); |
| FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); |
| - } else { |
| - LOG(WARNING) << "Mount request failed for device " |
| - << device_path << ", with error: " |
| - << (error_message ? error_message : "Unknown"); |
| } |
| } |
| - void OnUnmountRemovableDevice(const char* device_path, |
| - MountMethodErrorType error, |
| - const char* error_message) { |
| - DCHECK(device_path); |
| - if (error == MOUNT_METHOD_ERROR_NONE && device_path) { |
| - std::string path(device_path); |
| + void OnUnmountPath(const char* source_path, |
|
Oleg Eterevsky
2011/07/22 13:34:53
Can we throw an event here also? Probably the same
tbarzic
2011/07/22 17:21:29
Done.
|
| + MountMethodErrorType error, |
| + const char* error_message) { |
| + DCHECK(source_path); |
| + |
| + mount_points_.erase(source_path); |
|
tbarzic
2011/07/22 08:01:29
this should go into if bellow
tbarzic
2011/07/22 17:21:29
Done.
|
| + |
| + if (error == MOUNT_METHOD_ERROR_NONE && source_path) { |
| + std::string path(source_path); |
| DiskMap::iterator iter = disks_.find(path); |
| if (iter == disks_.end()) { |
| // disk might have been removed by now? |
| @@ -316,7 +321,7 @@ |
| FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk); |
| } else { |
| LOG(WARNING) << "Unmount request failed for device " |
| - << device_path << ", with error: " |
| + << source_path << ", with error: " |
| << (error_message ? error_message : "Unknown"); |
| } |
| } |
| @@ -476,14 +481,17 @@ |
| type = MOUNT_DEVICE_SCANNED; |
| break; |
| } |
| + default: { |
| + return; |
| + } |
| } |
| FireDeviceStatusUpdate(type, std::string(device_path)); |
| } |
| void Init() { |
| // Getting the monitor status so that the daemon starts up. |
| - mount_status_connection_ = MonitorMountEvents( |
| - &MonitorMountEventsHandler, this); |
| + mount_status_connection_ = MonitorAllMountEvents( |
| + &MonitorMountEventsHandler, &MountCompletedHandler, this); |
| } |
| void FireDiskStatusUpdate(MountLibraryEventType evt, |
| @@ -502,6 +510,19 @@ |
| Observer, observers_, DeviceChanged(evt, device_path)); |
| } |
| + void FireMountCompleted(MountError error_code, |
| + const char* source_path, |
| + MountType mount_type, |
| + const char* mount_path) { |
| + // Make sure we run on UI thread. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + FOR_EACH_OBSERVER( |
| + Observer, observers_, MountCompleted(error_code, |
| + source_path, |
| + mount_type, |
| + mount_path)); |
| + } |
| + |
| // Mount event change observers. |
| ObserverList<Observer> observers_; |
| @@ -512,6 +533,8 @@ |
| // The list of disks found. |
| MountLibrary::DiskMap disks_; |
| + MountLibrary::MountPointMap mount_points_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); |
| }; |
| @@ -524,9 +547,13 @@ |
| virtual void AddObserver(Observer* observer) OVERRIDE {} |
| virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
| virtual const DiskMap& disks() const OVERRIDE { return disks_; } |
| + virtual const MountPointMap& mount_points() const OVERRIDE { |
| + return mount_points_; |
| + } |
| virtual void RequestMountInfoRefresh() OVERRIDE {} |
| - virtual void MountPath(const char* device_path) OVERRIDE {} |
| - virtual void UnmountPath(const char* device_path) OVERRIDE {} |
| + virtual void MountPath(const char* source_path, MountType type, |
| + const MountPathOptions& options) OVERRIDE {} |
| + virtual void UnmountPath(const char* path) OVERRIDE {} |
| virtual void UnmountDeviceRecursive(const char* device_path, |
| UnmountDeviceRecursiveCallbackType callback, void* user_data) |
| OVERRIDE {} |
| @@ -534,6 +561,7 @@ |
| private: |
| // The list of disks found. |
| DiskMap disks_; |
| + MountPointMap mount_points_; |
| DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); |
| }; |