| 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 "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 return; | 24 return; |
| 25 } | 25 } |
| 26 | 26 |
| 27 chromeos::DBusThreadManager::Get()-> | 27 chromeos::DBusThreadManager::Get()-> |
| 28 GetImageBurnerClient()-> | 28 GetImageBurnerClient()-> |
| 29 ResetEventHandlers(); | 29 ResetEventHandlers(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 void Operation::WriteStart() { | 34 void Operation::Write(const base::Closure& continuation) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 36 SetStage(image_writer_api::STAGE_WRITE); | 36 SetStage(image_writer_api::STAGE_WRITE); |
| 37 | 37 |
| 38 BrowserThread::PostTask(BrowserThread::UI, | 38 BrowserThread::PostTask( |
| 39 FROM_HERE, | 39 BrowserThread::UI, |
| 40 base::Bind(&Operation::StartWriteOnUIThread, this)); | 40 FROM_HERE, |
| 41 base::Bind(&Operation::StartWriteOnUIThread, this, continuation)); |
| 41 | 42 |
| 42 AddCleanUpFunction(base::Bind(&ClearImageBurner)); | 43 AddCleanUpFunction(base::Bind(&ClearImageBurner)); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void Operation::StartWriteOnUIThread() { | 46 void Operation::VerifyWrite(const base::Closure& continuation) { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 48 |
| 49 // No verification is available in Chrome OS currently. |
| 50 continuation.Run(); |
| 51 } |
| 52 |
| 53 void Operation::StartWriteOnUIThread(const base::Closure& continuation) { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 DVLOG(1) << "Starting burn."; | |
| 48 | 55 |
| 49 ImageBurnerClient* burner = | 56 ImageBurnerClient* burner = |
| 50 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); | 57 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); |
| 51 | 58 |
| 52 burner->SetEventHandlers( | 59 burner->SetEventHandlers( |
| 53 base::Bind(&Operation::OnBurnFinished, this), | 60 base::Bind(&Operation::OnBurnFinished, this, continuation), |
| 54 base::Bind(&Operation::OnBurnProgress, this)); | 61 base::Bind(&Operation::OnBurnProgress, this)); |
| 55 | 62 |
| 56 burner->BurnImage(image_path_.value(), | 63 burner->BurnImage(image_path_.value(), |
| 57 storage_unit_id_, | 64 device_path_.value(), |
| 58 base::Bind(&Operation::OnBurnError, this)); | 65 base::Bind(&Operation::OnBurnError, this)); |
| 59 } | 66 } |
| 60 | 67 |
| 61 void Operation::OnBurnFinished(const std::string& target_path, | 68 void Operation::OnBurnFinished(const base::Closure& continuation, |
| 62 bool success, | 69 const std::string& target_path, |
| 63 const std::string& error) { | 70 bool success, |
| 64 DVLOG(1) << "Burn finished: " << success; | 71 const std::string& error) { |
| 65 | |
| 66 if (success) { | 72 if (success) { |
| 67 SetProgress(kProgressComplete); | 73 SetProgress(kProgressComplete); |
| 68 Finish(); | 74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); |
| 69 } else { | 75 } else { |
| 70 Error(error); | 76 DLOG(ERROR) << "Error encountered while burning: " << error; |
| 77 Error(error::kChromeOSImageBurnerError); |
| 71 } | 78 } |
| 72 } | 79 } |
| 73 | 80 |
| 74 void Operation::OnBurnProgress(const std::string& target_path, | 81 void Operation::OnBurnProgress(const std::string& target_path, |
| 75 int64 num_bytes_burnt, | 82 int64 num_bytes_burnt, |
| 76 int64 total_size) { | 83 int64 total_size) { |
| 77 int progress = kProgressComplete * num_bytes_burnt / total_size; | 84 int progress = kProgressComplete * num_bytes_burnt / total_size; |
| 78 SetProgress(progress); | 85 SetProgress(progress); |
| 79 } | 86 } |
| 80 | 87 |
| 81 void Operation::OnBurnError() { | 88 void Operation::OnBurnError() { |
| 82 Error(error::kChromeOSImageBurnerError); | 89 Error(error::kChromeOSImageBurnerError); |
| 83 } | 90 } |
| 84 | 91 |
| 85 } // namespace image_writer | 92 } // namespace image_writer |
| 86 } // namespace extensions | 93 } // namespace extensions |
| OLD | NEW |