| 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 #include "chrome/utility/image_writer/disk_unmounter_mac.h" | 5 #include "chrome/utility/image_writer/disk_unmounter_mac.h" |
| 6 | 6 |
| 7 #include <IOKit/storage/IOStorageProtocolCharacteristics.h> |
| 7 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 8 #include <IOKit/storage/IOStorageProtocolCharacteristics.h> | |
| 9 | 9 |
| 10 #include "base/message_loop/message_pump_mac.h" | 10 #include "base/message_loop/message_pump_mac.h" |
| 11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/utility/image_writer/error_messages.h" | 14 #include "chrome/utility/image_writer/error_messages.h" |
| 14 #include "chrome/utility/image_writer/image_writer.h" | 15 #include "chrome/utility/image_writer/image_writer.h" |
| 15 | 16 |
| 16 namespace image_writer { | 17 namespace image_writer { |
| 17 | 18 |
| 18 DiskUnmounterMac::DiskUnmounterMac() : cf_thread_("ImageWriterDiskArb") { | 19 DiskUnmounterMac::DiskUnmounterMac() : cf_thread_("ImageWriterDiskArb") { |
| 19 base::Thread::Options options; | 20 base::Thread::Options options; |
| 20 options.message_pump_factory = base::Bind(&CreateMessagePump); | 21 options.message_pump_factory = base::Bind(&CreateMessagePump); |
| 21 | 22 |
| 22 cf_thread_.StartWithOptions(options); | 23 cf_thread_.StartWithOptions(options); |
| 23 } | 24 } |
| 24 | 25 |
| 25 DiskUnmounterMac::~DiskUnmounterMac() { | 26 DiskUnmounterMac::~DiskUnmounterMac() { |
| 26 if (disk_) | 27 if (disk_) |
| 27 DADiskUnclaim(disk_); | 28 DADiskUnclaim(disk_); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void DiskUnmounterMac::Unmount(const std::string& device_path, | 31 void DiskUnmounterMac::Unmount(const std::string& device_path, |
| 31 const base::Closure& success_continuation, | 32 const base::Closure& success_continuation, |
| 32 const base::Closure& failure_continuation) { | 33 const base::Closure& failure_continuation) { |
| 33 // Should only be used once. | 34 // Should only be used once. |
| 34 DCHECK(!original_thread_.get()); | 35 DCHECK(!original_thread_.get()); |
| 35 original_thread_ = base::ThreadTaskRunnerHandle::Get(); | 36 original_thread_ = base::ThreadTaskRunnerHandle::Get(); |
| 36 success_continuation_ = success_continuation; | 37 success_continuation_ = success_continuation; |
| 37 failure_continuation_ = failure_continuation; | 38 failure_continuation_ = failure_continuation; |
| 38 | 39 |
| 39 cf_thread_.message_loop()->PostTask( | 40 cf_thread_.task_runner()->PostTask( |
| 40 FROM_HERE, | 41 FROM_HERE, base::Bind(&DiskUnmounterMac::UnmountOnWorker, |
| 41 base::Bind(&DiskUnmounterMac::UnmountOnWorker, | 42 base::Unretained(this), device_path)); |
| 42 base::Unretained(this), | |
| 43 device_path)); | |
| 44 } | 43 } |
| 45 | 44 |
| 46 // static | 45 // static |
| 47 void DiskUnmounterMac::DiskClaimed(DADiskRef disk, | 46 void DiskUnmounterMac::DiskClaimed(DADiskRef disk, |
| 48 DADissenterRef dissenter, | 47 DADissenterRef dissenter, |
| 49 void* context) { | 48 void* context) { |
| 50 DiskUnmounterMac* disk_unmounter = static_cast<DiskUnmounterMac*>(context); | 49 DiskUnmounterMac* disk_unmounter = static_cast<DiskUnmounterMac*>(context); |
| 51 | 50 |
| 52 if (dissenter) { | 51 if (dissenter) { |
| 53 LOG(ERROR) << "Unable to claim disk."; | 52 LOG(ERROR) << "Unable to claim disk."; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 this, | 115 this, |
| 117 DiskClaimed, | 116 DiskClaimed, |
| 118 this); | 117 this); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void DiskUnmounterMac::Error() { | 120 void DiskUnmounterMac::Error() { |
| 122 original_thread_->PostTask(FROM_HERE, failure_continuation_); | 121 original_thread_->PostTask(FROM_HERE, failure_continuation_); |
| 123 } | 122 } |
| 124 | 123 |
| 125 } // namespace image_writer | 124 } // namespace image_writer |
| OLD | NEW |