Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/image_writer_client.h

Issue 61643015: Adds imageWriterPrivate support for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and now working on Windows with minimal changes. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_BROWSER_IMAGE_WRITER_CLIENT_H_
6 #define CHROME_BROWSER_IMAGE_WRITER_CLIENT_H_
7
8 #include "base/files/file_path.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "content/public/browser/utility_process_host.h"
12 #include "content/public/browser/utility_process_host_client.h"
13
14 // Writes a disk image to a device inside the utility process.
15 class ImageWriterClient : public content::UtilityProcessHostClient {
16 public:
17 typedef base::Callback<void()> CancelCallback;
18 typedef base::Callback<void()> SuccessCallback;
19 typedef base::Callback<void(int64)> ProgressCallback;
20 typedef base::Callback<void(const std::string&)> ErrorCallback;
21
22 ImageWriterClient();
23
24 // Sets the instance to be returned by |Create| methods when testing. This
25 // should be cleared when the test is complete to avoid poluting future tests.
26 static void SetInstanceForTesting(
27 scoped_refptr<ImageWriterClient> testing_instance);
28
29 // Starts the write.
30 // |progress_callback|: Called periodically with the count of bytes processed.
31 // |success_callback|: Called at successful completion.
32 // |error_callback|: Called with an error message on failure.
33 // |source|: The path to the source file to read data from.
34 // |target|: The path to the target device to write the image file to.
35 void Write(const ProgressCallback& progress_callback,
36 const SuccessCallback& success_callback,
37 const ErrorCallback& error_callback,
38 const base::FilePath& source,
39 const base::FilePath& target);
40
41 // Starts a verification.
42 // |progress_callback|: Called periodically with the count of bytes processed.
43 // |success_callback|: Called at successful completion.
44 // |error_callback|: Called with an error message on failure.
45 // |source|: The path to the source file to read data from.
46 // |target|: The path to the target device to write the image file to.
47 void Verify(const ProgressCallback& progress_callback,
48 const SuccessCallback& success_callback,
49 const ErrorCallback& error_callback,
50 const base::FilePath& source,
51 const base::FilePath& target);
52
53 // Cancels any pending write or verification.
54 // |cancel_callback|: Called when the cancel has actually occurred.
55 void Cancel(const CancelCallback& cancel_callback);
56
57 // Shuts down the Utility thread that may have been created.
58 void Shutdown();
59
60 // Sets the ImageWriterClient to use during testing.
61 static void InstallForTesting(scoped_refptr<ImageWriterClient> client);
62
63 private:
64 // Ensures the UtilityProcessHost has been created.
65 void StartHost();
66
67 // UtilityProcessHostClient implementation.
68 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
69 virtual void OnProcessLaunchFailed() OVERRIDE;
70 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
71 virtual bool Send(IPC::Message* msg);
72
73 // It's a reference-counted object, so destructor is private.
74 virtual ~ImageWriterClient();
75
76 // IPC message handlers.
77 void OnWriteImageSucceeded();
78 void OnWriteImageCancelled();
79 void OnWriteImageFailed(const std::string& message);
80 void OnWriteImageProgress(int64 progress);
81
82 CancelCallback cancel_callback_;
83 ProgressCallback progress_callback_;
84 SuccessCallback success_callback_;
85 ErrorCallback error_callback_;
86
87 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
88
89 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
90
91 DISALLOW_COPY_AND_ASSIGN(ImageWriterClient);
92 };
93
94 #endif // CHROME_BROWSER_IMAGE_WRITER_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698