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..053924f1790637982f71b7c50348b9e64f6b04ac 100644 |
--- a/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc |
+++ b/chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc |
@@ -6,16 +6,20 @@ |
#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; |
namespace { |
+// TODO(haven): The Image Burner cannot handle multiple burns. crbug.com/373575 |
tbarzic
2014/05/15 16:41:40
nit: I'd put this in StartWriteOnUIThread
Drew Haven
2014/05/15 17:37:21
Done. But now it is longer than 80 chars and I ha
|
+ |
void ClearImageBurner() { |
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
BrowserThread::PostTask(BrowserThread::UI, |
@@ -35,12 +39,13 @@ void Operation::Write(const base::Closure& continuation) { |
DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
SetStage(image_writer_api::STAGE_WRITE); |
+ // Note this has to be run on the FILE thread to avoid concurrent access. |
+ AddCleanUpFunction(base::Bind(&ClearImageBurner)); |
+ |
BrowserThread::PostTask( |
BrowserThread::UI, |
FROM_HERE, |
- base::Bind(&Operation::StartWriteOnUIThread, this, continuation)); |
- |
- AddCleanUpFunction(base::Bind(&ClearImageBurner)); |
+ base::Bind(&Operation::UnmountVolumes, this, continuation)); |
} |
void Operation::VerifyWrite(const base::Closure& continuation) { |
@@ -50,7 +55,39 @@ void Operation::VerifyWrite(const base::Closure& continuation) { |
continuation.Run(); |
} |
-void Operation::StartWriteOnUIThread(const base::Closure& continuation) { |
+void Operation::UnmountVolumes(const base::Closure& continuation) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ DiskMountManager::GetInstance()->UnmountDeviceRecursively( |
+ device_path_.value(), |
+ base::Bind(&Operation::UnmountVolumesCallback, this, continuation)); |
+} |
+ |
+void Operation::UnmountVolumesCallback(const base::Closure& continuation, |
+ bool success) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ |
+ 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; |
+ } |
+ |
+ StartWriteOnUIThread(iter->second->file_path(), continuation); |
+} |
+ |
+void Operation::StartWriteOnUIThread(const std::string& target_path, |
+ const base::Closure& continuation) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
ImageBurnerClient* burner = |
@@ -61,7 +98,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)); |
} |