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_IMAGE_WRITER_MAC_H_ | |
6 #define CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_MAC_H_ | |
7 | |
8 #include <vector> | |
Robert Sesek
2014/06/05 19:49:48
nit: C++ system headers come after C system header
Drew Haven
2014/06/05 22:28:28
vector is not actually needed here. Removed.
| |
9 #include <CoreFoundation/CoreFoundation.h> | |
10 #include <DiskArbitration/DiskArbitration.h> | |
11 | |
12 #include "base/bind.h" | |
13 #include "base/callback.h" | |
14 #include "base/files/file.h" | |
15 #include "base/files/file_path.h" | |
16 #include "base/mac/foundation_util.h" | |
17 #include "base/memory/weak_ptr.h" | |
18 #include "base/threading/thread.h" | |
19 | |
20 namespace image_writer { | |
21 | |
22 class ImageWriter; | |
23 | |
24 // Manages the unmounting of disks through Disk Arbitration. Disk Arbitration | |
25 // has to be run on a thread with a CFRunLoop. In the utility process neither | |
26 // the main or IO thread have one by default, so we need to manage a new thread | |
27 // which will explicitly have a CFRunLoop-based message pump. | |
28 class DiskUnmounter : public base::SupportsWeakPtr<DiskUnmounter> { | |
Robert Sesek
2014/06/05 19:49:48
The general preference is to use WeakPtrFactory ra
Drew Haven
2014/06/05 22:28:28
So, I looked at the logic and we don't even need a
| |
29 public: | |
30 DiskUnmounter(base::WeakPtr<ImageWriter> image_writer); | |
31 virtual ~DiskUnmounter(); | |
32 | |
33 // Claims and unmounts the device described by |device_path| and then calls | |
34 // the |continuation| when complete. This can be called from any thread. | |
35 // The continuation will be run on the thread this object was created on. | |
36 void Unmount(const std::string& device_path, | |
Robert Sesek
2014/06/05 19:49:48
Is this class meant to unmount more than one volum
Drew Haven
2014/06/05 22:28:28
No. The ImageWriter/ImageWriterHandler restrict t
| |
37 const base::Closure& continuation); | |
38 | |
39 private: | |
40 // Handles disk-claimed callbacks. | |
41 static void DiskClaimed(DADiskRef disk, | |
42 DADissenterRef dissenter, | |
43 void* context); | |
44 // Handles when we fail to claim a disk. | |
45 static DADissenterRef DiskClaimRevoked(DADiskRef disk, void* context); | |
46 // Handles the disk-unmounted callback. | |
47 static void DiskUnmounted(DADiskRef disk, | |
48 DADissenterRef dissenter, | |
49 void* context); | |
50 | |
51 // A |MessagePumpFactory| for creating the thread. | |
52 static scoped_ptr<base::MessagePump> CreateMessagePump(); | |
53 | |
54 // Starts the unmount process. Should be posted to the |cf_thread_|. | |
55 void UnmountOnWorker(const std::string& device_path); | |
56 | |
57 // A convenience method for sending an error back to the |image_writer_|. | |
58 void Error(const std::string& message); | |
59 | |
60 base::WeakPtr<ImageWriter> image_writer_; | |
61 base::Closure unmount_continuation_closure_; | |
62 scoped_refptr<base::MessageLoopProxy> original_thread_; | |
63 | |
64 base::ScopedCFTypeRef<DADiskRef> disk_; | |
65 base::ScopedCFTypeRef<DASessionRef> session_; | |
66 | |
67 // Thread is last to ensure it is stopped before this class is destroyed. | |
68 base::Thread cf_thread_; | |
69 }; | |
70 | |
71 } // namespace image_writer | |
72 | |
73 #endif // CHROME_UTILITY_IMAGE_WRITER_IMAGE_WRITER_MAC_H_ | |
OLD | NEW |