Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Side by Side Diff: chrome/utility/image_writer/image_writer_mac.cc

Issue 2950153002: Improve process launch handle sharing API. (Closed)
Patch Set: Fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <CoreFoundation/CoreFoundation.h> 5 #include <CoreFoundation/CoreFoundation.h>
6 #include <IOKit/IOBSD.h> 6 #include <IOKit/IOBSD.h>
7 #include <IOKit/IOKitLib.h> 7 #include <IOKit/IOKitLib.h>
8 #include <IOKit/storage/IOBlockStorageDevice.h> 8 #include <IOKit/storage/IOBlockStorageDevice.h>
9 #include <IOKit/storage/IOMedia.h> 9 #include <IOKit/storage/IOMedia.h>
10 #include <IOKit/storage/IOStorageProtocolCharacteristics.h> 10 #include <IOKit/storage/IOStorageProtocolCharacteristics.h>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 unmounter_->Unmount( 70 unmounter_->Unmount(
71 device_path_.value(), 71 device_path_.value(),
72 continuation, 72 continuation,
73 base::Bind( 73 base::Bind(
74 &ImageWriter::Error, base::Unretained(this), error::kUnmountVolumes)); 74 &ImageWriter::Error, base::Unretained(this), error::kUnmountVolumes));
75 } 75 }
76 76
77 bool ImageWriter::OpenDevice() { 77 bool ImageWriter::OpenDevice() {
78 base::LaunchOptions options = base::LaunchOptions(); 78 base::LaunchOptions options;
79 options.wait = false; 79 options.wait = false;
80 80
81 // Create a socket pair for communication. 81 // Create a socket pair for communication.
82 int sockets[2]; 82 int sockets[2];
83 int result = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets); 83 int result = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
84 if (result == -1) { 84 if (result == -1) {
85 PLOG(ERROR) << "Unable to allocate socket pair."; 85 PLOG(ERROR) << "Unable to allocate socket pair.";
86 return false; 86 return false;
87 } 87 }
88 base::ScopedFD parent_socket(sockets[0]); 88 base::ScopedFD parent_socket(sockets[0]);
89 base::ScopedFD child_socket(sockets[1]); 89 base::ScopedFD child_socket(sockets[1]);
90 90
91 // Map the client socket to the client's STDOUT. 91 // Map the client socket to the client's STDOUT.
92 base::FileHandleMappingVector fd_map; 92 options.fds_to_remap.push_back(
93 fd_map.push_back(std::pair<int, int>(child_socket.get(), STDOUT_FILENO)); 93 std::pair<int, int>(child_socket.get(), STDOUT_FILENO));
94 options.fds_to_remap = &fd_map;
95 94
96 // Find the file path to open. 95 // Find the file path to open.
97 base::FilePath real_device_path; 96 base::FilePath real_device_path;
98 if (device_path_.IsAbsolute()) { 97 if (device_path_.IsAbsolute()) {
99 // This only occurs for tests where the device path is mocked with a 98 // This only occurs for tests where the device path is mocked with a
100 // temporary file. 99 // temporary file.
101 real_device_path = device_path_; 100 real_device_path = device_path_;
102 } else { 101 } else {
103 // Get the raw device file. Writes need to be in multiples of 102 // Get the raw device file. Writes need to be in multiples of
104 // DAMediaBlockSize (usually 512). This is fine since WriteChunk() writes in 103 // DAMediaBlockSize (usually 512). This is fine since WriteChunk() writes in
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 164
166 if (child_exit_status) { 165 if (child_exit_status) {
167 LOG(ERROR) << "Child process returned failure."; 166 LOG(ERROR) << "Child process returned failure.";
168 return false; 167 return false;
169 } 168 }
170 169
171 return device_file_.IsValid(); 170 return device_file_.IsValid();
172 } 171 }
173 172
174 } // namespace image_writer 173 } // namespace image_writer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698