Chromium Code Reviews| 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/weak_ptr.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::SupportsWeakPtr<ImageWriter> { | |
| 22 public: | |
| 23 explicit ImageWriter(ImageWriterHandler* handler); | |
| 24 virtual ~ImageWriter(); | |
| 25 | |
| 26 // Starts a write from image_path to device_path. | |
|
Lei Zhang
2014/02/15 00:49:16
nit: foo_path -> |foo_path|, same below.
Drew Haven
2014/02/15 01:23:58
Done.
| |
| 27 void Write(const base::FilePath& image_path, | |
| 28 const base::FilePath& device_path); | |
| 29 // Starts verifying that image_path and device_path have the same size and | |
| 30 // contents. | |
| 31 void Verify(const base::FilePath& image_path, | |
| 32 const base::FilePath& device_path); | |
| 33 // Cancels any pending writes or verifications. | |
| 34 void Cancel(); | |
| 35 | |
| 36 // Returns whether an operation is in progress. | |
| 37 bool IsRunning(); | |
| 38 | |
| 39 private: | |
| 40 // Convenience wrappers. | |
| 41 void PostTask(const base::Closure& task); | |
| 42 void PostProgress(int64 progress); | |
| 43 void Error(const std::string& message); | |
| 44 | |
| 45 // Work loops. | |
| 46 void WriteChunk(); | |
| 47 void VerifyChunk(); | |
| 48 | |
| 49 // Cleans up file handles. | |
| 50 void 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 bytes_processed_; | |
| 58 | |
| 59 ImageWriterHandler* handler_; | |
| 60 }; | |
| 61 | |
| 62 } // namespace image_writer | |
| 63 } // namespace chrome | |
| 64 | |
| 65 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ | |
| OLD | NEW |