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 "base/file_util.h" |
| 6 #include "base/files/file_enumerator.h" |
5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
6 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
| 10 #include "content/public/browser/browser_thread.h" |
7 | 11 |
8 namespace extensions { | 12 namespace extensions { |
9 namespace image_writer { | 13 namespace image_writer { |
10 | 14 |
| 15 using content::BrowserThread; |
| 16 |
11 void Operation::WriteStart() { | 17 void Operation::WriteStart() { |
12 Error(error::kUnsupportedOperation); | 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 19 if (IsCancelled()) { |
| 20 return; |
| 21 } |
| 22 |
| 23 SetStage(image_writer_api::STAGE_WRITE); |
| 24 |
| 25 base::FilePath storage_path = |
| 26 base::FilePath::FromUTF8Unsafe(storage_unit_id_); |
| 27 |
| 28 StartImageWriterClient(); |
| 29 |
| 30 int64 file_size; |
| 31 if (!base::GetFileSize(image_path_, &file_size)) { |
| 32 Error(error::kImageReadError); |
| 33 return; |
| 34 } |
| 35 |
| 36 BrowserThread::PostTask( |
| 37 BrowserThread::IO, |
| 38 FROM_HERE, |
| 39 base::Bind(&ImageWriterClient::Write, |
| 40 image_writer_client_, |
| 41 base::Bind(&Operation::WriteImageProgress, this, file_size), |
| 42 base::Bind(&Operation::VerifyWriteStart, this), |
| 43 base::Bind(&Operation::Error, this), |
| 44 image_path_, |
| 45 storage_path)); |
13 } | 46 } |
14 | 47 |
15 void Operation::VerifyWriteStart() { | 48 void Operation::VerifyWriteStart() { |
16 Error(error::kUnsupportedOperation); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 50 |
| 51 if (IsCancelled()) { |
| 52 return; |
| 53 } |
| 54 |
| 55 SetStage(image_writer_api::STAGE_VERIFYWRITE); |
| 56 |
| 57 base::FilePath storage_path = |
| 58 base::FilePath::FromUTF8Unsafe(storage_unit_id_); |
| 59 |
| 60 StartImageWriterClient(); |
| 61 |
| 62 int64 file_size; |
| 63 if (!base::GetFileSize(image_path_, &file_size)) { |
| 64 Error(error::kImageReadError); |
| 65 return; |
| 66 } |
| 67 |
| 68 BrowserThread::PostTask( |
| 69 BrowserThread::IO, |
| 70 FROM_HERE, |
| 71 base::Bind(&ImageWriterClient::Verify, |
| 72 image_writer_client_, |
| 73 base::Bind(&Operation::WriteImageProgress, this, file_size), |
| 74 base::Bind(&Operation::Finish, this), |
| 75 base::Bind(&Operation::Error, this), |
| 76 image_path_, |
| 77 storage_path)); |
17 } | 78 } |
18 | 79 |
19 } // namespace image_writer | 80 } // namespace image_writer |
20 } // namespace extensions | 81 } // namespace extensions |
OLD | NEW |