Remount external device even if formatting fails

Transient issues may cause formatting to fail, so remount the device to
let the user see what happened to the device, and also try format it
again.

Bug: 965806
Change-Id: I4e95f050dd4d48fbe11527be000cfa4c34b22d0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624005
Reviewed-by: Anand Mistry <amistry@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662499}
diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc
index c1ab69c..7e137ca 100644
--- a/chrome/browser/chromeos/file_manager/volume_manager.cc
+++ b/chrome/browser/chromeos/file_manager/volume_manager.cc
@@ -945,16 +945,14 @@
       }
       return;
     case chromeos::disks::DiskMountManager::FORMAT_COMPLETED:
-      if (error_code == chromeos::FORMAT_ERROR_NONE) {
-        // If format is completed successfully, try to mount the device.
-        // MountPath auto-detects filesystem format if second argument is
-        // empty. The third argument (mount label) is not used in a disk mount
-        // operation.
-        disk_mount_manager_->MountPath(device_path, std::string(),
-                                       std::string(), {},
-                                       chromeos::MOUNT_TYPE_DEVICE,
-                                       GetExternalStorageAccessMode(profile_));
-      }
+      // Even if format did not complete successfully, try to mount the device
+      // so the user can retry.
+      // MountPath auto-detects filesystem format if second argument is
+      // empty. The third argument (mount label) is not used in a disk mount
+      // operation.
+      disk_mount_manager_->MountPath(device_path, std::string(), std::string(),
+                                     {}, chromeos::MOUNT_TYPE_DEVICE,
+                                     GetExternalStorageAccessMode(profile_));
 
       for (auto& observer : observers_) {
         observer.OnFormatCompleted(device_path,
diff --git a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc
index a753090..18c0464 100644
--- a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc
+++ b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc
@@ -717,7 +717,7 @@
   EXPECT_EQ("device1", event.device_path);
   EXPECT_TRUE(event.success);
 
-  // When "format" is successfully done, VolumeManager requests to mount it.
+  // When "format" is done, VolumeManager requests to mount it.
   ASSERT_EQ(1U, disk_mount_manager_->mount_requests().size());
   const FakeDiskMountManager::MountRequest& mount_request =
       disk_mount_manager_->mount_requests()[0];
@@ -742,7 +742,14 @@
   EXPECT_EQ("device1", event.device_path);
   EXPECT_FALSE(event.success);
 
-  EXPECT_EQ(0U, disk_mount_manager_->mount_requests().size());
+  // When "format" is done, VolumeManager requests to mount it.
+  ASSERT_EQ(1U, disk_mount_manager_->mount_requests().size());
+  const FakeDiskMountManager::MountRequest& mount_request =
+      disk_mount_manager_->mount_requests()[0];
+  EXPECT_EQ("device1", mount_request.source_path);
+  EXPECT_EQ("", mount_request.source_format);
+  EXPECT_EQ("", mount_request.mount_label);
+  EXPECT_EQ(chromeos::MOUNT_TYPE_DEVICE, mount_request.type);
 
   volume_manager()->RemoveObserver(&observer);
 }