diff options
Diffstat (limited to 'chromeos/disks/disk_mount_manager.cc')
-rw-r--r-- | chromeos/disks/disk_mount_manager.cc | 76 |
1 files changed, 34 insertions, 42 deletions
diff --git a/chromeos/disks/disk_mount_manager.cc b/chromeos/disks/disk_mount_manager.cc index a781107..75ab642 100644 --- a/chromeos/disks/disk_mount_manager.cc +++ b/chromeos/disks/disk_mount_manager.cc @@ -31,11 +31,15 @@ class DiskMountManagerImpl : public DiskMountManager { DCHECK(dbus_thread_manager); cros_disks_client_ = dbus_thread_manager->GetCrosDisksClient(); DCHECK(cros_disks_client_); - cros_disks_client_->SetUpConnections( + cros_disks_client_->SetMountEventHandler( base::Bind(&DiskMountManagerImpl::OnMountEvent, - weak_ptr_factory_.GetWeakPtr()), + weak_ptr_factory_.GetWeakPtr())); + cros_disks_client_->SetMountCompletedHandler( base::Bind(&DiskMountManagerImpl::OnMountCompleted, weak_ptr_factory_.GetWeakPtr())); + cros_disks_client_->SetFormatCompletedHandler( + base::Bind(&DiskMountManagerImpl::OnFormatCompleted, + weak_ptr_factory_.GetWeakPtr())); } virtual ~DiskMountManagerImpl() { @@ -280,7 +284,7 @@ class DiskMountManagerImpl : public DiskMountManager { if (success) { // Do standard processing for Unmount event. OnUnmountPath(UnmountPathCallback(), true, mount_path); - LOG(INFO) << mount_path << " unmounted."; + VLOG(1) << mount_path << " unmounted."; } // This is safe as long as all callbacks are called on the same thread as // UnmountDeviceRecursively. @@ -407,6 +411,33 @@ class DiskMountManagerImpl : public DiskMountManager { NotifyFormatStatusUpdate(FORMAT_STARTED, error_code, device_path); } + // Callback to handle FormatCompleted signal and Format method call failure. + void OnFormatCompleted(FormatError error_code, + const std::string& device_path) { + std::string actual_device_path; + // Depending on cros-disks implementation the event may return either file + // path or device path. We want to use device path. + // TODO(benchan): This shouldn't be necessary. Find out the issue and ensure + // that cros-disks simply returns the path format that Chrome expects, then + // we should remove the following code. + for (DiskMountManager::DiskMap::const_iterator it = disks_.begin(); + it != disks_.end(); ++it) { + if (it->second->file_path() == device_path || + it->second->device_path() == device_path) { + actual_device_path = it->second->device_path(); + break; + } + } + + if (actual_device_path.empty()) { + LOG(ERROR) << "Error while handling disks metadata. Cannot find " + << "device that is being formatted."; + return; + } + + NotifyFormatStatusUpdate(FORMAT_COMPLETED, error_code, actual_device_path); + } + // Callbcak for GetDeviceProperties. void OnGetDeviceProperties(const DiskInfo& disk_info) { // TODO(zelidrag): Find a better way to filter these out before we @@ -513,20 +544,6 @@ class DiskMountManagerImpl : public DiskMountManager { NotifyDeviceStatusUpdate(DEVICE_SCANNED, device_path); break; } - case CROS_DISKS_FORMATTING_FINISHED: { - std::string path; - FormatError error_code; - ParseFormatFinishedPath(device_path, &path, &error_code); - - if (!path.empty()) { - NotifyFormatStatusUpdate(FORMAT_COMPLETED, error_code, path); - break; - } - - LOG(ERROR) << "Error while handling disks metadata. Cannot find " - << "device that is being formatted."; - break; - } default: { LOG(ERROR) << "Unknown event: " << event; } @@ -560,31 +577,6 @@ class DiskMountManagerImpl : public DiskMountManager { OnFormatEvent(event, error_code, device_path)); } - // Converts file path to device path. - void ParseFormatFinishedPath(const std::string& received_path, - std::string* device_path, - FormatError* error_code) { - // TODO(tbarzic): Refactor error handling code like here. - // Appending "!" is not the best way to indicate error. This kind of trick - // also makes it difficult to simplify the code paths. - bool success = !StartsWithASCII(received_path, "!", true); - *error_code = success ? FORMAT_ERROR_NONE : FORMAT_ERROR_UNKNOWN; - - std::string path = received_path.substr(success ? 0 : 1); - - // Depending on cros disks implementation the event may return either file - // path or device path. We want to use device path. - for (DiskMountManager::DiskMap::iterator it = disks_.begin(); - it != disks_.end(); ++it) { - // Skip the leading '!' on the failure case. - if (it->second->file_path() == path || - it->second->device_path() == path) { - *device_path = it->second->device_path(); - return; - } - } - } - // Finds system path prefix from |system_path|. const std::string& FindSystemPathPrefix(const std::string& system_path) { if (system_path.empty()) |