OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/chromeos/process_proxy/process_output_watcher.h" | 5 #include "chromeos/process_proxy/process_output_watcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdio> | 8 #include <cstdio> |
9 #include <cstring> | 9 #include <cstring> |
10 | 10 |
11 #include <sys/ioctl.h> | 11 #include <sys/ioctl.h> |
12 #include <sys/select.h> | 12 #include <sys/select.h> |
13 #include <unistd.h> | 13 #include <unistd.h> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... |
27 void CloseFd(int* fd) { | 27 void CloseFd(int* fd) { |
28 if (*fd >= 0) { | 28 if (*fd >= 0) { |
29 if (HANDLE_EINTR(close(*fd)) != 0) | 29 if (HANDLE_EINTR(close(*fd)) != 0) |
30 DPLOG(WARNING) << "close fd " << *fd << " failed."; | 30 DPLOG(WARNING) << "close fd " << *fd << " failed."; |
31 } | 31 } |
32 *fd = -1; | 32 *fd = -1; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
| 37 namespace chromeos { |
| 38 |
37 ProcessOutputWatcher::ProcessOutputWatcher(int out_fd, int stop_fd, | 39 ProcessOutputWatcher::ProcessOutputWatcher(int out_fd, int stop_fd, |
38 const ProcessOutputCallback& callback) | 40 const ProcessOutputCallback& callback) |
39 : out_fd_(out_fd), | 41 : out_fd_(out_fd), |
40 stop_fd_(stop_fd), | 42 stop_fd_(stop_fd), |
41 on_read_callback_(callback) { | 43 on_read_callback_(callback) { |
42 VerifyFileDescriptor(out_fd_); | 44 VerifyFileDescriptor(out_fd_); |
43 VerifyFileDescriptor(stop_fd_); | 45 VerifyFileDescriptor(stop_fd_); |
44 max_fd_ = std::max(out_fd_, stop_fd_); | 46 max_fd_ = std::max(out_fd_, stop_fd_); |
45 // We want to be sure we will be able to add 0 at the end of the input, so -1. | 47 // We want to be sure we will be able to add 0 at the end of the input, so -1. |
46 read_buffer_size_ = arraysize(read_buffer_) - 1; | 48 read_buffer_size_ = arraysize(read_buffer_) - 1; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 CloseFd(fd); | 109 CloseFd(fd); |
108 | 110 |
109 // We have lost contact with the process, so report it. | 111 // We have lost contact with the process, so report it. |
110 on_read_callback_.Run(PROCESS_OUTPUT_TYPE_EXIT, ""); | 112 on_read_callback_.Run(PROCESS_OUTPUT_TYPE_EXIT, ""); |
111 } | 113 } |
112 } | 114 } |
113 | 115 |
114 void ProcessOutputWatcher::OnStop() { | 116 void ProcessOutputWatcher::OnStop() { |
115 delete this; | 117 delete this; |
116 } | 118 } |
| 119 |
| 120 } // namespace chromeos |
OLD | NEW |