Don't leave aborted URLs in the omnibox unless we're on the NTP.
[chromium-blink-merge.git] / chrome / utility / image_writer / image_writer.h
blob70633e7c49113cb8a19dbe0f0ce60f3d8ce55ac2
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.
5 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_
6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_
8 #include "base/bind.h"
9 #include "base/callback.h"
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
14 namespace image_writer {
16 class ImageWriterHandler;
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();
26 // Starts a write from |image_path| to |device_path|.
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();
36 // Returns whether an operation is in progress.
37 bool IsRunning() const;
39 private:
40 // Convenience wrappers.
41 void PostTask(const base::Closure& task);
42 void PostProgress(int64 progress);
43 void Error(const std::string& message);
45 // Work loops.
46 void WriteChunk();
47 void VerifyChunk();
49 // Cleans up file handles.
50 void CleanUp();
52 base::FilePath image_path_;
53 base::FilePath device_path_;
55 base::File image_file_;
56 base::File device_file_;
57 int64 bytes_processed_;
59 ImageWriterHandler* handler_;
62 } // namespace image_writer
64 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_H_