Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_UTILITY_IMAGE_WRITER_DISK_UNMOUNTER_MAC_H_ | |
| 6 #define CHROME_UTILITY_IMAGE_WRITER_DISK_UNMOUNTER_MAC_H_ | |
| 7 | |
| 8 #include <CoreFoundation/CoreFoundation.h> | |
| 9 #include <DiskArbitration/DiskArbitration.h> | |
| 10 | |
| 11 #include "base/bind.h" | |
| 12 #include "base/callback.h" | |
| 13 #include "base/mac/foundation_util.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/threading/thread.h" | |
| 16 | |
| 17 namespace image_writer { | |
| 18 | |
| 19 class ImageWriter; | |
| 20 | |
| 21 // Manages the unmounting of disks through Disk Arbitration. Disk Arbitration | |
| 22 // has to be run on a thread with a CFRunLoop. In the utility process neither | |
| 23 // the main or IO thread have one by default, so we need to manage a new thread | |
| 24 // which will explicitly have a CFRunLoop-based message pump. Note that this | |
| 25 // class can only handle one unmount operation at a time and calling Unmount | |
|
Robert Sesek
2014/06/06 18:34:06
That's not quite accurate. You can only ever call
Drew Haven
2014/06/10 01:13:25
I agree. I followed up on that. Creation of the
| |
| 26 // again before the continuation returns will cause undefined behavior. | |
| 27 class DiskUnmounterMac { | |
| 28 public: | |
| 29 DiskUnmounterMac(base::WeakPtr<ImageWriter> image_writer); | |
| 30 virtual ~DiskUnmounterMac(); | |
| 31 | |
| 32 // Claims and unmounts the device described by |device_path| and then calls | |
| 33 // the |continuation| when complete. This can be called from any thread. | |
| 34 // The continuation will be run on the thread this object was created on. | |
| 35 void Unmount(const std::string& device_path, | |
| 36 const base::Closure& continuation); | |
| 37 | |
| 38 private: | |
| 39 // Handles disk-claimed callbacks. | |
| 40 static void DiskClaimed(DADiskRef disk, | |
| 41 DADissenterRef dissenter, | |
| 42 void* context); | |
| 43 // Handles when we fail to claim a disk. | |
| 44 static DADissenterRef DiskClaimRevoked(DADiskRef disk, void* context); | |
| 45 // Handles the disk-unmounted callback. | |
| 46 static void DiskUnmounted(DADiskRef disk, | |
| 47 DADissenterRef dissenter, | |
| 48 void* context); | |
| 49 | |
| 50 // A |MessagePumpFactory| for creating the thread. | |
| 51 static scoped_ptr<base::MessagePump> CreateMessagePump(); | |
| 52 | |
| 53 // Starts the unmount process. Should be posted to the |cf_thread_|. | |
| 54 void UnmountOnWorker(const std::string& device_path); | |
| 55 | |
| 56 // A convenience method for sending an error back to the |image_writer_|. | |
| 57 void Error(const std::string& message); | |
| 58 | |
| 59 base::WeakPtr<ImageWriter> image_writer_; | |
| 60 base::Closure unmount_continuation_closure_; | |
| 61 scoped_refptr<base::MessageLoopProxy> original_thread_; | |
| 62 | |
| 63 base::ScopedCFTypeRef<DADiskRef> disk_; | |
| 64 base::ScopedCFTypeRef<DASessionRef> session_; | |
| 65 | |
| 66 // Thread is last to ensure it is stopped before the data members are | |
| 67 // destroyed. | |
| 68 base::Thread cf_thread_; | |
| 69 }; | |
| 70 | |
| 71 } // namespace image_writer | |
| 72 | |
| 73 #endif // CHROME_UTILITY_IMAGE_WRITER_DISK_UNMOUNTER_MAC_H_ | |
| OLD | NEW |