Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 verification 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 to write the image file to. |
| 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 verification 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 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.
| |
| 74 void OnWriteImageSucceeded(); | 72 return utility_process_mojo_client_->service(); |
| 75 void OnWriteImageCancelled(); | 73 } |
| 76 void OnWriteImageFailed(const std::string& message); | |
| 77 void OnWriteImageProgress(int64_t progress); | |
| 78 | 74 |
| 79 CancelCallback cancel_callback_; | 75 void UtilityProcessError(); |
| 76 | |
| 77 void OperationProgress(int64_t progress); | |
| 78 void OperationSucceeded(); | |
| 79 void OperationFailed(const std::string& error); | |
| 80 | |
| 81 void ResetRequest(); | |
| 82 | |
| 80 ProgressCallback progress_callback_; | 83 ProgressCallback progress_callback_; |
| 81 SuccessCallback success_callback_; | 84 SuccessCallback success_callback_; |
| 82 ErrorCallback error_callback_; | 85 ErrorCallback error_callback_; |
| 83 | 86 |
| 84 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 87 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
|
Sam McNally
2017/02/02 21:54:17
const
Noel Gordon
2017/02/03 13:54:56
Done.
| |
| 85 | 88 |
| 86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 89 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
| |
| 90 | |
| 91 std::unique_ptr<content::UtilityProcessMojoClient<UtilityService>> | |
| 92 utility_process_mojo_client_; | |
| 93 | |
| 94 std::unique_ptr<RemovableStorageWriterClientImpl> | |
| 95 removable_storage_writer_client_; | |
| 87 | 96 |
| 88 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); | 97 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); |
| 89 }; | 98 }; |
| 90 | 99 |
| 91 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI TY_CLIENT_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI TY_CLIENT_H_ |
| OLD | NEW |