Fix issue with browser action toolbar putting all extension icons in overflow once...
[chromium-blink-merge.git] / chrome / utility / image_writer / image_writer_handler.cc
blob2fe78c9d242f42cb589900c78b3c943e1b42df4d
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 "base/files/file_path.h"
6 #include "chrome/common/chrome_utility_messages.h"
7 #include "chrome/utility/image_writer/error_messages.h"
8 #include "chrome/utility/image_writer/image_writer_handler.h"
9 #include "content/public/utility/utility_thread.h"
11 namespace image_writer {
13 ImageWriterHandler::ImageWriterHandler() {}
14 ImageWriterHandler::~ImageWriterHandler() {}
16 void ImageWriterHandler::SendSucceeded() {
17 Send(new ChromeUtilityHostMsg_ImageWriter_Succeeded());
18 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
21 void ImageWriterHandler::SendCancelled() {
22 Send(new ChromeUtilityHostMsg_ImageWriter_Cancelled());
23 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
26 void ImageWriterHandler::SendFailed(const std::string& message) {
27 Send(new ChromeUtilityHostMsg_ImageWriter_Failed(message));
28 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
31 void ImageWriterHandler::SendProgress(int64 progress) {
32 Send(new ChromeUtilityHostMsg_ImageWriter_Progress(progress));
35 void ImageWriterHandler::Send(IPC::Message* msg) {
36 content::UtilityThread::Get()->Send(msg);
39 bool ImageWriterHandler::OnMessageReceived(const IPC::Message& message) {
40 bool handled = true;
41 IPC_BEGIN_MESSAGE_MAP(ImageWriterHandler, message)
42 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Write, OnWriteStart)
43 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Verify, OnVerifyStart)
44 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ImageWriter_Cancel, OnCancel)
45 IPC_MESSAGE_UNHANDLED(handled = false)
46 IPC_END_MESSAGE_MAP()
47 return handled;
50 void ImageWriterHandler::OnWriteStart(const base::FilePath& image,
51 const base::FilePath& device) {
52 if (!image_writer_.get() || image != image_writer_->GetImagePath() ||
53 device != image_writer_->GetDevicePath()) {
54 image_writer_.reset(new ImageWriter(this, image, device));
57 if (image_writer_->IsRunning()) {
58 SendFailed(error::kOperationAlreadyInProgress);
59 return;
62 if (!image_writer_->IsValidDevice()) {
63 SendFailed(error::kInvalidDevice);
64 return;
67 if (!image_writer_->UnmountVolumes()) {
68 SendFailed(error::kUnmountVolumes);
69 return;
72 image_writer_->Write();
75 void ImageWriterHandler::OnVerifyStart(const base::FilePath& image,
76 const base::FilePath& device) {
77 if (!image_writer_.get() || image != image_writer_->GetImagePath() ||
78 device != image_writer_->GetDevicePath()) {
79 image_writer_.reset(new ImageWriter(this, image, device));
82 if (image_writer_->IsRunning()) {
83 SendFailed(error::kOperationAlreadyInProgress);
84 return;
87 if (!image_writer_->IsValidDevice()) {
88 SendFailed(error::kInvalidDevice);
89 return;
92 image_writer_->Verify();
95 void ImageWriterHandler::OnCancel() {
96 if (image_writer_.get()) {
97 image_writer_->Cancel();
98 } else {
99 SendCancelled();
103 } // namespace image_writer