Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Unified Diff: chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc

Issue 282853003: Unmounts volumes before writing to a drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds function comments and reorganizes the unmount operation slightly. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc
diff --git a/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc b/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc
index ceaf76bc30911c395fe0dcc3e05c849ff3af505f..0aff9b981bbeafa6079f0f89ede0aca3dbabffcd 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc
+++ b/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc
@@ -6,11 +6,13 @@
#include "chrome/browser/extensions/api/image_writer_private/operation.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_burner_client.h"
+#include "chromeos/disks/disk_mount_manager.h"
#include "content/public/browser/browser_thread.h"
namespace extensions {
namespace image_writer {
+using chromeos::disks::DiskMountManager;
using chromeos::ImageBurnerClient;
using content::BrowserThread;
@@ -35,12 +37,7 @@ void Operation::Write(const base::Closure& continuation) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
SetStage(image_writer_api::STAGE_WRITE);
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&Operation::StartWriteOnUIThread, this, continuation));
-
- AddCleanUpFunction(base::Bind(&ClearImageBurner));
+ UnmountVolumes(continuation);
}
void Operation::VerifyWrite(const base::Closure& continuation) {
@@ -50,7 +47,44 @@ void Operation::VerifyWrite(const base::Closure& continuation) {
continuation.Run();
}
-void Operation::StartWriteOnUIThread(const base::Closure& continuation) {
+void Operation::UnmountVolumes(const base::Closure& continuation) {
+ LOG(ERROR) << "Unmounting volumes.";
tbarzic 2014/05/13 20:09:33 remove this
Drew Haven 2014/05/15 00:30:04 Oops. I had trouble deploying a debug build to my
tbarzic 2014/05/15 00:58:58 hehe, I usually do something similar.
+
+ DiskMountManager::GetInstance()->UnmountDeviceRecursively(
tbarzic 2014/05/13 20:09:33 this should be done on UI thread
Drew Haven 2014/05/15 00:30:04 Really? It feels like a File/IO thing since it ei
tbarzic 2014/05/15 00:58:58 it's just sending dbus message to disks process wh
+ device_path_.value(),
+ base::Bind(&Operation::UnmountVolumesCallback, this, continuation));
+}
+
+void Operation::UnmountVolumesCallback(const base::Closure& continuation,
+ bool success) {
+ if (!success) {
+ LOG(ERROR) << "Volume unmounting failed.";
+ Error(error::kUnmountVolumesError);
+ return;
+ }
+
+ const DiskMountManager::DiskMap& disks =
+ DiskMountManager::GetInstance()->disks();
+ DiskMountManager::DiskMap::const_iterator iter =
+ disks.find(device_path_.value());
+
+ if (iter == disks.end()) {
+ LOG(ERROR) << "Disk not found in disk list after unmounting volumes.";
+ Error(error::kUnmountVolumesError);
+ return;
+ }
+
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&Operation::StartWriteOnUIThread,
+ this,
+ iter->second->file_path(),
+ continuation));
+ AddCleanUpFunction(base::Bind(&ClearImageBurner));
+}
+
+void Operation::StartWriteOnUIThread(const std::string& target_path,
+ const base::Closure& continuation) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ImageBurnerClient* burner =
@@ -61,7 +95,7 @@ void Operation::StartWriteOnUIThread(const base::Closure& continuation) {
base::Bind(&Operation::OnBurnProgress, this));
burner->BurnImage(image_path_.value(),
- device_path_.value(),
+ target_path,
base::Bind(&Operation::OnBurnError, this));
}

Powered by Google App Engine
This is Rietveld 408576698