| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | |
| 6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 | |
| 13 namespace image_writer { | |
| 14 | |
| 15 class ImageWriterHandler; | |
| 16 | |
| 17 // Manages a write within the utility thread. This class holds all the state | |
| 18 // around the writing and communicates with the ImageWriterHandler to dispatch | |
| 19 // messages. | |
| 20 class ImageWriter : public base::SupportsWeakPtr<ImageWriter> { | |
| 21 public: | |
| 22 explicit ImageWriter(ImageWriterHandler* handler); | |
| 23 virtual ~ImageWriter(); | |
| 24 | |
| 25 // Starts a write from |image_path| to |device_path|. | |
| 26 void Write(const base::FilePath& image_path, | |
| 27 const base::FilePath& device_path); | |
| 28 // Starts verifying that |image_path| and |device_path| have the same size and | |
| 29 // contents. | |
| 30 void Verify(const base::FilePath& image_path, | |
| 31 const base::FilePath& device_path); | |
| 32 // Cancels any pending writes or verifications. | |
| 33 void Cancel(); | |
| 34 | |
| 35 // Returns whether an operation is in progress. | |
| 36 bool IsRunning() const; | |
| 37 | |
| 38 private: | |
| 39 // Convenience wrappers. | |
| 40 void PostTask(const base::Closure& task); | |
| 41 void PostProgress(int64 progress); | |
| 42 void Error(const std::string& message); | |
| 43 | |
| 44 // Work loops. | |
| 45 void WriteChunk(); | |
| 46 void VerifyChunk(); | |
| 47 | |
| 48 // Cleans up file handles. | |
| 49 void CleanUp(); | |
| 50 | |
| 51 base::FilePath image_path_; | |
| 52 base::FilePath device_path_; | |
| 53 | |
| 54 base::PlatformFile image_file_; | |
| 55 base::PlatformFile device_file_; | |
| 56 int64 bytes_processed_; | |
| 57 | |
| 58 ImageWriterHandler* handler_; | |
| 59 }; | |
| 60 | |
| 61 } // namespace image_writer | |
| 62 | |
| 63 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | |
| OLD | NEW |