Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / image_writer_private / operation_nonchromeos.cc
blob1aab868186a3e1b13f5bbc2d604d794aa835e6c5
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);
20 if (IsCancelled()) {
21 return;
24 SetStage(image_writer_api::STAGE_WRITE);
25 StartUtilityClient();
27 int64 file_size;
28 if (!base::GetFileSize(image_path_, &file_size)) {
29 Error(error::kImageReadError);
30 return;
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_));
46 void Operation::VerifyWrite(const base::Closure& continuation) {
47 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
49 if (IsCancelled()) {
50 return;
53 SetStage(image_writer_api::STAGE_VERIFYWRITE);
54 StartUtilityClient();
56 int64 file_size;
57 if (!base::GetFileSize(image_path_, &file_size)) {
58 Error(error::kImageReadError);
59 return;
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_));
75 } // namespace image_writer
76 } // namespace extensions