blob: f04191e812700bd21eac52940751764e660a2cb3 [file] [log] [blame]
[email protected]b90d7e802011-01-09 16:32:201// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]946d1b22009-07-22 23:57:215#include "ipc/ipc_channel_win.h"
[email protected]c1afbd2c2008-10-13 19:19:366
initial.commit09911bf2008-07-26 23:55:297#include <windows.h>
[email protected]935aa542010-10-15 01:59:158#include <sddl.h>
initial.commit09911bf2008-07-26 23:55:299#include <sstream>
10
[email protected]5be7da242009-11-20 23:16:2611#include "base/auto_reset.h"
[email protected]c1afbd2c2008-10-13 19:19:3612#include "base/compiler_specific.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/logging.h"
[email protected]c9177502011-01-01 04:48:4914#include "base/threading/non_thread_safe.h"
[email protected]be1ce6a72010-08-03 14:35:2215#include "base/utf_string_conversions.h"
[email protected]b90d7e802011-01-09 16:32:2016#include "base/win/scoped_handle.h"
[email protected]946d1b22009-07-22 23:57:2117#include "ipc/ipc_logging.h"
18#include "ipc/ipc_message_utils.h"
initial.commit09911bf2008-07-26 23:55:2919
initial.commit09911bf2008-07-26 23:55:2920namespace IPC {
[email protected]935aa542010-10-15 01:59:1521
22namespace {
23
24// Creates a security descriptor with a DACL that has one ace giving full
25// access to the current logon session.
26// The security descriptor returned must be freed using LocalFree.
27// The function returns true if it succeeds, false otherwise.
28bool GetLogonSessionOnlyDACL(SECURITY_DESCRIPTOR** security_descriptor) {
29 // Get the current token.
30 HANDLE token = NULL;
31 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token))
32 return false;
[email protected]b90d7e802011-01-09 16:32:2033 base::win::ScopedHandle token_scoped(token);
[email protected]935aa542010-10-15 01:59:1534
35 // Get the size of the TokenGroups structure.
36 DWORD size = 0;
37 BOOL result = GetTokenInformation(token, TokenGroups, NULL, 0, &size);
38 if (result != FALSE && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
39 return false;
40
41 // Get the data.
42 scoped_array<char> token_groups_chars(new char[size]);
43 TOKEN_GROUPS* token_groups =
44 reinterpret_cast<TOKEN_GROUPS*>(token_groups_chars.get());
45
46 if (!GetTokenInformation(token, TokenGroups, token_groups, size, &size))
47 return false;
48
49 // Look for the logon sid.
50 SID* logon_sid = NULL;
51 for (unsigned int i = 0; i < token_groups->GroupCount ; ++i) {
52 if ((token_groups->Groups[i].Attributes & SE_GROUP_LOGON_ID) != 0) {
53 logon_sid = static_cast<SID*>(token_groups->Groups[i].Sid);
54 break;
55 }
56 }
57
58 if (!logon_sid)
59 return false;
60
61 // Convert the data to a string.
62 wchar_t* sid_string;
63 if (!ConvertSidToStringSid(logon_sid, &sid_string))
64 return false;
65
66 static const wchar_t dacl_format[] = L"D:(A;OICI;GA;;;%ls)";
67 wchar_t dacl[SECURITY_MAX_SID_SIZE + arraysize(dacl_format) + 1] = {0};
68 wsprintf(dacl, dacl_format, sid_string);
69
70 LocalFree(sid_string);
71
72 // Convert the string to a security descriptor
73 if (!ConvertStringSecurityDescriptorToSecurityDescriptor(
74 dacl,
75 SDDL_REVISION_1,
76 reinterpret_cast<PSECURITY_DESCRIPTOR*>(security_descriptor),
77 NULL)) {
78 return false;
79 }
80
81 return true;
82}
83
84} // namespace
85
initial.commit09911bf2008-07-26 23:55:2986//------------------------------------------------------------------------------
87
[email protected]514411fc2008-12-10 22:28:1188Channel::ChannelImpl::State::State(ChannelImpl* channel) : is_pending(false) {
[email protected]17b89142008-11-07 21:52:1589 memset(&context.overlapped, 0, sizeof(context.overlapped));
90 context.handler = channel;
initial.commit09911bf2008-07-26 23:55:2991}
92
[email protected]514411fc2008-12-10 22:28:1193Channel::ChannelImpl::State::~State() {
94 COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context),
95 starts_with_io_context);
initial.commit09911bf2008-07-26 23:55:2996}
97
98//------------------------------------------------------------------------------
99
[email protected]42ce94e2010-12-08 19:28:09100Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle,
101 Mode mode, Listener* listener)
[email protected]17b89142008-11-07 21:52:15102 : ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)),
103 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)),
104 pipe_(INVALID_HANDLE_VALUE),
initial.commit09911bf2008-07-26 23:55:29105 listener_(listener),
106 waiting_connect_(mode == MODE_SERVER),
[email protected]c1afbd2c2008-10-13 19:19:36107 processing_incoming_(false),
108 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
[email protected]22b42c592010-12-20 06:59:23109 switch(mode) {
110 case MODE_NONE:
111 LOG(FATAL) << "Bad mode for " << channel_handle.name;
112 break;
113 case MODE_SERVER:
114 case MODE_CLIENT:
115 break;
116 case MODE_NAMED_SERVER:
117 mode = MODE_SERVER;
118 break;
119 case MODE_NAMED_CLIENT:
120 mode = MODE_CLIENT;
121 break;
122 // Intentionally no default case here so that the compiler
123 // will check that we handle all the cases in the enum.
124 }
[email protected]42ce94e2010-12-08 19:28:09125 if (!CreatePipe(channel_handle, mode)) {
initial.commit09911bf2008-07-26 23:55:29126 // The pipe may have been closed already.
[email protected]42ce94e2010-12-08 19:28:09127 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name <<
initial.commit09911bf2008-07-26 23:55:29128 "\" in " << (mode == 0 ? "server" : "client") << " mode.";
129 }
130}
131
[email protected]601858c02010-09-01 17:08:20132Channel::ChannelImpl::~ChannelImpl() {
133 Close();
134}
135
[email protected]514411fc2008-12-10 22:28:11136void Channel::ChannelImpl::Close() {
[email protected]c1e4bff32009-01-29 00:07:06137 if (thread_check_.get()) {
138 DCHECK(thread_check_->CalledOnValidThread());
139 }
140
[email protected]74f87acf22009-10-14 22:10:40141 if (input_state_.is_pending || output_state_.is_pending)
[email protected]17b89142008-11-07 21:52:15142 CancelIo(pipe_);
[email protected]ee78622d2008-10-13 21:25:50143
[email protected]17b89142008-11-07 21:52:15144 // Closing the handle at this point prevents us from issuing more requests
145 // form OnIOCompleted().
initial.commit09911bf2008-07-26 23:55:29146 if (pipe_ != INVALID_HANDLE_VALUE) {
147 CloseHandle(pipe_);
148 pipe_ = INVALID_HANDLE_VALUE;
149 }
150
[email protected]17b89142008-11-07 21:52:15151 // Make sure all IO has completed.
152 base::Time start = base::Time::Now();
153 while (input_state_.is_pending || output_state_.is_pending) {
154 MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this);
155 }
[email protected]17b89142008-11-07 21:52:15156
initial.commit09911bf2008-07-26 23:55:29157 while (!output_queue_.empty()) {
158 Message* m = output_queue_.front();
159 output_queue_.pop();
160 delete m;
161 }
162}
163
[email protected]514411fc2008-12-10 22:28:11164bool Channel::ChannelImpl::Send(Message* message) {
[email protected]c1e4bff32009-01-29 00:07:06165 DCHECK(thread_check_->CalledOnValidThread());
[email protected]2a9d601b2010-10-19 23:50:00166 DVLOG(2) << "sending message @" << message << " on channel @" << this
167 << " with type " << message->type()
168 << " (" << output_queue_.size() << " in queue)";
initial.commit09911bf2008-07-26 23:55:29169
170#ifdef IPC_MESSAGE_LOG_ENABLED
[email protected]8e8bb6d2010-12-13 08:18:55171 Logging::GetInstance()->OnSendMessage(message, "");
initial.commit09911bf2008-07-26 23:55:29172#endif
173
174 output_queue_.push(message);
175 // ensure waiting to write
176 if (!waiting_connect_) {
177 if (!output_state_.is_pending) {
[email protected]c1afbd2c2008-10-13 19:19:36178 if (!ProcessOutgoingMessages(NULL, 0))
initial.commit09911bf2008-07-26 23:55:29179 return false;
initial.commit09911bf2008-07-26 23:55:29180 }
181 }
182
183 return true;
184}
185
[email protected]d3216442009-03-05 21:07:27186const std::wstring Channel::ChannelImpl::PipeName(
[email protected]9a3a293b2009-06-04 22:28:16187 const std::string& channel_id) const {
[email protected]514411fc2008-12-10 22:28:11188 std::wostringstream ss;
initial.commit09911bf2008-07-26 23:55:29189 // XXX(darin): get application name from somewhere else
[email protected]9a3a293b2009-06-04 22:28:16190 ss << L"\\\\.\\pipe\\chrome." << ASCIIToWide(channel_id);
initial.commit09911bf2008-07-26 23:55:29191 return ss.str();
192}
193
[email protected]42ce94e2010-12-08 19:28:09194bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle,
[email protected]514411fc2008-12-10 22:28:11195 Mode mode) {
initial.commit09911bf2008-07-26 23:55:29196 DCHECK(pipe_ == INVALID_HANDLE_VALUE);
[email protected]42ce94e2010-12-08 19:28:09197 const std::wstring pipe_name = PipeName(channel_handle.name);
initial.commit09911bf2008-07-26 23:55:29198 if (mode == MODE_SERVER) {
199 SECURITY_ATTRIBUTES security_attributes = {0};
200 security_attributes.bInheritHandle = FALSE;
201 security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
[email protected]935aa542010-10-15 01:59:15202 if (!GetLogonSessionOnlyDACL(
initial.commit09911bf2008-07-26 23:55:29203 reinterpret_cast<SECURITY_DESCRIPTOR**>(
204 &security_attributes.lpSecurityDescriptor))) {
205 NOTREACHED();
206 }
207
208 pipe_ = CreateNamedPipeW(pipe_name.c_str(),
209 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
210 FILE_FLAG_FIRST_PIPE_INSTANCE,
211 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
212 1, // number of pipe instances
[email protected]514411fc2008-12-10 22:28:11213 // output buffer size (XXX tune)
214 Channel::kReadBufferSize,
215 // input buffer size (XXX tune)
216 Channel::kReadBufferSize,
initial.commit09911bf2008-07-26 23:55:29217 5000, // timeout in milliseconds (XXX tune)
218 &security_attributes);
219 LocalFree(security_attributes.lpSecurityDescriptor);
220 } else {
221 pipe_ = CreateFileW(pipe_name.c_str(),
222 GENERIC_READ | GENERIC_WRITE,
223 0,
224 NULL,
225 OPEN_EXISTING,
226 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION |
227 FILE_FLAG_OVERLAPPED,
228 NULL);
229 }
230 if (pipe_ == INVALID_HANDLE_VALUE) {
231 // If this process is being closed, the pipe may be gone already.
232 LOG(WARNING) << "failed to create pipe: " << GetLastError();
233 return false;
234 }
235
236 // Create the Hello message to be sent when Connect is called
237 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE,
238 HELLO_MESSAGE_TYPE,
239 IPC::Message::PRIORITY_NORMAL));
240 if (!m->WriteInt(GetCurrentProcessId())) {
241 CloseHandle(pipe_);
242 pipe_ = INVALID_HANDLE_VALUE;
243 return false;
244 }
245
246 output_queue_.push(m.release());
247 return true;
248}
249
[email protected]514411fc2008-12-10 22:28:11250bool Channel::ChannelImpl::Connect() {
[email protected]19340722009-08-17 19:53:25251 DLOG_IF(WARNING, thread_check_.get()) << "Connect called more than once";
initial.commit09911bf2008-07-26 23:55:29252
[email protected]c1e4bff32009-01-29 00:07:06253 if (!thread_check_.get())
[email protected]c9177502011-01-01 04:48:49254 thread_check_.reset(new base::NonThreadSafe());
[email protected]c1e4bff32009-01-29 00:07:06255
initial.commit09911bf2008-07-26 23:55:29256 if (pipe_ == INVALID_HANDLE_VALUE)
257 return false;
258
[email protected]c1afbd2c2008-10-13 19:19:36259 MessageLoopForIO::current()->RegisterIOHandler(pipe_, this);
260
initial.commit09911bf2008-07-26 23:55:29261 // Check to see if there is a client connected to our pipe...
262 if (waiting_connect_)
263 ProcessConnection();
264
265 if (!input_state_.is_pending) {
[email protected]c1afbd2c2008-10-13 19:19:36266 // Complete setup asynchronously. By not setting input_state_.is_pending
267 // to true, we indicate to OnIOCompleted that this is the special
268 // initialization signal.
269 MessageLoopForIO::current()->PostTask(FROM_HERE, factory_.NewRunnableMethod(
[email protected]514411fc2008-12-10 22:28:11270 &Channel::ChannelImpl::OnIOCompleted, &input_state_.context, 0, 0));
initial.commit09911bf2008-07-26 23:55:29271 }
272
273 if (!waiting_connect_)
[email protected]c1afbd2c2008-10-13 19:19:36274 ProcessOutgoingMessages(NULL, 0);
initial.commit09911bf2008-07-26 23:55:29275 return true;
276}
277
[email protected]514411fc2008-12-10 22:28:11278bool Channel::ChannelImpl::ProcessConnection() {
[email protected]c1e4bff32009-01-29 00:07:06279 DCHECK(thread_check_->CalledOnValidThread());
[email protected]17b89142008-11-07 21:52:15280 if (input_state_.is_pending)
[email protected]c1afbd2c2008-10-13 19:19:36281 input_state_.is_pending = false;
initial.commit09911bf2008-07-26 23:55:29282
283 // Do we have a client connected to our pipe?
[email protected]17b89142008-11-07 21:52:15284 if (INVALID_HANDLE_VALUE == pipe_)
285 return false;
286
287 BOOL ok = ConnectNamedPipe(pipe_, &input_state_.context.overlapped);
initial.commit09911bf2008-07-26 23:55:29288
289 DWORD err = GetLastError();
290 if (ok) {
291 // Uhm, the API documentation says that this function should never
292 // return success when used in overlapped mode.
293 NOTREACHED();
294 return false;
295 }
296
297 switch (err) {
298 case ERROR_IO_PENDING:
299 input_state_.is_pending = true;
initial.commit09911bf2008-07-26 23:55:29300 break;
301 case ERROR_PIPE_CONNECTED:
302 waiting_connect_ = false;
303 break;
[email protected]20aa32c2009-07-14 22:25:49304 case ERROR_NO_DATA:
305 // The pipe is being closed.
306 return false;
initial.commit09911bf2008-07-26 23:55:29307 default:
308 NOTREACHED();
309 return false;
310 }
311
312 return true;
313}
314
[email protected]514411fc2008-12-10 22:28:11315bool Channel::ChannelImpl::ProcessIncomingMessages(
316 MessageLoopForIO::IOContext* context,
317 DWORD bytes_read) {
[email protected]c1e4bff32009-01-29 00:07:06318 DCHECK(thread_check_->CalledOnValidThread());
initial.commit09911bf2008-07-26 23:55:29319 if (input_state_.is_pending) {
320 input_state_.is_pending = false;
[email protected]c1afbd2c2008-10-13 19:19:36321 DCHECK(context);
initial.commit09911bf2008-07-26 23:55:29322
[email protected]c1afbd2c2008-10-13 19:19:36323 if (!context || !bytes_read)
initial.commit09911bf2008-07-26 23:55:29324 return false;
initial.commit09911bf2008-07-26 23:55:29325 } else {
[email protected]c1afbd2c2008-10-13 19:19:36326 // This happens at channel initialization.
[email protected]17b89142008-11-07 21:52:15327 DCHECK(!bytes_read && context == &input_state_.context);
initial.commit09911bf2008-07-26 23:55:29328 }
329
330 for (;;) {
331 if (bytes_read == 0) {
[email protected]17b89142008-11-07 21:52:15332 if (INVALID_HANDLE_VALUE == pipe_)
333 return false;
334
[email protected]c1afbd2c2008-10-13 19:19:36335 // Read from pipe...
initial.commit09911bf2008-07-26 23:55:29336 BOOL ok = ReadFile(pipe_,
337 input_buf_,
[email protected]514411fc2008-12-10 22:28:11338 Channel::kReadBufferSize,
initial.commit09911bf2008-07-26 23:55:29339 &bytes_read,
[email protected]17b89142008-11-07 21:52:15340 &input_state_.context.overlapped);
initial.commit09911bf2008-07-26 23:55:29341 if (!ok) {
342 DWORD err = GetLastError();
343 if (err == ERROR_IO_PENDING) {
initial.commit09911bf2008-07-26 23:55:29344 input_state_.is_pending = true;
345 return true;
346 }
347 LOG(ERROR) << "pipe error: " << err;
348 return false;
349 }
[email protected]17b89142008-11-07 21:52:15350 input_state_.is_pending = true;
351 return true;
initial.commit09911bf2008-07-26 23:55:29352 }
353 DCHECK(bytes_read);
354
[email protected]c1afbd2c2008-10-13 19:19:36355 // Process messages from input buffer.
initial.commit09911bf2008-07-26 23:55:29356
357 const char* p, *end;
358 if (input_overflow_buf_.empty()) {
359 p = input_buf_;
360 end = p + bytes_read;
361 } else {
362 if (input_overflow_buf_.size() > (kMaximumMessageSize - bytes_read)) {
363 input_overflow_buf_.clear();
364 LOG(ERROR) << "IPC message is too big";
365 return false;
366 }
367 input_overflow_buf_.append(input_buf_, bytes_read);
368 p = input_overflow_buf_.data();
369 end = p + input_overflow_buf_.size();
370 }
371
372 while (p < end) {
373 const char* message_tail = Message::FindNext(p, end);
374 if (message_tail) {
375 int len = static_cast<int>(message_tail - p);
376 const Message m(p, len);
[email protected]2a9d601b2010-10-19 23:50:00377 DVLOG(2) << "received message on channel @" << this
378 << " with type " << m.type();
initial.commit09911bf2008-07-26 23:55:29379 if (m.routing_id() == MSG_ROUTING_NONE &&
380 m.type() == HELLO_MESSAGE_TYPE) {
381 // The Hello message contains only the process id.
382 listener_->OnChannelConnected(MessageIterator(m).NextInt());
383 } else {
384 listener_->OnMessageReceived(m);
385 }
386 p = message_tail;
387 } else {
[email protected]c1afbd2c2008-10-13 19:19:36388 // Last message is partial.
initial.commit09911bf2008-07-26 23:55:29389 break;
390 }
391 }
392 input_overflow_buf_.assign(p, end - p);
393
[email protected]c1afbd2c2008-10-13 19:19:36394 bytes_read = 0; // Get more data.
initial.commit09911bf2008-07-26 23:55:29395 }
396
397 return true;
398}
399
[email protected]514411fc2008-12-10 22:28:11400bool Channel::ChannelImpl::ProcessOutgoingMessages(
401 MessageLoopForIO::IOContext* context,
402 DWORD bytes_written) {
initial.commit09911bf2008-07-26 23:55:29403 DCHECK(!waiting_connect_); // Why are we trying to send messages if there's
404 // no connection?
[email protected]c1e4bff32009-01-29 00:07:06405 DCHECK(thread_check_->CalledOnValidThread());
initial.commit09911bf2008-07-26 23:55:29406
407 if (output_state_.is_pending) {
[email protected]c1afbd2c2008-10-13 19:19:36408 DCHECK(context);
initial.commit09911bf2008-07-26 23:55:29409 output_state_.is_pending = false;
[email protected]c1afbd2c2008-10-13 19:19:36410 if (!context || bytes_written == 0) {
initial.commit09911bf2008-07-26 23:55:29411 DWORD err = GetLastError();
412 LOG(ERROR) << "pipe error: " << err;
413 return false;
414 }
[email protected]c1afbd2c2008-10-13 19:19:36415 // Message was sent.
initial.commit09911bf2008-07-26 23:55:29416 DCHECK(!output_queue_.empty());
417 Message* m = output_queue_.front();
418 output_queue_.pop();
419 delete m;
420 }
421
[email protected]17b89142008-11-07 21:52:15422 if (output_queue_.empty())
423 return true;
424
425 if (INVALID_HANDLE_VALUE == pipe_)
426 return false;
427
428 // Write to pipe...
429 Message* m = output_queue_.front();
[email protected]8a861402011-01-28 19:59:11430 DCHECK(m->size() <= INT_MAX);
[email protected]17b89142008-11-07 21:52:15431 BOOL ok = WriteFile(pipe_,
432 m->data(),
[email protected]8a861402011-01-28 19:59:11433 static_cast<int>(m->size()),
[email protected]17b89142008-11-07 21:52:15434 &bytes_written,
435 &output_state_.context.overlapped);
436 if (!ok) {
437 DWORD err = GetLastError();
438 if (err == ERROR_IO_PENDING) {
439 output_state_.is_pending = true;
initial.commit09911bf2008-07-26 23:55:29440
[email protected]2a9d601b2010-10-19 23:50:00441 DVLOG(2) << "sent pending message @" << m << " on channel @" << this
442 << " with type " << m->type();
initial.commit09911bf2008-07-26 23:55:29443
[email protected]17b89142008-11-07 21:52:15444 return true;
initial.commit09911bf2008-07-26 23:55:29445 }
[email protected]17b89142008-11-07 21:52:15446 LOG(ERROR) << "pipe error: " << err;
447 return false;
initial.commit09911bf2008-07-26 23:55:29448 }
449
[email protected]2a9d601b2010-10-19 23:50:00450 DVLOG(2) << "sent message @" << m << " on channel @" << this
451 << " with type " << m->type();
[email protected]17b89142008-11-07 21:52:15452
453 output_state_.is_pending = true;
initial.commit09911bf2008-07-26 23:55:29454 return true;
455}
456
[email protected]514411fc2008-12-10 22:28:11457void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context,
[email protected]17b89142008-11-07 21:52:15458 DWORD bytes_transfered, DWORD error) {
initial.commit09911bf2008-07-26 23:55:29459 bool ok;
[email protected]c1e4bff32009-01-29 00:07:06460 DCHECK(thread_check_->CalledOnValidThread());
[email protected]17b89142008-11-07 21:52:15461 if (context == &input_state_.context) {
initial.commit09911bf2008-07-26 23:55:29462 if (waiting_connect_) {
[email protected]17b89142008-11-07 21:52:15463 if (!ProcessConnection())
464 return;
initial.commit09911bf2008-07-26 23:55:29465 // We may have some messages queued up to send...
466 if (!output_queue_.empty() && !output_state_.is_pending)
[email protected]c1afbd2c2008-10-13 19:19:36467 ProcessOutgoingMessages(NULL, 0);
initial.commit09911bf2008-07-26 23:55:29468 if (input_state_.is_pending)
469 return;
470 // else, fall-through and look for incoming messages...
471 }
472 // we don't support recursion through OnMessageReceived yet!
473 DCHECK(!processing_incoming_);
[email protected]0fbd70332010-06-01 19:28:34474 AutoReset<bool> auto_reset_processing_incoming(&processing_incoming_, true);
[email protected]c1afbd2c2008-10-13 19:19:36475 ok = ProcessIncomingMessages(context, bytes_transfered);
initial.commit09911bf2008-07-26 23:55:29476 } else {
[email protected]17b89142008-11-07 21:52:15477 DCHECK(context == &output_state_.context);
[email protected]c1afbd2c2008-10-13 19:19:36478 ok = ProcessOutgoingMessages(context, bytes_transfered);
initial.commit09911bf2008-07-26 23:55:29479 }
[email protected]17b89142008-11-07 21:52:15480 if (!ok && INVALID_HANDLE_VALUE != pipe_) {
481 // We don't want to re-enter Close().
initial.commit09911bf2008-07-26 23:55:29482 Close();
483 listener_->OnChannelError();
484 }
485}
486
[email protected]514411fc2008-12-10 22:28:11487//------------------------------------------------------------------------------
488// Channel's methods simply call through to ChannelImpl.
[email protected]42ce94e2010-12-08 19:28:09489Channel::Channel(const IPC::ChannelHandle &channel_handle, Mode mode,
[email protected]514411fc2008-12-10 22:28:11490 Listener* listener)
[email protected]42ce94e2010-12-08 19:28:09491 : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) {
initial.commit09911bf2008-07-26 23:55:29492}
[email protected]514411fc2008-12-10 22:28:11493
494Channel::~Channel() {
495 delete channel_impl_;
496}
497
498bool Channel::Connect() {
499 return channel_impl_->Connect();
500}
501
502void Channel::Close() {
503 channel_impl_->Close();
504}
505
506void Channel::set_listener(Listener* listener) {
507 channel_impl_->set_listener(listener);
508}
509
510bool Channel::Send(Message* message) {
511 return channel_impl_->Send(message);
512}
513
514} // namespace IPC