Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / utility / image_writer / image_writer.h
blob7c1225cac27641c3dc2e72640e14fdece299c372
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_
8 #include <vector>
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"
16 #if defined(OS_WIN)
17 #include <windows.h>
18 #endif
20 namespace image_writer {
22 class ImageWriterHandler;
23 #if defined(OS_MACOSX)
24 class DiskUnmounterMac;
25 #endif
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
29 // messages.
30 class ImageWriter : public base::SupportsWeakPtr<ImageWriter> {
31 public:
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_|.
38 void Write();
39 // Starts verifying that |image_path_| and |device_path_| have the same size
40 // and contents.
41 void Verify();
42 // Cancels any pending writes or verifications.
43 void Cancel();
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.
49 bool IsValidDevice();
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();
59 private:
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();
67 bool OpenDevice();
69 // Work loops.
70 void WriteChunk();
71 void VerifyChunk();
73 base::FilePath image_path_;
74 base::FilePath device_path_;
76 base::File image_file_;
77 base::File device_file_;
78 int64 bytes_processed_;
79 bool running_;
81 #if defined(OS_WIN)
82 std::vector<HANDLE> volume_handles_;
83 #endif
85 #if defined(OS_MACOSX)
86 friend class DiskUnmounterMac;
87 scoped_ptr<DiskUnmounterMac> unmounter_;
88 #endif
90 ImageWriterHandler* handler_;
93 } // namespace image_writer
95 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_