Chromium Code Reviews| 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..c36abd3d2a22eb4ba0c139cba66802b92de45aa4 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; |
| @@ -38,9 +40,7 @@ void Operation::Write(const base::Closure& continuation) { |
| 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,18 +50,51 @@ 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 = |
| chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); |
| + AddCleanUpFunction(base::Bind(&ClearImageBurner)); |
|
tbarzic
2014/05/15 00:58:58
AddCleanupFunction has DCHECK that it's on file th
Drew Haven
2014/05/15 02:00:28
Oh, I built release mode when I tested, so I didn'
|
| burner->SetEventHandlers( |
| base::Bind(&Operation::OnBurnFinished, this, continuation), |
| base::Bind(&Operation::OnBurnProgress, this)); |
| burner->BurnImage(image_path_.value(), |
| - device_path_.value(), |
| + target_path, |
| base::Bind(&Operation::OnBurnError, this)); |
| } |