OLD | NEW |
(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_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 |
| 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 ImageWriterUtilityClient : 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 ImageWriterUtilityClient(); |
| 23 |
| 24 // Starts the write. |
| 25 // |progress_callback|: Called periodically with the count of bytes processed. |
| 26 // |success_callback|: Called at successful completion. |
| 27 // |error_callback|: Called with an error message on failure. |
| 28 // |source|: The path to the source file to read data from. |
| 29 // |target|: The path to the target device to write the image file to. |
| 30 void Write(const ProgressCallback& progress_callback, |
| 31 const SuccessCallback& success_callback, |
| 32 const ErrorCallback& error_callback, |
| 33 const base::FilePath& source, |
| 34 const base::FilePath& target); |
| 35 |
| 36 // Starts a verification. |
| 37 // |progress_callback|: Called periodically with the count of bytes processed. |
| 38 // |success_callback|: Called at successful completion. |
| 39 // |error_callback|: Called with an error message on failure. |
| 40 // |source|: The path to the source file to read data from. |
| 41 // |target|: The path to the target device to write the image file to. |
| 42 void Verify(const ProgressCallback& progress_callback, |
| 43 const SuccessCallback& success_callback, |
| 44 const ErrorCallback& error_callback, |
| 45 const base::FilePath& source, |
| 46 const base::FilePath& target); |
| 47 |
| 48 // Cancels any pending write or verification. |
| 49 // |cancel_callback|: Called when the cancel has actually occurred. |
| 50 void Cancel(const CancelCallback& cancel_callback); |
| 51 |
| 52 // Shuts down the Utility thread that may have been created. |
| 53 void Shutdown(); |
| 54 |
| 55 private: |
| 56 // Ensures the UtilityProcessHost has been created. |
| 57 void StartHost(); |
| 58 |
| 59 // UtilityProcessHostClient implementation. |
| 60 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 61 virtual void OnProcessLaunchFailed() OVERRIDE; |
| 62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 63 virtual bool Send(IPC::Message* msg); |
| 64 |
| 65 // It's a reference-counted object, so destructor is private. |
| 66 virtual ~ImageWriterUtilityClient(); |
| 67 |
| 68 // IPC message handlers. |
| 69 void OnWriteImageSucceeded(); |
| 70 void OnWriteImageCancelled(); |
| 71 void OnWriteImageFailed(const std::string& message); |
| 72 void OnWriteImageProgress(int64 progress); |
| 73 |
| 74 CancelCallback cancel_callback_; |
| 75 ProgressCallback progress_callback_; |
| 76 SuccessCallback success_callback_; |
| 77 ErrorCallback error_callback_; |
| 78 |
| 79 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 80 |
| 81 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(ImageWriterUtilityClient); |
| 84 }; |
| 85 |
| 86 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_IMAGE_WRITER_UTILI
TY_CLIENT_H_ |
OLD | NEW |