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
3 // found in the LICENSE file.
5 #include "base/files/file_util.h"
6 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
7 #include "chrome/browser/extensions/api/image_writer_private/write_from_file_operation.h"
8 #include "content/public/browser/browser_thread.h"
10 namespace extensions
{
11 namespace image_writer
{
13 using content::BrowserThread
;
15 WriteFromFileOperation::WriteFromFileOperation(
16 base::WeakPtr
<OperationManager
> manager
,
17 const ExtensionId
& extension_id
,
18 const base::FilePath
& user_file_path
,
19 const std::string
& device_path
)
20 : Operation(manager
, extension_id
, device_path
) {
21 image_path_
= user_file_path
;
24 WriteFromFileOperation::~WriteFromFileOperation() {}
26 void WriteFromFileOperation::StartImpl() {
27 if (!base::PathExists(image_path_
) || base::DirectoryExists(image_path_
)) {
28 DLOG(ERROR
) << "Source must exist and not be a directory.";
29 Error(error::kImageInvalid
);
33 BrowserThread::PostTask(
37 &WriteFromFileOperation::Unzip
,
40 &WriteFromFileOperation::Write
,
42 base::Bind(&WriteFromFileOperation::VerifyWrite
,
44 base::Bind(&WriteFromFileOperation::Finish
, this)))));
47 } // namespace image_writer
48 } // namespace extensions