Chromium Code Reviews| Index: chrome/browser/chromeos/cros/mount_library.cc |
| diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc |
| index 2457a0912c7aacee0b38786882b95c27f57f581a..67b721a7b9ef269b08fccc084c0d58821f9d36e6 100644 |
| --- a/chrome/browser/chromeos/cros/mount_library.cc |
| +++ b/chrome/browser/chromeos/cros/mount_library.cc |
| @@ -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" |
| @@ -117,6 +118,52 @@ class MountLibraryImpl : public MountLibrary { |
| this); |
| } |
| + virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE { |
| + CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
achuithb
2011/07/21 00:58:21
DCHECK?
sidor
2011/07/21 18:24:15
Done.
|
| + if (!CrosLibrary::Get()->EnsureLoaded()) { |
| + OnFormatDevice(device_path, |
| + false, |
| + MOUNT_METHOD_ERROR_LOCAL, |
| + kLibraryNotLoaded); |
| + return; |
| + } |
| + FormatDevice(device_path, |
| + "vfat", // currently format in vfat by default |
| + &MountLibraryImpl::FormatDeviceCallback, |
| + this); |
| + } |
| + |
| + virtual void FormatMountedDevice(const char* device_mount_path) OVERRIDE { |
| + DCHECK(device_mount_path); |
| + std::string device_path = ""; |
| + std::string file_path = ""; |
|
achuithb
2011/07/21 00:58:21
Don't need = "", since the empty string is the def
sidor
2011/07/21 18:24:15
Done.
|
| + for (MountLibrary::DiskMap::iterator it = disks_.begin(); |
| + it != disks_.end(); ++it) { |
| + if (it->second->mount_path().compare(device_mount_path) == 0) { |
| + device_path = it->second->device_path(); |
| + file_path = it->second->file_path(); |
| + } |
| + } |
| + if (device_path.compare("") == 0) { |
|
achuithb
2011/07/21 00:58:21
Use device_path.empty()
sidor
2011/07/21 18:24:15
Done.
|
| + OnFormatDevice(device_path.c_str(), |
| + false, |
| + MOUNT_METHOD_ERROR_LOCAL, |
| + "Device with this mount path not found."); |
| + return; |
| + } |
| + PathMap::iterator it = to_be_formated_.find(device_path); |
| + if (it != to_be_formated_.end()) { |
|
achuithb
2011/07/21 00:58:21
You can just do:
if (to_be_formated_.find(device_p
sidor
2011/07/21 18:24:15
Done.
|
| + OnFormatDevice(device_path.c_str(), |
| + false, |
| + MOUNT_METHOD_ERROR_LOCAL, |
| + "Formatting is already pending."); |
| + return; |
| + } |
| + // Formatting process continues, after unmounting |
|
achuithb
2011/07/21 00:58:21
Period at the end of comments please.
sidor
2011/07/21 18:24:15
Done.
|
| + to_be_formated_[device_path] = file_path; |
| + UnmountPath(device_path.c_str()); |
| + } |
| + |
| virtual void UnmountDeviceRecursive(const char* device_path, |
| UnmountDeviceRecursiveCallbackType callback, void* user_data) |
| OVERRIDE { |
| @@ -207,6 +254,17 @@ class MountLibraryImpl : public MountLibrary { |
| 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* device_path, |
| @@ -225,7 +283,7 @@ class MountLibraryImpl : public MountLibrary { |
| cb_data->success = false; |
| } else if (error == MOUNT_METHOD_ERROR_NONE) { |
| LOG(WARNING) << device_path << " unmounted."; |
| - } |
| + } |
| // This is safe as long as all callbacks are called on the same thread as |
| // UnmountDeviceRecursive. |
| @@ -314,6 +372,13 @@ class MountLibraryImpl : public MountLibrary { |
| DCHECK(disk); |
| disk->clear_mount_path(); |
| FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk); |
| + // Check if there is a formatting scheduled |
| + PathMap::iterator it = to_be_formated_.find(device_path); |
| + if (it != to_be_formated_.end()) { |
| + const std::string* file_path = &(it->second); |
|
achuithb
2011/07/21 00:58:21
I don't think this is safe. You should do
const st
sidor
2011/07/21 18:24:15
That's really weird. It intuitively it shouldn't w
|
| + to_be_formated_.erase(it); |
| + FormatUnmountedDevice(file_path->c_str()); |
| + } |
| } else { |
| LOG(WARNING) << "Unmount request failed for device " |
| << device_path << ", with error: " |
| @@ -321,6 +386,24 @@ class MountLibraryImpl : public MountLibrary { |
| } |
| } |
| + 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("!").append(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, |
| @@ -476,6 +559,10 @@ class MountLibraryImpl : public MountLibrary { |
| type = MOUNT_DEVICE_SCANNED; |
| break; |
| } |
| + case FORMATTING_FINISHED: { |
| + type = MOUNT_FORMATTING_FINISHED; |
| + break; |
| + } |
| } |
| FireDeviceStatusUpdate(type, std::string(device_path)); |
| } |
| @@ -512,6 +599,10 @@ class MountLibraryImpl : public MountLibrary { |
| // The list of disks found. |
| MountLibrary::DiskMap disks_; |
| + // Set of devices that are supposed to be formated, but are currently waiting |
| + // to be unmounted |
|
achuithb
2011/07/21 00:58:21
Period at the end of comments please.
sidor
2011/07/21 18:24:15
Done.
|
| + PathMap to_be_formated_; |
|
achuithb
2011/07/21 00:58:21
Maybe format_pending_?
sidor
2011/07/21 18:24:15
That doesn't sound correct. This is map holding th
achuithb
2011/07/21 22:02:32
Isn't that what format_pending_ means? Format hasn
|
| + |
| DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); |
| }; |
| @@ -527,6 +618,8 @@ class MountLibraryStubImpl : public MountLibrary { |
| virtual void RequestMountInfoRefresh() OVERRIDE {} |
| virtual void MountPath(const char* device_path) OVERRIDE {} |
| virtual void UnmountPath(const char* device_path) OVERRIDE {} |
| + virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {} |
| + virtual void FormatMountedDevice(const char* device_mount_path) OVERRIDE {} |
| virtual void UnmountDeviceRecursive(const char* device_path, |
| UnmountDeviceRecursiveCallbackType callback, void* user_data) |
| OVERRIDE {} |