Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 6 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | 6 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| 7 #include "chromeos/dbus/dbus_thread_manager.h" | 7 #include "chromeos/dbus/dbus_thread_manager.h" |
| 8 #include "chromeos/dbus/image_burner_client.h" | 8 #include "chromeos/dbus/image_burner_client.h" |
| 9 #include "chromeos/disks/disk_mount_manager.h" | |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 10 | 11 |
| 11 namespace extensions { | 12 namespace extensions { |
| 12 namespace image_writer { | 13 namespace image_writer { |
| 13 | 14 |
| 15 using chromeos::disks::DiskMountManager; | |
| 14 using chromeos::ImageBurnerClient; | 16 using chromeos::ImageBurnerClient; |
| 15 using content::BrowserThread; | 17 using content::BrowserThread; |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 void ClearImageBurner() { | 21 void ClearImageBurner() { |
| 20 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 22 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 21 BrowserThread::PostTask(BrowserThread::UI, | 23 BrowserThread::PostTask(BrowserThread::UI, |
| 22 FROM_HERE, | 24 FROM_HERE, |
| 23 base::Bind(&ClearImageBurner)); | 25 base::Bind(&ClearImageBurner)); |
| 24 return; | 26 return; |
| 25 } | 27 } |
| 26 | 28 |
| 27 chromeos::DBusThreadManager::Get()-> | 29 chromeos::DBusThreadManager::Get()-> |
| 28 GetImageBurnerClient()-> | 30 GetImageBurnerClient()-> |
| 29 ResetEventHandlers(); | 31 ResetEventHandlers(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 } // namespace | 34 } // namespace |
| 33 | 35 |
| 34 void Operation::Write(const base::Closure& continuation) { | 36 void Operation::Write(const base::Closure& continuation) { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 37 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 36 SetStage(image_writer_api::STAGE_WRITE); | 38 SetStage(image_writer_api::STAGE_WRITE); |
| 37 | 39 |
| 38 BrowserThread::PostTask( | 40 UnmountVolumes(continuation); |
| 39 BrowserThread::UI, | |
| 40 FROM_HERE, | |
| 41 base::Bind(&Operation::StartWriteOnUIThread, this, continuation)); | |
| 42 | |
| 43 AddCleanUpFunction(base::Bind(&ClearImageBurner)); | |
| 44 } | 41 } |
| 45 | 42 |
| 46 void Operation::VerifyWrite(const base::Closure& continuation) { | 43 void Operation::VerifyWrite(const base::Closure& continuation) { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 44 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 48 | 45 |
| 49 // No verification is available in Chrome OS currently. | 46 // No verification is available in Chrome OS currently. |
| 50 continuation.Run(); | 47 continuation.Run(); |
| 51 } | 48 } |
| 52 | 49 |
| 53 void Operation::StartWriteOnUIThread(const base::Closure& continuation) { | 50 void Operation::UnmountVolumes(const base::Closure& continuation) { |
| 51 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.
| |
| 52 | |
| 53 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
| |
| 54 device_path_.value(), | |
| 55 base::Bind(&Operation::UnmountVolumesCallback, this, continuation)); | |
| 56 } | |
| 57 | |
| 58 void Operation::UnmountVolumesCallback(const base::Closure& continuation, | |
| 59 bool success) { | |
| 60 if (!success) { | |
| 61 LOG(ERROR) << "Volume unmounting failed."; | |
| 62 Error(error::kUnmountVolumesError); | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 const DiskMountManager::DiskMap& disks = | |
| 67 DiskMountManager::GetInstance()->disks(); | |
| 68 DiskMountManager::DiskMap::const_iterator iter = | |
| 69 disks.find(device_path_.value()); | |
| 70 | |
| 71 if (iter == disks.end()) { | |
| 72 LOG(ERROR) << "Disk not found in disk list after unmounting volumes."; | |
| 73 Error(error::kUnmountVolumesError); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 BrowserThread::PostTask(BrowserThread::UI, | |
| 78 FROM_HERE, | |
| 79 base::Bind(&Operation::StartWriteOnUIThread, | |
| 80 this, | |
| 81 iter->second->file_path(), | |
| 82 continuation)); | |
| 83 AddCleanUpFunction(base::Bind(&ClearImageBurner)); | |
| 84 } | |
| 85 | |
| 86 void Operation::StartWriteOnUIThread(const std::string& target_path, | |
| 87 const base::Closure& continuation) { | |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 55 | 89 |
| 56 ImageBurnerClient* burner = | 90 ImageBurnerClient* burner = |
| 57 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); | 91 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); |
| 58 | 92 |
| 59 burner->SetEventHandlers( | 93 burner->SetEventHandlers( |
|
tbarzic
2014/05/13 20:09:33
can you add a todo to handle a case where another
Drew Haven
2014/05/15 00:30:04
Won't that be handled by the error handler? We mak
tbarzic
2014/05/15 00:58:58
ImageBurnerClient can handle max one burn operatio
Drew Haven
2014/05/15 02:00:28
I added a guard to only allow one burn operation a
| |
| 60 base::Bind(&Operation::OnBurnFinished, this, continuation), | 94 base::Bind(&Operation::OnBurnFinished, this, continuation), |
| 61 base::Bind(&Operation::OnBurnProgress, this)); | 95 base::Bind(&Operation::OnBurnProgress, this)); |
| 62 | 96 |
| 63 burner->BurnImage(image_path_.value(), | 97 burner->BurnImage(image_path_.value(), |
| 64 device_path_.value(), | 98 target_path, |
| 65 base::Bind(&Operation::OnBurnError, this)); | 99 base::Bind(&Operation::OnBurnError, this)); |
| 66 } | 100 } |
| 67 | 101 |
| 68 void Operation::OnBurnFinished(const base::Closure& continuation, | 102 void Operation::OnBurnFinished(const base::Closure& continuation, |
| 69 const std::string& target_path, | 103 const std::string& target_path, |
| 70 bool success, | 104 bool success, |
| 71 const std::string& error) { | 105 const std::string& error) { |
| 72 if (success) { | 106 if (success) { |
| 73 SetProgress(kProgressComplete); | 107 SetProgress(kProgressComplete); |
| 74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); | 108 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); |
| 75 } else { | 109 } else { |
| 76 DLOG(ERROR) << "Error encountered while burning: " << error; | 110 DLOG(ERROR) << "Error encountered while burning: " << error; |
| 77 Error(error::kChromeOSImageBurnerError); | 111 Error(error::kChromeOSImageBurnerError); |
| 78 } | 112 } |
| 79 } | 113 } |
| 80 | 114 |
| 81 void Operation::OnBurnProgress(const std::string& target_path, | 115 void Operation::OnBurnProgress(const std::string& target_path, |
| 82 int64 num_bytes_burnt, | 116 int64 num_bytes_burnt, |
| 83 int64 total_size) { | 117 int64 total_size) { |
| 84 int progress = kProgressComplete * num_bytes_burnt / total_size; | 118 int progress = kProgressComplete * num_bytes_burnt / total_size; |
| 85 SetProgress(progress); | 119 SetProgress(progress); |
| 86 } | 120 } |
| 87 | 121 |
| 88 void Operation::OnBurnError() { | 122 void Operation::OnBurnError() { |
| 89 Error(error::kChromeOSImageBurnerError); | 123 Error(error::kChromeOSImageBurnerError); |
| 90 } | 124 } |
| 91 | 125 |
| 92 } // namespace image_writer | 126 } // namespace image_writer |
| 93 } // namespace extensions | 127 } // namespace extensions |
| OLD | NEW |