Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / utility / image_writer / image_writer_handler.cc
blob3afb17711238230850950b74efcfc11f38bc0476
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.
5 #include "chrome/utility/image_writer/image_writer_handler.h"
7 #include "base/files/file_path.h"
8 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
9 #include "chrome/utility/image_writer/error_messages.h"
10 #include "content/public/utility/utility_thread.h"
12 namespace image_writer {
14 ImageWriterHandler::ImageWriterHandler() {}
15 ImageWriterHandler::~ImageWriterHandler() {}
17 void ImageWriterHandler::SendSucceeded() {
18 Send(new ChromeUtilityHostMsg_ImageWriter_Succeeded());
19 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
22 void ImageWriterHandler::SendCancelled() {
23 Send(new ChromeUtilityHostMsg_ImageWriter_Cancelled());
24 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
27 void ImageWriterHandler::SendFailed(const std::string& message) {
28 Send(new ChromeUtilityHostMsg_ImageWriter_Failed(message));
29 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
32 void ImageWriterHandler::SendProgress(int64 progress) {
33 Send(new ChromeUtilityHostMsg_ImageWriter_Progress(progress));
36 void ImageWriterHandler::Send(IPC::Message* msg) {
37 content::UtilityThread::Get()->Send(msg);
40 bool ImageWriterHandler::OnMessageReceived(const IPC::Message& message) {
41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(ImageWriterHandler, message)
43 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Write, OnWriteStart)
44 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Verify, OnVerifyStart)
45 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Cancel, OnCancel)
46 IPC_MESSAGE_UNHANDLED(handled = false)
47 IPC_END_MESSAGE_MAP()
48 return handled;
51 void ImageWriterHandler::OnWriteStart(const base::FilePath& image,
52 const base::FilePath& device) {
53 if (!image_writer_.get() || image != image_writer_->GetImagePath() ||
54 device != image_writer_->GetDevicePath()) {
55 image_writer_.reset(new ImageWriter(this, image, device));
58 if (image_writer_->IsRunning()) {
59 SendFailed(error::kOperationAlreadyInProgress);
60 return;
63 if (!image_writer_->IsValidDevice()) {
64 SendFailed(error::kInvalidDevice);
65 return;
68 image_writer_->UnmountVolumes(
69 base::Bind(&ImageWriter::Write, image_writer_->AsWeakPtr()));
72 void ImageWriterHandler::OnVerifyStart(const base::FilePath& image,
73 const base::FilePath& device) {
74 if (!image_writer_.get() || image != image_writer_->GetImagePath() ||
75 device != image_writer_->GetDevicePath()) {
76 image_writer_.reset(new ImageWriter(this, image, device));
79 if (image_writer_->IsRunning()) {
80 SendFailed(error::kOperationAlreadyInProgress);
81 return;
84 if (!image_writer_->IsValidDevice()) {
85 SendFailed(error::kInvalidDevice);
86 return;
89 image_writer_->Verify();
92 void ImageWriterHandler::OnCancel() {
93 if (image_writer_.get()) {
94 image_writer_->Cancel();
95 } else {
96 SendCancelled();
100 } // namespace image_writer