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.
5 #include "base/files/file_enumerator.h"
6 #include "base/files/file_util.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"
13 namespace extensions
{
14 namespace image_writer
{
16 using content::BrowserThread
;
18 void Operation::Write(const base::Closure
& continuation
) {
19 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
24 SetStage(image_writer_api::STAGE_WRITE
);
28 if (!base::GetFileSize(image_path_
, &file_size
)) {
29 Error(error::kImageReadError
);
33 BrowserThread::PostTask(
37 &ImageWriterUtilityClient::Write
,
39 base::Bind(&Operation::WriteImageProgress
, this, file_size
),
40 base::Bind(&Operation::CompleteAndContinue
, this, continuation
),
41 base::Bind(&Operation::Error
, this),
46 void Operation::VerifyWrite(const base::Closure
& continuation
) {
47 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
53 SetStage(image_writer_api::STAGE_VERIFYWRITE
);
57 if (!base::GetFileSize(image_path_
, &file_size
)) {
58 Error(error::kImageReadError
);
62 BrowserThread::PostTask(
66 &ImageWriterUtilityClient::Verify
,
68 base::Bind(&Operation::WriteImageProgress
, this, file_size
),
69 base::Bind(&Operation::CompleteAndContinue
, this, continuation
),
70 base::Bind(&Operation::Error
, this),
75 } // namespace image_writer
76 } // namespace extensions