OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this image 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/ref_counted.h" |
| 12 |
| 13 namespace chrome { |
| 14 namespace image_writer { |
| 15 |
| 16 class ImageWriterHandler; |
| 17 |
| 18 // Manages a write within the utility thread. This class holds all the state |
| 19 // around the writing and communicates with the ImageWriterHandler to dispatch |
| 20 // messages. |
| 21 class ImageWriter : public base::RefCountedThreadSafe<ImageWriter> { |
| 22 public: |
| 23 explicit ImageWriter(base::WeakPtr<ImageWriterHandler> handler); |
| 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 private: |
| 36 virtual ~ImageWriter(); |
| 37 friend class base::RefCountedThreadSafe<ImageWriter>; |
| 38 |
| 39 void PostTask(const base::Closure& task); |
| 40 void PostProgress(int64 progress); |
| 41 void Error(const std::string& message); |
| 42 |
| 43 void WriteChunk(); |
| 44 void WriteComplete(); |
| 45 |
| 46 void VerifyChunk(); |
| 47 void VerifyComplete(); |
| 48 |
| 49 bool SetUp(); |
| 50 bool CleanUp(); |
| 51 |
| 52 base::FilePath image_path_; |
| 53 base::FilePath device_path_; |
| 54 |
| 55 base::PlatformFile image_file_; |
| 56 base::PlatformFile device_file_; |
| 57 int64 total_bytes_; |
| 58 |
| 59 bool cancelled_; |
| 60 |
| 61 base::WeakPtr<ImageWriterHandler> handler_; |
| 62 }; |
| 63 |
| 64 } // namespace image_writer |
| 65 } // namespace chrome |
| 66 |
| 67 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
OLD | NEW |