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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h

Issue 2663603002: Convert utility process ImageWriter IPC to mojo (Closed)
Patch Set: Use https: in bug references, minor comment fixes. Created 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_ CLIENT_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_ CLIENT_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_ CLIENT_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILITY_ CLIENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/threading/sequenced_worker_pool.h" 15 #include "chrome/common/extensions/removable_storage_writer.mojom.h"
15 #include "content/public/browser/utility_process_host.h" 16 #include "content/public/browser/utility_process_mojo_client.h"
16 #include "content/public/browser/utility_process_host_client.h"
17 17
18 // Writes a disk image to a device inside the utility process. 18 // Writes a disk image to a device inside the utility process.
19 class ImageWriterUtilityClient : public content::UtilityProcessHostClient { 19 class ImageWriterUtilityClient
20 : public base::RefCountedThreadSafe<ImageWriterUtilityClient> {
20 public: 21 public:
21 typedef base::Callback<void()> CancelCallback; 22 typedef base::Callback<void()> CancelCallback;
22 typedef base::Callback<void()> SuccessCallback; 23 typedef base::Callback<void()> SuccessCallback;
23 typedef base::Callback<void(int64_t)> ProgressCallback; 24 typedef base::Callback<void(int64_t)> ProgressCallback;
24 typedef base::Callback<void(const std::string&)> ErrorCallback; 25 typedef base::Callback<void(const std::string&)> ErrorCallback;
25 26
26 ImageWriterUtilityClient(); 27 ImageWriterUtilityClient();
27 28
28 // Starts the write. 29 // Starts the write operation.
29 // |progress_callback|: Called periodically with the count of bytes processed. 30 // |progress_callback|: Called periodically with the count of bytes processed.
30 // |success_callback|: Called at successful completion. 31 // |success_callback|: Called at successful completion.
31 // |error_callback|: Called with an error message on failure. 32 // |error_callback|: Called with an error message on failure.
32 // |source|: The path to the source file to read data from. 33 // |source|: The path to the source file to read data from.
33 // |target|: The path to the target device to write the image file to. 34 // |target|: The path to the target device to write the image file to.
34 virtual void Write(const ProgressCallback& progress_callback, 35 virtual void Write(const ProgressCallback& progress_callback,
35 const SuccessCallback& success_callback, 36 const SuccessCallback& success_callback,
36 const ErrorCallback& error_callback, 37 const ErrorCallback& error_callback,
37 const base::FilePath& source, 38 const base::FilePath& source,
38 const base::FilePath& target); 39 const base::FilePath& target);
39 40
40 // Starts a verification. 41 // Starts a verify operation.
41 // |progress_callback|: Called periodically with the count of bytes processed. 42 // |progress_callback|: Called periodically with the count of bytes processed.
42 // |success_callback|: Called at successful completion. 43 // |success_callback|: Called at successful completion.
43 // |error_callback|: Called with an error message on failure. 44 // |error_callback|: Called with an error message on failure.
44 // |source|: The path to the source file to read data from. 45 // |source|: The path to the source file to read data from.
45 // |target|: The path to the target device to write the image file to. 46 // |target|: The path to the target device file to verify.
46 virtual void Verify(const ProgressCallback& progress_callback, 47 virtual void Verify(const ProgressCallback& progress_callback,
47 const SuccessCallback& success_callback, 48 const SuccessCallback& success_callback,
48 const ErrorCallback& error_callback, 49 const ErrorCallback& error_callback,
49 const base::FilePath& source, 50 const base::FilePath& source,
50 const base::FilePath& target); 51 const base::FilePath& target);
51 52
52 // Cancels any pending write or verification. 53 // Cancels any pending write or verify operation.
53 // |cancel_callback|: Called when the cancel has actually occurred. 54 // |cancel_callback|: Called when the cancel has actually occurred.
54 virtual void Cancel(const CancelCallback& cancel_callback); 55 virtual void Cancel(const CancelCallback& cancel_callback);
55 56
56 // Shuts down the Utility thread that may have been created. 57 // Shuts down the utility process that may have been created.
57 virtual void Shutdown(); 58 virtual void Shutdown();
58 59
59 protected: 60 protected:
60 // It's a reference-counted object, so destructor is not public. 61 friend class base::RefCountedThreadSafe<ImageWriterUtilityClient>;
61 ~ImageWriterUtilityClient() override; 62
63 virtual ~ImageWriterUtilityClient();
62 64
63 private: 65 private:
64 // Ensures the UtilityProcessHost has been created. 66 class RemovableStorageWriterClientImpl;
65 void StartHost();
66 67
67 // UtilityProcessHostClient implementation. 68 // Ensures the utility process has been created.
68 void OnProcessCrashed(int exit_code) override; 69 void StartUtilityProcess();
69 void OnProcessLaunchFailed(int error_code) override;
70 bool OnMessageReceived(const IPC::Message& message) override;
71 virtual bool Send(IPC::Message* msg);
72 70
73 // IPC message handlers. 71 void UtilityProcessError();
74 void OnWriteImageSucceeded();
75 void OnWriteImageCancelled();
76 void OnWriteImageFailed(const std::string& message);
77 void OnWriteImageProgress(int64_t progress);
78 72
79 CancelCallback cancel_callback_; 73 void OperationProgress(int64_t progress);
74 void OperationSucceeded();
75 void OperationFailed(const std::string& error);
76
77 void ResetRequest();
78
80 ProgressCallback progress_callback_; 79 ProgressCallback progress_callback_;
81 SuccessCallback success_callback_; 80 SuccessCallback success_callback_;
82 ErrorCallback error_callback_; 81 ErrorCallback error_callback_;
83 82
84 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 83 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85 84
86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 85 std::unique_ptr<content::UtilityProcessMojoClient<
86 extensions::mojom::RemovableStorageWriter>>
87 utility_process_mojo_client_;
88
89 std::unique_ptr<RemovableStorageWriterClientImpl>
90 removable_storage_writer_client_;
87 91
88 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); 92 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient);
89 }; 93 };
90 94
91 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI TY_CLIENT_H_ 95 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI TY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698