| Index: chrome/browser/chromeos/cros/mount_library.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/cros/mount_library.cc (revision 96422)
|
| +++ chrome/browser/chromeos/cros/mount_library.cc (working copy)
|
| @@ -5,6 +5,7 @@
|
| #include "chrome/browser/chromeos/cros/mount_library.h"
|
|
|
| #include <set>
|
| +#include <vector>
|
|
|
| #include "base/message_loop.h"
|
| #include "base/string_util.h"
|
| @@ -143,6 +144,63 @@
|
| this);
|
| }
|
|
|
| + virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (!CrosLibrary::Get()->EnsureLoaded()) {
|
| + OnFormatDevice(file_path,
|
| + false,
|
| + MOUNT_METHOD_ERROR_LOCAL,
|
| + kLibraryNotLoaded);
|
| + return;
|
| + }
|
| + for (MountLibrary::DiskMap::iterator it = disks_.begin();
|
| + it != disks_.end(); ++it) {
|
| + if (it->second->file_path().compare(file_path) == 0 &&
|
| + !it->second->mount_path().empty()) {
|
| + OnFormatDevice(file_path,
|
| + false,
|
| + MOUNT_METHOD_ERROR_LOCAL,
|
| + "Device is still mounted.");
|
| + return;
|
| + }
|
| + }
|
| + FormatDevice(file_path,
|
| + "vfat", // currently format in vfat by default
|
| + &MountLibraryImpl::FormatDeviceCallback,
|
| + this);
|
| + }
|
| +
|
| + virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {
|
| + DCHECK(mount_path);
|
| + Disk* disk = NULL;
|
| + for (MountLibrary::DiskMap::iterator it = disks_.begin();
|
| + it != disks_.end(); ++it) {
|
| + if (it->second->mount_path().compare(mount_path) == 0) {
|
| + disk = it->second;
|
| + break;
|
| + }
|
| + }
|
| +
|
| + if (!disk) {
|
| + OnFormatDevice(disk->device_path().c_str(),
|
| + false,
|
| + MOUNT_METHOD_ERROR_LOCAL,
|
| + "Device with this mount path not found.");
|
| + return;
|
| + }
|
| + if (formatting_pending_.find(disk->device_path()) !=
|
| + formatting_pending_.end()) {
|
| + OnFormatDevice(disk->device_path().c_str(),
|
| + false,
|
| + MOUNT_METHOD_ERROR_LOCAL,
|
| + "Formatting is already pending.");
|
| + return;
|
| + }
|
| + // Formatting process continues, after unmounting.
|
| + formatting_pending_[disk->device_path()] = disk->file_path();
|
| + UnmountPath(disk->mount_path().c_str());
|
| + }
|
| +
|
| virtual void UnmountDeviceRecursive(const char* device_path,
|
| UnmountDeviceRecursiveCallbackType callback, void* user_data)
|
| OVERRIDE {
|
| @@ -237,6 +295,17 @@
|
| self->OnUnmountPath(mount_path, error, error_message);
|
| }
|
|
|
| + // Callback for FormatRemovableDevice method.
|
| + static void FormatDeviceCallback(void* object,
|
| + const char* device_path,
|
| + bool success,
|
| + MountMethodErrorType error,
|
| + const char* error_message) {
|
| + DCHECK(object);
|
| + MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
|
| + self->OnFormatDevice(device_path, success, error, error_message);
|
| + }
|
| +
|
| // Callback for UnmountDeviceRecursive.
|
| static void UnmountDeviceRecursiveCallback(void* object,
|
| const char* mount_path,
|
| @@ -254,7 +323,7 @@
|
| cb_data->success = false;
|
| } else if (error == MOUNT_METHOD_ERROR_NONE) {
|
| LOG(INFO) << mount_path << " unmounted.";
|
| - }
|
| + }
|
|
|
| // This is safe as long as all callbacks are called on the same thread as
|
| // UnmountDeviceRecursive.
|
| @@ -351,16 +420,21 @@
|
| mount_points_it->second.mount_type));
|
| std::string path(mount_points_it->second.source_path);
|
| mount_points_.erase(mount_points_it);
|
| -
|
| DiskMap::iterator iter = disks_.find(path);
|
| if (iter == disks_.end()) {
|
| - // disk might have been removed by now?
|
| + // disk might have been removed by now.
|
| return;
|
| }
|
| Disk* disk = iter->second;
|
| DCHECK(disk);
|
| disk->clear_mount_path();
|
| - FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk);
|
| + // Check if there is a formatting scheduled
|
| + PathMap::iterator it = formatting_pending_.find(disk->device_path());
|
| + if (it != formatting_pending_.end()) {
|
| + const std::string file_path = it->second;
|
| + formatting_pending_.erase(it);
|
| + FormatUnmountedDevice(file_path.c_str());
|
| + }
|
| } else {
|
| LOG(WARNING) << "Unmount request failed for device "
|
| << mount_path << ", with error: "
|
| @@ -368,6 +442,23 @@
|
| }
|
| }
|
|
|
| + void OnFormatDevice(const char* device_path,
|
| + bool success,
|
| + MountMethodErrorType error,
|
| + const char* error_message) {
|
| + DCHECK(device_path);
|
| + if (error == MOUNT_METHOD_ERROR_NONE && device_path && success) {
|
| + FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path);
|
| + } else {
|
| + FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED,
|
| + std::string("!") + device_path);
|
| + LOG(WARNING) << "Format request failed for device "
|
| + << device_path << ", with error: "
|
| + << (error_message ? error_message : "Unknown");
|
| + }
|
| + }
|
| +
|
| +
|
| void OnGetDiskProperties(const char* device_path,
|
| const DiskInfo* disk1,
|
| MountMethodErrorType error,
|
| @@ -523,6 +614,10 @@
|
| type = MOUNT_DEVICE_SCANNED;
|
| break;
|
| }
|
| + case FORMATTING_FINISHED: {
|
| + type = MOUNT_FORMATTING_FINISHED;
|
| + break;
|
| + }
|
| default: {
|
| return;
|
| }
|
| @@ -574,6 +669,10 @@
|
| MountLibrary::DiskMap disks_;
|
|
|
| MountLibrary::MountPointMap mount_points_;
|
| + // Set of devices that are supposed to be formated, but are currently waiting
|
| + // to be unmounted. When device is in this map, the formatting process HAVEN'T
|
| + // started yet.
|
| + PathMap formatting_pending_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
|
| };
|
| @@ -594,6 +693,8 @@
|
| virtual void MountPath(const char* source_path, MountType type,
|
| const MountPathOptions& options) 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,
|
| UnmountDeviceRecursiveCallbackType callback, void* user_data)
|
| OVERRIDE {}
|
|
|