Index: chrome/utility/image_writer/image_writer.h |
diff --git a/chrome/utility/image_writer/image_writer.h b/chrome/utility/image_writer/image_writer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc8837556bfed0df81c1d88641f9b750637c377c |
--- /dev/null |
+++ b/chrome/utility/image_writer/image_writer.h |
@@ -0,0 +1,67 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this image code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
+#define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/ref_counted.h" |
+ |
+namespace chrome { |
+namespace image_writer { |
+ |
+class ImageWriterHandler; |
+ |
+// Manages a write within the utility thread. This class holds all the state |
+// around the writing and communicates with the ImageWriterHandler to dispatch |
+// messages. |
+class ImageWriter : public base::RefCountedThreadSafe<ImageWriter> { |
+ public: |
+ explicit ImageWriter(base::WeakPtr<ImageWriterHandler> handler); |
+ |
+ // Starts a write from image_path to device_path. |
+ void Write(const base::FilePath& image_path, |
+ const base::FilePath& device_path); |
+ // Starts verifying that image_path and device_path have the same size and |
+ // contents. |
+ void Verify(const base::FilePath& image_path, |
+ const base::FilePath& device_path); |
+ // Cancels any pending writes or verifications. |
+ void Cancel(); |
+ |
+ private: |
+ virtual ~ImageWriter(); |
+ friend class base::RefCountedThreadSafe<ImageWriter>; |
+ |
+ void PostTask(const base::Closure& task); |
+ void PostProgress(int64 progress); |
+ void Error(const std::string& message); |
+ |
+ void WriteChunk(); |
+ void WriteComplete(); |
+ |
+ void VerifyChunk(); |
+ void VerifyComplete(); |
+ |
+ bool SetUp(); |
+ bool CleanUp(); |
+ |
+ base::FilePath image_path_; |
+ base::FilePath device_path_; |
+ |
+ base::PlatformFile image_file_; |
+ base::PlatformFile device_file_; |
+ int64 total_bytes_; |
+ |
+ bool cancelled_; |
+ |
+ base::WeakPtr<ImageWriterHandler> handler_; |
+}; |
+ |
+} // namespace image_writer |
+} // namespace chrome |
+ |
+#endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_ |