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

Unified 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: Remove test DLOG, minor name changes. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h
diff --git a/chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h b/chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h
index 62a9a28c4ded5908f7908b62f4a5ffcdd5cc3c65..a51da7ca894085c43fb88e4f34f939201f6a242e 100644
--- a/chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h
+++ b/chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h
@@ -7,16 +7,17 @@
#include <stdint.h>
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
+#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
-#include "base/threading/sequenced_worker_pool.h"
-#include "content/public/browser/utility_process_host.h"
-#include "content/public/browser/utility_process_host_client.h"
+#include "chrome/common/extensions/removable_storage_writer.mojom.h"
+#include "content/public/browser/utility_process_mojo_client.h"
// Writes a disk image to a device inside the utility process.
-class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
+class ImageWriterUtilityClient
+ : public base::RefCountedThreadSafe<ImageWriterUtilityClient> {
public:
typedef base::Callback<void()> CancelCallback;
typedef base::Callback<void()> SuccessCallback;
@@ -25,7 +26,7 @@ class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
ImageWriterUtilityClient();
- // Starts the write.
+ // Starts the write operation.
// |progress_callback|: Called periodically with the count of bytes processed.
// |success_callback|: Called at successful completion.
// |error_callback|: Called with an error message on failure.
@@ -37,7 +38,7 @@ class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
const base::FilePath& source,
const base::FilePath& target);
- // Starts a verification.
+ // Starts a verification operation.
// |progress_callback|: Called periodically with the count of bytes processed.
// |success_callback|: Called at successful completion.
// |error_callback|: Called with an error message on failure.
@@ -49,42 +50,50 @@ class ImageWriterUtilityClient : public content::UtilityProcessHostClient {
const base::FilePath& source,
const base::FilePath& target);
- // Cancels any pending write or verification.
+ // Cancels any pending write or verification operation.
// |cancel_callback|: Called when the cancel has actually occurred.
virtual void Cancel(const CancelCallback& cancel_callback);
- // Shuts down the Utility thread that may have been created.
+ // Shuts down the utility process that may have been created.
virtual void Shutdown();
protected:
- // It's a reference-counted object, so destructor is not public.
- ~ImageWriterUtilityClient() override;
+ friend class base::RefCountedThreadSafe<ImageWriterUtilityClient>;
+
+ virtual ~ImageWriterUtilityClient();
private:
- // Ensures the UtilityProcessHost has been created.
- void StartHost();
-
- // UtilityProcessHostClient implementation.
- void OnProcessCrashed(int exit_code) override;
- void OnProcessLaunchFailed(int error_code) override;
- bool OnMessageReceived(const IPC::Message& message) override;
- virtual bool Send(IPC::Message* msg);
-
- // IPC message handlers.
- void OnWriteImageSucceeded();
- void OnWriteImageCancelled();
- void OnWriteImageFailed(const std::string& message);
- void OnWriteImageProgress(int64_t progress);
-
- CancelCallback cancel_callback_;
+ class RemovableStorageWriterClientImpl;
+
+ // Ensures the utility process has been created.
+ void StartUtilityProcess();
+
+ extensions::mojom::RemovableStorageWriter* UtilityProcessService() {
Sam McNally 2017/02/02 21:54:17 UtilityService* utility_process_service() {
Noel Gordon 2017/02/03 13:54:56 Removed this instead.
+ return utility_process_mojo_client_->service();
+ }
+
+ void UtilityProcessError();
+
+ void OperationProgress(int64_t progress);
+ void OperationSucceeded();
+ void OperationFailed(const std::string& error);
+
+ void ResetRequest();
+
ProgressCallback progress_callback_;
SuccessCallback success_callback_;
ErrorCallback error_callback_;
- base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
-
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
Sam McNally 2017/02/02 21:54:17 const
Noel Gordon 2017/02/03 13:54:56 Done.
+ typedef extensions::mojom::RemovableStorageWriter UtilityService;
Sam McNally 2017/02/02 21:54:17 Typedefs before methods. using UtilityService = e
Noel Gordon 2017/02/03 13:54:56 The effect I was attempting to achieve with the ty
+
+ std::unique_ptr<content::UtilityProcessMojoClient<UtilityService>>
+ utility_process_mojo_client_;
+
+ std::unique_ptr<RemovableStorageWriterClientImpl>
+ removable_storage_writer_client_;
+
DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient);
};

Powered by Google App Engine
This is Rietveld 408576698