OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this image code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/chrome_utility_messages.h" |
| 6 #include "chrome/utility/image_writer/error_messages.h" |
| 7 #include "chrome/utility/image_writer/image_writer.h" |
| 8 #include "chrome/utility/image_writer/image_writer_handler.h" |
| 9 #include "content/public/utility/utility_thread.h" |
| 10 |
| 11 namespace chrome { |
| 12 namespace image_writer { |
| 13 |
| 14 ImageWriterHandler::ImageWriterHandler() |
| 15 : weak_factory_(this) { |
| 16 } |
| 17 |
| 18 ImageWriterHandler::~ImageWriterHandler() { |
| 19 } |
| 20 |
| 21 bool ImageWriterHandler::OnMessageReceived(const IPC::Message& message) { |
| 22 bool handled = true; |
| 23 IPC_BEGIN_MESSAGE_MAP(ImageWriterHandler, message) |
| 24 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Write, OnWriteStart) |
| 25 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Verify, OnVerifyStart) |
| 26 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Cancel, OnCancel) |
| 27 IPC_MESSAGE_UNHANDLED(handled = false) |
| 28 IPC_END_MESSAGE_MAP() |
| 29 return handled; |
| 30 } |
| 31 |
| 32 void ImageWriterHandler::SendProgress(int progress) { |
| 33 Send(new ChromeUtilityHostMsg_ImageWriter_Progress(progress)); |
| 34 } |
| 35 void ImageWriterHandler::SendFailed(const std::string& message) { |
| 36 Send(new ChromeUtilityHostMsg_ImageWriter_Failed(message)); |
| 37 image_writer_ = NULL; |
| 38 } |
| 39 void ImageWriterHandler::SendSucceeded() { |
| 40 Send(new ChromeUtilityHostMsg_ImageWriter_Succeeded()); |
| 41 image_writer_ = NULL; |
| 42 } |
| 43 |
| 44 void ImageWriterHandler::Send(IPC::Message* msg) { |
| 45 content::UtilityThread::Get()->Send(msg); |
| 46 } |
| 47 |
| 48 void ImageWriterHandler::OnWriteStart(const base::FilePath& image, |
| 49 const base::FilePath& device) { |
| 50 if (image_writer_ != NULL) { |
| 51 SendFailed(error::kOperationAlreadyInProgress); |
| 52 return; |
| 53 } |
| 54 image_writer_ = new ImageWriter(weak_factory_.GetWeakPtr()); |
| 55 image_writer_->Write(image, device); |
| 56 } |
| 57 |
| 58 void ImageWriterHandler::OnVerifyStart(const base::FilePath& image, |
| 59 const base::FilePath& device) { |
| 60 if (image_writer_ != NULL) { |
| 61 SendFailed(error::kOperationAlreadyInProgress); |
| 62 return; |
| 63 } |
| 64 image_writer_ = new ImageWriter(weak_factory_.GetWeakPtr()); |
| 65 image_writer_->Verify(image, device); |
| 66 } |
| 67 |
| 68 void ImageWriterHandler::OnCancel() { |
| 69 if (image_writer_ == NULL) { |
| 70 // TODO: Error message. |
| 71 return; |
| 72 } |
| 73 |
| 74 image_writer_->Cancel(); |
| 75 image_writer_ = NULL; |
| 76 } |
| 77 |
| 78 } // namespace image_writer |
| 79 } // namespace chrome |
OLD | NEW |