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

Unified Diff: chrome/browser/mac/relauncher.cc

Issue 191673003: Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/mac/relauncher.cc
diff --git a/chrome/browser/mac/relauncher.cc b/chrome/browser/mac/relauncher.cc
index 5d8357fc5dcbe428d13a75b38044b7c7ae14b256..e659793fe0f45c838f8a6b9483e60b21715c96db 100644
--- a/chrome/browser/mac/relauncher.cc
+++ b/chrome/browser/mac/relauncher.cc
@@ -19,6 +19,7 @@
#include "base/basictypes.h"
#include "base/file_util.h"
+#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h"
@@ -132,8 +133,8 @@ bool RelaunchAppWithHelper(const std::string& helper,
// write side of the pipe. In that process, the read side will be closed by
// base::LaunchApp because it won't be present in fd_map, and the write side
// will be remapped to kRelauncherSyncFD by fd_map.
- file_util::ScopedFD pipe_read_fd(&pipe_fds[0]);
- file_util::ScopedFD pipe_write_fd(&pipe_fds[1]);
+ base::ScopedFD pipe_read_fd(pipe_fds[0]);
+ base::ScopedFD pipe_write_fd(pipe_fds[1]);
// Make sure kRelauncherSyncFD is a safe value. base::LaunchProcess will
// preserve these three FDs in forked processes, so kRelauncherSyncFD should
@@ -144,7 +145,7 @@ bool RelaunchAppWithHelper(const std::string& helper,
kRelauncherSyncFD_must_not_conflict_with_stdio_fds);
base::FileHandleMappingVector fd_map;
- fd_map.push_back(std::make_pair(*pipe_write_fd, kRelauncherSyncFD));
+ fd_map.push_back(std::make_pair(pipe_write_fd.get(), kRelauncherSyncFD));
base::LaunchOptions options;
options.fds_to_remap = &fd_map;
@@ -160,7 +161,7 @@ bool RelaunchAppWithHelper(const std::string& helper,
// Synchronize with the relauncher process.
char read_char;
- int read_result = HANDLE_EINTR(read(*pipe_read_fd, &read_char, 1));
+ int read_result = HANDLE_EINTR(read(pipe_read_fd.get(), &read_char, 1));
if (read_result != 1) {
if (read_result < 0) {
PLOG(ERROR) << "read";
@@ -185,9 +186,7 @@ namespace {
// situations, it can be assumed that something went wrong with the parent
// process and the best recovery approach is to attempt relaunch anyway.
void RelauncherSynchronizeWithParent() {
- // file_util::ScopedFD needs something non-const to operate on.
- int relauncher_sync_fd = kRelauncherSyncFD;
- file_util::ScopedFD relauncher_sync_fd_closer(&relauncher_sync_fd);
+ base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD);
int parent_pid = getppid();
@@ -201,22 +200,21 @@ void RelauncherSynchronizeWithParent() {
}
// Set up a kqueue to monitor the parent process for exit.
- int kq = kqueue();
- if (kq < 0) {
+ base::ScopedFD kq(kqueue());
+ if (!kq.is_valid()) {
PLOG(ERROR) << "kqueue";
return;
}
- file_util::ScopedFD kq_closer(&kq);
struct kevent change = { 0 };
EV_SET(&change, parent_pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
- if (kevent(kq, &change, 1, NULL, 0, NULL) == -1) {
+ if (kevent(kq.get(), &change, 1, NULL, 0, NULL) == -1) {
PLOG(ERROR) << "kevent (add)";
return;
}
// Write a '\0' character to the pipe.
- if (HANDLE_EINTR(write(relauncher_sync_fd, "", 1)) != 1) {
+ if (HANDLE_EINTR(write(relauncher_sync_fd.get(), "", 1)) != 1) {
PLOG(ERROR) << "write";
return;
}
@@ -225,7 +223,7 @@ void RelauncherSynchronizeWithParent() {
// write above to complete. The parent process is now free to exit. Wait for
// that to happen.
struct kevent event;
- int events = kevent(kq, NULL, 0, &event, 1, NULL);
+ int events = kevent(kq.get(), NULL, 0, &event, 1, NULL);
if (events != 1) {
if (events < 0) {
PLOG(ERROR) << "kevent (monitor)";

Powered by Google App Engine
This is Rietveld 408576698