| 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/callback.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "chrome/common/extensions/removable_storage_writer.mojom.h" | 15 #include "chrome/common/extensions/removable_storage_writer.mojom.h" |
| 16 #include "content/public/browser/utility_process_mojo_client.h" | 16 #include "content/public/browser/utility_process_mojo_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. This |
| 19 // class lives on the FILE thread. |
| 19 class ImageWriterUtilityClient | 20 class ImageWriterUtilityClient |
| 20 : public base::RefCountedThreadSafe<ImageWriterUtilityClient> { | 21 : public base::RefCountedThreadSafe<ImageWriterUtilityClient> { |
| 21 public: | 22 public: |
| 22 typedef base::Callback<void()> CancelCallback; | 23 typedef base::Callback<void()> CancelCallback; |
| 23 typedef base::Callback<void()> SuccessCallback; | 24 typedef base::Callback<void()> SuccessCallback; |
| 24 typedef base::Callback<void(int64_t)> ProgressCallback; | 25 typedef base::Callback<void(int64_t)> ProgressCallback; |
| 25 typedef base::Callback<void(const std::string&)> ErrorCallback; | 26 typedef base::Callback<void(const std::string&)> ErrorCallback; |
| 26 | 27 |
| 27 ImageWriterUtilityClient(); | 28 ImageWriterUtilityClient(); |
| 28 | 29 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 // |source|: The path to the source file to read data from. | 46 // |source|: The path to the source file to read data from. |
| 46 // |target|: The path to the target device file to verify. | 47 // |target|: The path to the target device file to verify. |
| 47 virtual void Verify(const ProgressCallback& progress_callback, | 48 virtual void Verify(const ProgressCallback& progress_callback, |
| 48 const SuccessCallback& success_callback, | 49 const SuccessCallback& success_callback, |
| 49 const ErrorCallback& error_callback, | 50 const ErrorCallback& error_callback, |
| 50 const base::FilePath& source, | 51 const base::FilePath& source, |
| 51 const base::FilePath& target); | 52 const base::FilePath& target); |
| 52 | 53 |
| 53 // Cancels any pending write or verify operation. | 54 // Cancels any pending write or verify operation. |
| 54 // |cancel_callback|: Called when the cancel has actually occurred. | 55 // |cancel_callback|: Called when the cancel has actually occurred. |
| 56 // TODO(crbug.com/703514): Consider removing this API. |
| 55 virtual void Cancel(const CancelCallback& cancel_callback); | 57 virtual void Cancel(const CancelCallback& cancel_callback); |
| 56 | 58 |
| 57 // Shuts down the utility process that may have been created. | 59 // Shuts down the utility process that may have been created. |
| 58 virtual void Shutdown(); | 60 virtual void Shutdown(); |
| 59 | 61 |
| 60 protected: | 62 protected: |
| 61 friend class base::RefCountedThreadSafe<ImageWriterUtilityClient>; | 63 friend class base::RefCountedThreadSafe<ImageWriterUtilityClient>; |
| 62 | 64 |
| 63 virtual ~ImageWriterUtilityClient(); | 65 virtual ~ImageWriterUtilityClient(); |
| 64 | 66 |
| 65 private: | 67 private: |
| 66 class RemovableStorageWriterClientImpl; | 68 class RemovableStorageWriterClientImpl; |
| 67 | 69 |
| 68 void StartUtilityProcessIfNeeded(); | 70 void StartUtilityProcessIfNeeded(); |
| 69 void UtilityProcessError(); | 71 void UtilityProcessError(); |
| 70 | 72 |
| 71 void OperationProgress(int64_t progress); | 73 void OperationProgress(int64_t progress); |
| 72 void OperationSucceeded(); | 74 void OperationSucceeded(); |
| 73 void OperationFailed(const std::string& error); | 75 void OperationFailed(const std::string& error); |
| 74 | 76 |
| 75 void ResetRequest(); | 77 void ResetRequest(); |
| 76 | 78 |
| 77 ProgressCallback progress_callback_; | 79 ProgressCallback progress_callback_; |
| 78 SuccessCallback success_callback_; | 80 SuccessCallback success_callback_; |
| 79 ErrorCallback error_callback_; | 81 ErrorCallback error_callback_; |
| 80 | 82 |
| 81 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 82 | |
| 83 std::unique_ptr<content::UtilityProcessMojoClient< | 83 std::unique_ptr<content::UtilityProcessMojoClient< |
| 84 extensions::mojom::RemovableStorageWriter>> | 84 extensions::mojom::RemovableStorageWriter>> |
| 85 utility_process_mojo_client_; | 85 utility_process_mojo_client_; |
| 86 | 86 |
| 87 std::unique_ptr<RemovableStorageWriterClientImpl> | 87 std::unique_ptr<RemovableStorageWriterClientImpl> |
| 88 removable_storage_writer_client_; | 88 removable_storage_writer_client_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); | 90 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI
TY_CLIENT_H_ | 93 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI
TY_CLIENT_H_ |
| OLD | NEW |