| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | 5 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
| 6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | 6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
| 7 | 7 |
| 8 #if defined(OS_WIN) | |
| 9 #include <windows.h> | |
| 10 #endif | |
| 11 | |
| 12 #include <string> | |
| 13 #include <vector> | 8 #include <vector> |
| 14 | 9 |
| 15 #include "base/bind.h" | 10 #include "base/bind.h" |
| 16 #include "base/callback.h" | 11 #include "base/callback.h" |
| 17 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 18 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 19 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 20 | 15 |
| 16 #if defined(OS_WIN) |
| 17 #include <windows.h> |
| 18 #endif |
| 19 |
| 21 namespace image_writer { | 20 namespace image_writer { |
| 22 | 21 |
| 23 class ImageWriterHandler; | 22 class ImageWriterHandler; |
| 23 #if defined(OS_MACOSX) |
| 24 class DiskUnmounterMac; |
| 25 #endif |
| 24 | 26 |
| 25 // Manages a write within the utility thread. This class holds all the state | 27 // 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 // around the writing and communicates with the ImageWriterHandler to dispatch |
| 27 // messages. | 29 // messages. |
| 28 class ImageWriter : public base::SupportsWeakPtr<ImageWriter> { | 30 class ImageWriter : public base::SupportsWeakPtr<ImageWriter> { |
| 29 public: | 31 public: |
| 30 explicit ImageWriter(ImageWriterHandler* handler, | 32 explicit ImageWriter(ImageWriterHandler* handler, |
| 31 const base::FilePath& image_path, | 33 const base::FilePath& image_path, |
| 32 const base::FilePath& device_path); | 34 const base::FilePath& device_path); |
| 33 virtual ~ImageWriter(); | 35 virtual ~ImageWriter(); |
| 34 | 36 |
| 35 // Starts a write from |image_path_| to |device_path_|. | 37 // Starts a write from |image_path_| to |device_path_|. |
| 36 void Write(); | 38 void Write(); |
| 37 // Starts verifying that |image_path_| and |device_path_| have the same size | 39 // Starts verifying that |image_path_| and |device_path_| have the same size |
| 38 // and contents. | 40 // and contents. |
| 39 void Verify(); | 41 void Verify(); |
| 40 // Cancels any pending writes or verifications. | 42 // Cancels any pending writes or verifications. |
| 41 void Cancel(); | 43 void Cancel(); |
| 42 | 44 |
| 43 // Returns whether an operation is in progress. | 45 // Returns whether an operation is in progress. |
| 44 bool IsRunning() const; | 46 bool IsRunning() const; |
| 45 // Checks if a path is a valid target device. | 47 // Checks if a path is a valid target device. |
| 46 // This method has OS-specific implementations. | 48 // This method has OS-specific implementations. |
| 47 bool IsValidDevice(); | 49 bool IsValidDevice(); |
| 48 // Unmounts all volumes on the target device. | 50 // Unmounts all volumes on the target device. |
| 49 // This method has OS-specific implementations. | 51 // This method has OS-specific implementations. |
| 50 bool UnmountVolumes(); | 52 void UnmountVolumes(const base::Closure& continuation); |
| 51 | 53 |
| 52 // Return the current image path. | 54 // Return the current image path. |
| 53 const base::FilePath& GetImagePath(); | 55 const base::FilePath& GetImagePath(); |
| 54 // Return the current device path. | 56 // Return the current device path. |
| 55 const base::FilePath& GetDevicePath(); | 57 const base::FilePath& GetDevicePath(); |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 // Convenience wrappers. | 60 // Convenience wrappers. |
| 59 void PostTask(const base::Closure& task); | 61 void PostTask(const base::Closure& task); |
| 60 void PostProgress(int64 progress); | 62 void PostProgress(int64 progress); |
| 61 void Error(const std::string& message); | 63 void Error(const std::string& message); |
| 62 | 64 |
| 63 // Initializes the files. | 65 // Initializes the files. |
| 64 bool InitializeFiles(); | 66 bool InitializeFiles(); |
| 67 bool OpenDevice(); |
| 65 | 68 |
| 66 // Work loops. | 69 // Work loops. |
| 67 void WriteChunk(); | 70 void WriteChunk(); |
| 68 void VerifyChunk(); | 71 void VerifyChunk(); |
| 69 | 72 |
| 70 base::FilePath image_path_; | 73 base::FilePath image_path_; |
| 71 base::FilePath device_path_; | 74 base::FilePath device_path_; |
| 72 | 75 |
| 73 base::File image_file_; | 76 base::File image_file_; |
| 74 base::File device_file_; | 77 base::File device_file_; |
| 75 int64 bytes_processed_; | 78 int64 bytes_processed_; |
| 76 bool running_; | 79 bool running_; |
| 77 | 80 |
| 78 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 79 std::vector<HANDLE> volume_handles_; | 82 std::vector<HANDLE> volume_handles_; |
| 80 #endif | 83 #endif |
| 81 | 84 |
| 85 #if defined(OS_MACOSX) |
| 86 friend class DiskUnmounterMac; |
| 87 scoped_ptr<DiskUnmounterMac> unmounter_; |
| 88 #endif |
| 89 |
| 82 ImageWriterHandler* handler_; | 90 ImageWriterHandler* handler_; |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace image_writer | 93 } // namespace image_writer |
| 86 | 94 |
| 87 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | 95 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
| OLD | NEW |