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_
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/files/file.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/weak_ptr.h"
20 namespace image_writer
{
22 class ImageWriterHandler
;
23 #if defined(OS_MACOSX)
24 class DiskUnmounterMac
;
27 // Manages a write within the utility thread. This class holds all the state
28 // around the writing and communicates with the ImageWriterHandler to dispatch
30 class ImageWriter
: public base::SupportsWeakPtr
<ImageWriter
> {
32 explicit ImageWriter(ImageWriterHandler
* handler
,
33 const base::FilePath
& image_path
,
34 const base::FilePath
& device_path
);
35 virtual ~ImageWriter();
37 // Starts a write from |image_path_| to |device_path_|.
39 // Starts verifying that |image_path_| and |device_path_| have the same size
42 // Cancels any pending writes or verifications.
45 // Returns whether an operation is in progress.
46 bool IsRunning() const;
47 // Checks if a path is a valid target device.
48 // This method has OS-specific implementations.
50 // Unmounts all volumes on the target device.
51 // This method has OS-specific implementations.
52 void UnmountVolumes(const base::Closure
& continuation
);
54 // Return the current image path.
55 const base::FilePath
& GetImagePath();
56 // Return the current device path.
57 const base::FilePath
& GetDevicePath();
60 // Convenience wrappers.
61 void PostTask(const base::Closure
& task
);
62 void PostProgress(int64 progress
);
63 void Error(const std::string
& message
);
65 // Initializes the files.
66 bool InitializeFiles();
73 base::FilePath image_path_
;
74 base::FilePath device_path_
;
76 base::File image_file_
;
77 base::File device_file_
;
78 int64 bytes_processed_
;
82 std::vector
<HANDLE
> volume_handles_
;
85 #if defined(OS_MACOSX)
86 friend class DiskUnmounterMac
;
87 scoped_ptr
<DiskUnmounterMac
> unmounter_
;
90 ImageWriterHandler
* handler_
;
93 } // namespace image_writer
95 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_