OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/file_util.h" | |
6 #include "base/files/file_enumerator.h" | |
7 #include "base/threading/worker_pool.h" | |
8 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | |
9 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | |
10 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 namespace extensions { | |
14 namespace image_writer { | |
15 | |
16 using content::BrowserThread; | |
17 | |
18 void Operation::Write(const base::Closure& continuation) { | |
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
20 if (IsCancelled()) { | |
21 return; | |
22 } | |
23 | |
24 SetStage(image_writer_api::STAGE_WRITE); | |
25 StartUtilityClient(); | |
26 | |
27 int64 file_size; | |
28 if (!base::GetFileSize(image_path_, &file_size)) { | |
29 Error(error::kImageReadError); | |
30 return; | |
31 } | |
32 | |
33 BrowserThread::PostTask( | |
34 BrowserThread::IO, | |
35 FROM_HERE, | |
36 base::Bind( | |
37 &ImageWriterUtilityClient::Write, | |
38 image_writer_client_, | |
39 base::Bind(&Operation::WriteImageProgress, this, file_size), | |
40 base::Bind(&Operation::CompleteAndContinue, this, continuation), | |
41 base::Bind(&Operation::Error, this), | |
42 image_path_, | |
43 device_path_)); | |
44 } | |
45 | |
46 void Operation::VerifyWrite(const base::Closure& continuation) { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
48 | |
49 if (IsCancelled()) { | |
50 return; | |
51 } | |
52 | |
53 SetStage(image_writer_api::STAGE_VERIFYWRITE); | |
54 StartUtilityClient(); | |
55 | |
56 int64 file_size; | |
57 if (!base::GetFileSize(image_path_, &file_size)) { | |
58 Error(error::kImageReadError); | |
59 return; | |
60 } | |
61 | |
62 BrowserThread::PostTask( | |
63 BrowserThread::IO, | |
64 FROM_HERE, | |
65 base::Bind( | |
66 &ImageWriterUtilityClient::Verify, | |
67 image_writer_client_, | |
68 base::Bind(&Operation::WriteImageProgress, this, file_size), | |
69 base::Bind(&Operation::CompleteAndContinue, this, continuation), | |
70 base::Bind(&Operation::Error, this), | |
71 image_path_, | |
72 device_path_)); | |
73 } | |
74 | |
75 } // namespace image_writer | |
76 } // namespace extensions | |
OLD | NEW |