| Index: chrome/browser/chromeos/cros/mount_library.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/cros/mount_library.cc (revision 95171)
|
| +++ chrome/browser/chromeos/cros/mount_library.cc (working copy)
|
| @@ -74,9 +74,6 @@
|
| is_read_only_(is_read_only),
|
| has_media_(has_media),
|
| on_boot_device_(on_boot_device) {
|
| - // Add trailing slash to mount path.
|
| - if (mount_path_.length() && mount_path_.at(mount_path_.length() -1) != '/')
|
| - mount_path_ = mount_path_.append("/");
|
| }
|
|
|
| MountLibrary::Disk::~Disk() {}
|
| @@ -134,15 +131,17 @@
|
| MountSourcePath(source_path, type, options, &MountCompletedHandler, this);
|
| }
|
|
|
| - virtual void UnmountPath(const char* path) OVERRIDE {
|
| + virtual void UnmountPath(const char* mount_path) OVERRIDE {
|
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| if (!CrosLibrary::Get()->EnsureLoaded()) {
|
| - OnUnmountPath(path,
|
| + OnUnmountPath(mount_path,
|
| MOUNT_METHOD_ERROR_LOCAL,
|
| kLibraryNotLoaded);
|
| return;
|
| }
|
| - UnmountMountPoint(path, &MountLibraryImpl::UnmountMountPointCallback, this);
|
| +
|
| + UnmountMountPoint(mount_path, &MountLibraryImpl::UnmountMountPointCallback,
|
| + this);
|
| }
|
|
|
| virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
|
| @@ -173,32 +172,31 @@
|
|
|
| virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {
|
| DCHECK(mount_path);
|
| - std::string device_path, file_path;
|
| + std::string file_path;
|
| for (MountLibrary::DiskMap::iterator it = disks_.begin();
|
| it != disks_.end(); ++it) {
|
| if (it->second->mount_path().compare(mount_path) == 0) {
|
| - device_path = it->second->device_path();
|
| file_path = it->second->file_path();
|
| break;
|
| }
|
| }
|
| - if (device_path.empty()) {
|
| - OnFormatDevice(device_path.c_str(),
|
| + if (file_path.empty()) {
|
| + OnFormatDevice(mount_path,
|
| false,
|
| MOUNT_METHOD_ERROR_LOCAL,
|
| "Device with this mount path not found.");
|
| return;
|
| }
|
| - if (formatting_pending_.find(device_path) != formatting_pending_.end()) {
|
| - OnFormatDevice(device_path.c_str(),
|
| + if (formatting_pending_.find(mount_path) != formatting_pending_.end()) {
|
| + OnFormatDevice(mount_path,
|
| false,
|
| MOUNT_METHOD_ERROR_LOCAL,
|
| "Formatting is already pending.");
|
| return;
|
| }
|
| // Formatting process continues, after unmounting.
|
| - formatting_pending_[device_path] = file_path;
|
| - UnmountPath(device_path.c_str());
|
| + formatting_pending_[mount_path] = file_path;
|
| + UnmountPath(mount_path);
|
| }
|
|
|
| virtual void UnmountDeviceRecursive(const char* device_path,
|
| @@ -215,16 +213,23 @@
|
| // Get list of all devices to unmount.
|
| int device_path_len = strlen(device_path);
|
| for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) {
|
| - if (strncmp(device_path, it->second->device_path().c_str(),
|
| - device_path_len) == 0) {
|
| - devices_to_unmount.push_back(it->second->device_path().c_str());
|
| + if (!it->second->mount_path().empty() &&
|
| + strncmp(device_path, it->second->device_path().c_str(),
|
| + device_path_len) == 0) {
|
| + devices_to_unmount.push_back(it->second->mount_path().c_str());
|
| }
|
| }
|
|
|
| // We should detect at least original device.
|
| if (devices_to_unmount.size() == 0) {
|
| - success = false;
|
| - error_message = kDeviceNotFound;
|
| + if (disks_.find(device_path) == disks_.end()) {
|
| + success = false;
|
| + error_message = kDeviceNotFound;
|
| + } else {
|
| + // Nothing to unmount.
|
| + callback(user_data, true);
|
| + return;
|
| + }
|
| }
|
| }
|
|
|
| @@ -280,12 +285,12 @@
|
|
|
| // Callback for UnmountRemovableDevice method.
|
| static void UnmountMountPointCallback(void* object,
|
| - const char* device_path,
|
| + const char* mount_path,
|
| MountMethodErrorType error,
|
| const char* error_message) {
|
| DCHECK(object);
|
| MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
|
| - self->OnUnmountPath(device_path, error, error_message);
|
| + self->OnUnmountPath(mount_path, error, error_message);
|
| }
|
|
|
| // Callback for FormatRemovableDevice method.
|
| @@ -301,7 +306,7 @@
|
|
|
| // Callback for UnmountDeviceRecursive.
|
| static void UnmountDeviceRecursiveCallback(void* object,
|
| - const char* device_path,
|
| + const char* mount_path,
|
| MountMethodErrorType error,
|
| const char* error_message) {
|
| DCHECK(object);
|
| @@ -309,13 +314,13 @@
|
| static_cast<UnmountDeviceRecursiveCallbackData*>(object);
|
|
|
| // Do standard processing for Unmount event.
|
| - cb_data->object->OnUnmountPath(device_path,
|
| + cb_data->object->OnUnmountPath(mount_path,
|
| error,
|
| error_message);
|
| if (error == MOUNT_METHOD_ERROR_LOCAL) {
|
| cb_data->success = false;
|
| } else if (error == MOUNT_METHOD_ERROR_NONE) {
|
| - LOG(WARNING) << device_path << " unmounted.";
|
| + LOG(INFO) << mount_path << " unmounted.";
|
| }
|
|
|
| // This is safe as long as all callbacks are called on the same thread as
|
| @@ -370,14 +375,12 @@
|
| const MountPointInfo& mount_info) {
|
| DCHECK(!mount_info.source_path.empty());
|
|
|
| - FireMountCompleted(MOUNTING,
|
| - error_code,
|
| - mount_info);
|
| + FireMountCompleted(MOUNTING, error_code, mount_info);
|
|
|
| if (error_code == MOUNT_ERROR_NONE &&
|
| - mount_points_.find(mount_info.source_path) == mount_points_.end()) {
|
| + mount_points_.find(mount_info.mount_path) == mount_points_.end()) {
|
| mount_points_.insert(MountPointMap::value_type(
|
| - mount_info.source_path.c_str(),
|
| + mount_info.mount_path.c_str(),
|
| mount_info));
|
| }
|
|
|
| @@ -398,13 +401,12 @@
|
| }
|
| }
|
|
|
| - void OnUnmountPath(const char* source_path,
|
| + void OnUnmountPath(const char* mount_path,
|
| MountMethodErrorType error,
|
| const char* error_message) {
|
| - DCHECK(source_path);
|
| -
|
| - if (error == MOUNT_METHOD_ERROR_NONE && source_path) {
|
| - MountPointMap::iterator mount_points_it = mount_points_.find(source_path);
|
| + DCHECK(mount_path);
|
| + if (error == MOUNT_METHOD_ERROR_NONE && mount_path) {
|
| + MountPointMap::iterator mount_points_it = mount_points_.find(mount_path);
|
| if (mount_points_it == mount_points_.end())
|
| return;
|
| // TODO(tbarzic): Add separate, PathUnmounted event to Observer.
|
| @@ -414,9 +416,9 @@
|
| MountPointInfo(mount_points_it->second.source_path.c_str(),
|
| mount_points_it->second.mount_path.c_str(),
|
| mount_points_it->second.mount_type));
|
| + std::string path(mount_points_it->second.source_path);
|
| mount_points_.erase(mount_points_it);
|
|
|
| - std::string path(source_path);
|
| DiskMap::iterator iter = disks_.find(path);
|
| if (iter == disks_.end()) {
|
| // disk might have been removed by now?
|
| @@ -427,7 +429,7 @@
|
| disk->clear_mount_path();
|
| FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk);
|
| // Check if there is a formatting scheduled
|
| - PathMap::iterator it = formatting_pending_.find(source_path);
|
| + PathMap::iterator it = formatting_pending_.find(mount_path);
|
| if (it != formatting_pending_.end()) {
|
| const std::string file_path = it->second;
|
| formatting_pending_.erase(it);
|
| @@ -435,7 +437,7 @@
|
| }
|
| } else {
|
| LOG(WARNING) << "Unmount request failed for device "
|
| - << source_path << ", with error: "
|
| + << mount_path << ", with error: "
|
| << (error_message ? error_message : "Unknown");
|
| }
|
| }
|
| @@ -457,7 +459,6 @@
|
| }
|
| }
|
|
|
| -
|
| void OnGetDiskProperties(const char* device_path,
|
| const DiskInfo* disk1,
|
| MountMethodErrorType error,
|
| @@ -691,7 +692,7 @@
|
| virtual void RequestMountInfoRefresh() OVERRIDE {}
|
| virtual void MountPath(const char* source_path, MountType type,
|
| const MountPathOptions& options) OVERRIDE {}
|
| - virtual void UnmountPath(const char* path) OVERRIDE {}
|
| + virtual void UnmountPath(const char* mount_path) OVERRIDE {}
|
| virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
|
| virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
|
| virtual void UnmountDeviceRecursive(const char* device_path,
|
|
|