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

Side by Side Diff: chromeos/process_proxy/process_proxy.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chromeos/process_proxy/process_proxy.h" 5 #include "chromeos/process_proxy/process_proxy.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <sys/ioctl.h> 9 #include <sys/ioctl.h>
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (callback_set_) 125 if (callback_set_)
126 callback_.Run(type, output); 126 callback_.Run(type, output);
127 } 127 }
128 128
129 bool ProcessProxy::StopWatching() { 129 bool ProcessProxy::StopWatching() {
130 if (!watcher_started_) 130 if (!watcher_started_)
131 return true; 131 return true;
132 // Signal Watcher that we are done. We use self-pipe trick to unblock watcher. 132 // Signal Watcher that we are done. We use self-pipe trick to unblock watcher.
133 // Anything may be written to the pipe. 133 // Anything may be written to the pipe.
134 const char message[] = "q"; 134 const char message[] = "q";
135 return file_util::WriteFileDescriptor(shutdown_pipe_[PIPE_END_WRITE], 135 return base::WriteFileDescriptor(shutdown_pipe_[PIPE_END_WRITE],
136 message, sizeof(message)); 136 message, sizeof(message));
137 } 137 }
138 138
139 void ProcessProxy::Close() { 139 void ProcessProxy::Close() {
140 if (!process_launched_) 140 if (!process_launched_)
141 return; 141 return;
142 142
143 process_launched_ = false; 143 process_launched_ = false;
144 callback_set_ = false; 144 callback_set_ = false;
145 callback_ = ProcessOutputCallback(); 145 callback_ = ProcessOutputCallback();
146 callback_runner_ = NULL; 146 callback_runner_ = NULL;
147 147
148 base::KillProcess(pid_, 0, true /* wait */); 148 base::KillProcess(pid_, 0, true /* wait */);
149 149
150 // TODO(tbarzic): What if this fails? 150 // TODO(tbarzic): What if this fails?
151 StopWatching(); 151 StopWatching();
152 152
153 CloseAllFdPairs(); 153 CloseAllFdPairs();
154 } 154 }
155 155
156 bool ProcessProxy::Write(const std::string& text) { 156 bool ProcessProxy::Write(const std::string& text) {
157 if (!process_launched_) 157 if (!process_launched_)
158 return false; 158 return false;
159 159
160 // We don't want to write '\0' to the pipe. 160 // We don't want to write '\0' to the pipe.
161 size_t data_size = text.length() * sizeof(*text.c_str()); 161 size_t data_size = text.length() * sizeof(*text.c_str());
162 int bytes_written = 162 int bytes_written =
163 file_util::WriteFileDescriptor(pt_pair_[PT_MASTER_FD], 163 base::WriteFileDescriptor(pt_pair_[PT_MASTER_FD],
164 text.c_str(), data_size); 164 text.c_str(), data_size);
165 return (bytes_written == static_cast<int>(data_size)); 165 return (bytes_written == static_cast<int>(data_size));
166 } 166 }
167 167
168 bool ProcessProxy::OnTerminalResize(int width, int height) { 168 bool ProcessProxy::OnTerminalResize(int width, int height) {
169 if (width < 0 || height < 0) 169 if (width < 0 || height < 0)
170 return false; 170 return false;
171 171
172 winsize ws; 172 winsize ws;
173 // Number of rows. 173 // Number of rows.
174 ws.ws_row = height; 174 ws.ws_row = height;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ClearFdPair(pt_pair_); 254 ClearFdPair(pt_pair_);
255 ClearFdPair(shutdown_pipe_); 255 ClearFdPair(shutdown_pipe_);
256 } 256 }
257 257
258 void ProcessProxy::ClearFdPair(int* pipe) { 258 void ProcessProxy::ClearFdPair(int* pipe) {
259 pipe[PIPE_END_READ] = kInvalidFd; 259 pipe[PIPE_END_READ] = kInvalidFd;
260 pipe[PIPE_END_WRITE] = kInvalidFd; 260 pipe[PIPE_END_WRITE] = kInvalidFd;
261 } 261 }
262 262
263 } // namespace chromeos 263 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/process_proxy/process_output_watcher_unittest.cc ('k') | cloud_print/gcp20/prototype/print_job_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698