| 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_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ | 5 #ifndef CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ |
| 6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ | 6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "chrome/common/extensions/removable_storage_writer.mojom.h" |
| 13 #include "chrome/utility/image_writer/image_writer.h" | 14 #include "chrome/utility/image_writer/image_writer.h" |
| 14 #include "chrome/utility/utility_message_handler.h" | |
| 15 #include "ipc/ipc_message.h" | |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 class FilePath; | 17 class FilePath; |
| 19 } | 18 } |
| 20 | 19 |
| 21 namespace image_writer { | 20 namespace image_writer { |
| 22 | 21 |
| 23 // A handler for messages related to writing images. This class is added as a | 22 class ImageWriterHandler { |
| 24 // handler in ChromeContentUtilityClient. | |
| 25 class ImageWriterHandler : public UtilityMessageHandler { | |
| 26 public: | 23 public: |
| 27 ImageWriterHandler(); | 24 ImageWriterHandler(); |
| 28 ~ImageWriterHandler() override; | 25 ~ImageWriterHandler(); |
| 29 | 26 |
| 30 // Methods for sending the different messages back to the browser process. | 27 void Write(const base::FilePath& image, |
| 31 // Generally should be called by chrome::image_writer::ImageWriter. | 28 const base::FilePath& device, |
| 29 extensions::mojom::RemovableStorageWriterClientPtr client); |
| 30 void Verify(const base::FilePath& image, |
| 31 const base::FilePath& device, |
| 32 extensions::mojom::RemovableStorageWriterClientPtr client); |
| 33 |
| 34 // Methods for sending the different messages back to the |client_|. |
| 35 // Generally should be called by image_writer::ImageWriter. |
| 36 virtual void SendProgress(int64_t progress); |
| 32 virtual void SendSucceeded(); | 37 virtual void SendSucceeded(); |
| 33 virtual void SendCancelled(); | 38 virtual void SendFailed(const std::string& error); |
| 34 virtual void SendFailed(const std::string& message); | 39 virtual void SendCancelled() {} |
| 35 virtual void SendProgress(int64_t progress); | |
| 36 | 40 |
| 37 private: | 41 private: |
| 38 bool OnMessageReceived(const IPC::Message& message) override; | 42 void Cancel(); |
| 39 | 43 |
| 40 // Small wrapper for sending on the UtilityProcess. | 44 extensions::mojom::RemovableStorageWriterClientPtr client_; |
| 41 void Send(IPC::Message* msg); | |
| 42 | |
| 43 // Message handlers. | |
| 44 void OnWriteStart(const base::FilePath& image, const base::FilePath& device); | |
| 45 void OnVerifyStart(const base::FilePath& image, const base::FilePath& device); | |
| 46 void OnCancel(); | |
| 47 | |
| 48 std::unique_ptr<ImageWriter> image_writer_; | 45 std::unique_ptr<ImageWriter> image_writer_; |
| 49 }; | 46 }; |
| 50 | 47 |
| 51 } // namespace image_writer | 48 } // namespace image_writer |
| 52 | 49 |
| 53 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ | 50 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_HANDLER_H_ |
| OLD | NEW |