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 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_
6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_
9 #include "base/callback.h"
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
14 namespace image_writer
{
16 class ImageWriterHandler
;
18 // Manages a write within the utility thread. This class holds all the state
19 // around the writing and communicates with the ImageWriterHandler to dispatch
21 class ImageWriter
: public base::SupportsWeakPtr
<ImageWriter
> {
23 explicit ImageWriter(ImageWriterHandler
* handler
);
24 virtual ~ImageWriter();
26 // Starts a write from |image_path| to |device_path|.
27 void Write(const base::FilePath
& image_path
,
28 const base::FilePath
& device_path
);
29 // Starts verifying that |image_path| and |device_path| have the same size and
31 void Verify(const base::FilePath
& image_path
,
32 const base::FilePath
& device_path
);
33 // Cancels any pending writes or verifications.
36 // Returns whether an operation is in progress.
37 bool IsRunning() const;
40 // Convenience wrappers.
41 void PostTask(const base::Closure
& task
);
42 void PostProgress(int64 progress
);
43 void Error(const std::string
& message
);
49 // Cleans up file handles.
52 base::FilePath image_path_
;
53 base::FilePath device_path_
;
55 base::File image_file_
;
56 base::File device_file_
;
57 int64 bytes_processed_
;
59 ImageWriterHandler
* handler_
;
62 } // namespace image_writer
64 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_