OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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() : weak_factory_(this) {} | |
15 | |
16 ImageWriterHandler::~ImageWriterHandler() {} | |
17 | |
18 void ImageWriterHandler::SendSucceeded() { | |
19 Send(new ChromeUtilityHostMsg_ImageWriter_Succeeded()); | |
20 image_writer_ = NULL; | |
21 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
22 } | |
23 | |
24 void ImageWriterHandler::SendCancelled() { | |
25 Send(new ChromeUtilityHostMsg_ImageWriter_Cancelled()); | |
26 image_writer_ = NULL; | |
27 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
28 } | |
29 | |
30 void ImageWriterHandler::SendFailed(const std::string& message) { | |
31 Send(new ChromeUtilityHostMsg_ImageWriter_Failed(message)); | |
32 image_writer_ = NULL; | |
33 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
34 } | |
35 | |
36 void ImageWriterHandler::SendProgress(int64 progress) { | |
37 Send(new ChromeUtilityHostMsg_ImageWriter_Progress(progress)); | |
38 } | |
39 | |
40 void ImageWriterHandler::Send(IPC::Message* msg) { | |
41 content::UtilityThread::Get()->Send(msg); | |
42 } | |
43 | |
44 bool ImageWriterHandler::OnMessageReceived(const IPC::Message& message) { | |
45 bool handled = true; | |
46 IPC_BEGIN_MESSAGE_MAP(ImageWriterHandler, message) | |
47 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Write, OnWriteStart) | |
48 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Verify, OnVerifyStart) | |
49 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Cancel, OnCancel) | |
50 IPC_MESSAGE_UNHANDLED(handled = false) | |
51 IPC_END_MESSAGE_MAP() | |
52 return handled; | |
53 } | |
54 | |
55 void ImageWriterHandler::OnWriteStart(const base::FilePath& image, | |
56 const base::FilePath& device) { | |
57 if (image_writer_ != NULL) { | |
58 SendFailed(error::kOperationAlreadyInProgress); | |
Matt Perry
2014/02/14 00:16:23
This will cancel the in-progress operation. Would
Drew Haven
2014/02/14 02:32:56
Good catch. I completely missed that!
| |
59 return; | |
60 } | |
61 image_writer_ = new ImageWriter(weak_factory_.GetWeakPtr()); | |
62 image_writer_->Write(image, device); | |
63 } | |
64 | |
65 void ImageWriterHandler::OnVerifyStart(const base::FilePath& image, | |
66 const base::FilePath& device) { | |
67 if (image_writer_ != NULL) { | |
68 SendFailed(error::kOperationAlreadyInProgress); | |
69 return; | |
70 } | |
71 image_writer_ = new ImageWriter(weak_factory_.GetWeakPtr()); | |
72 image_writer_->Verify(image, device); | |
73 } | |
74 | |
75 void ImageWriterHandler::OnCancel() { | |
76 if (image_writer_) { | |
77 image_writer_->Cancel(); | |
78 } else { | |
79 SendCancelled(); | |
80 } | |
81 } | |
82 | |
83 } // namespace image_writer | |
84 } // namespace chrome | |
OLD | NEW |