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(BrowserThread::UI, |
39 FROM_HERE, | 39 FROM_HERE, |
40 base::Bind(&Operation::StartWriteOnUIThread, this)); | 40 base::Bind(&Operation::StartWriteOnUIThread, |
| 41 this, |
| 42 continuation)); |
41 | 43 |
42 AddCleanUpFunction(base::Bind(&ClearImageBurner)); | 44 AddCleanUpFunction(base::Bind(&ClearImageBurner)); |
43 } | 45 } |
44 | 46 |
45 void Operation::StartWriteOnUIThread() { | 47 void Operation::VerifyWrite(const base::Closure& continuation) { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 49 |
| 50 // No verification is available in Chrome OS currently. |
| 51 continuation.Run(); |
| 52 } |
| 53 |
| 54 void Operation::StartWriteOnUIThread(const base::Closure& continuation) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 DVLOG(1) << "Starting burn."; | 56 DVLOG(1) << "Starting burn."; |
48 | 57 |
49 ImageBurnerClient* burner = | 58 ImageBurnerClient* burner = |
50 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); | 59 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); |
51 | 60 |
52 burner->SetEventHandlers( | 61 burner->SetEventHandlers( |
53 base::Bind(&Operation::OnBurnFinished, this), | 62 base::Bind(&Operation::OnBurnFinished, this, continuation), |
54 base::Bind(&Operation::OnBurnProgress, this)); | 63 base::Bind(&Operation::OnBurnProgress, this)); |
55 | 64 |
56 burner->BurnImage(image_path_.value(), | 65 burner->BurnImage(image_path_.value(), |
57 storage_unit_id_, | 66 device_path_.value(), |
58 base::Bind(&Operation::OnBurnError, this)); | 67 base::Bind(&Operation::OnBurnError, this)); |
59 } | 68 } |
60 | 69 |
61 void Operation::OnBurnFinished(const std::string& target_path, | 70 void Operation::OnBurnFinished(const base::Closure& continuation, |
62 bool success, | 71 const std::string& target_path, |
63 const std::string& error) { | 72 bool success, |
64 DVLOG(1) << "Burn finished: " << success; | 73 const std::string& error) { |
65 | |
66 if (success) { | 74 if (success) { |
67 SetProgress(kProgressComplete); | 75 SetProgress(kProgressComplete); |
68 Finish(); | 76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); |
69 } else { | 77 } else { |
70 Error(error); | 78 DLOG(ERROR) << "Error encountered while burning: " << error; |
| 79 Error(error::kChromeOSImageBurnerError); |
71 } | 80 } |
72 } | 81 } |
73 | 82 |
74 void Operation::OnBurnProgress(const std::string& target_path, | 83 void Operation::OnBurnProgress(const std::string& target_path, |
75 int64 num_bytes_burnt, | 84 int64 num_bytes_burnt, |
76 int64 total_size) { | 85 int64 total_size) { |
77 int progress = kProgressComplete * num_bytes_burnt / total_size; | 86 int progress = kProgressComplete * num_bytes_burnt / total_size; |
78 SetProgress(progress); | 87 SetProgress(progress); |
79 } | 88 } |
80 | 89 |
81 void Operation::OnBurnError() { | 90 void Operation::OnBurnError() { |
82 Error(error::kChromeOSImageBurnerError); | 91 Error(error::kChromeOSImageBurnerError); |
83 } | 92 } |
84 | 93 |
85 } // namespace image_writer | 94 } // namespace image_writer |
86 } // namespace extensions | 95 } // namespace extensions |
OLD | NEW |