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_
15 #include "base/bind.h"
16 #include "base/callback.h"
17 #include "base/files/file.h"
18 #include "base/files/file_path.h"
19 #include "base/memory/weak_ptr.h"
21 namespace image_writer {
23 class ImageWriterHandler;
25 // Manages a write within the utility thread. This class holds all the state
26 // around the writing and communicates with the ImageWriterHandler to dispatch
28 class ImageWriter : public base::SupportsWeakPtr<ImageWriter> {
30 explicit ImageWriter(ImageWriterHandler* handler,
31 const base::FilePath& image_path,
32 const base::FilePath& device_path);
33 virtual ~ImageWriter();
35 // Starts a write from |image_path_| to |device_path_|.
37 // Starts verifying that |image_path_| and |device_path_| have the same size
40 // Cancels any pending writes or verifications.
43 // Returns whether an operation is in progress.
44 bool IsRunning() const;
45 // Checks if a path is a valid target device.
46 // This method has OS-specific implementations.
48 // Unmounts all volumes on the target device.
49 // This method has OS-specific implementations.
50 bool UnmountVolumes();
52 // Return the current image path.
53 const base::FilePath& GetImagePath();
54 // Return the current device path.
55 const base::FilePath& GetDevicePath();
58 // Convenience wrappers.
59 void PostTask(const base::Closure& task);
60 void PostProgress(int64 progress);
61 void Error(const std::string& message);
63 // Initializes the files.
64 bool InitializeFiles();
70 base::FilePath image_path_;
71 base::FilePath device_path_;
73 base::File image_file_;
74 base::File device_file_;
75 int64 bytes_processed_;
79 std::vector<HANDLE> volume_handles_;
82 ImageWriterHandler* handler_;
85 } // namespace image_writer
87 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_