| 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 "ipc/ipc_channel_nacl.h" | 5 #include "ipc/ipc_channel_nacl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 main_task_runner_->PostTask(FROM_HERE, failure_callback_); | 115 main_task_runner_->PostTask(FROM_HERE, failure_callback_); |
| 116 // Because the read failed, we know we're going to quit. Don't bother | 116 // Because the read failed, we know we're going to quit. Don't bother |
| 117 // trying to read again. | 117 // trying to read again. |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 ChannelNacl::ChannelNacl(const IPC::ChannelHandle& channel_handle, | 123 ChannelNacl::ChannelNacl(const IPC::ChannelHandle& channel_handle, |
| 124 Mode mode, | 124 Mode mode, |
| 125 Listener* listener) | 125 Listener* listener, |
| 126 AttachmentBroker* broker) |
| 126 : ChannelReader(listener), | 127 : ChannelReader(listener), |
| 127 mode_(mode), | 128 mode_(mode), |
| 128 waiting_connect_(true), | 129 waiting_connect_(true), |
| 129 pipe_(-1), | 130 pipe_(-1), |
| 130 pipe_name_(channel_handle.name), | 131 pipe_name_(channel_handle.name), |
| 131 weak_ptr_factory_(this) { | 132 weak_ptr_factory_(this), |
| 133 broker_(broker) { |
| 132 if (!CreatePipe(channel_handle)) { | 134 if (!CreatePipe(channel_handle)) { |
| 133 // The pipe may have been closed already. | 135 // The pipe may have been closed already. |
| 134 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; | 136 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; |
| 135 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name | 137 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name |
| 136 << "\" in " << modestr << " mode"; | 138 << "\" in " << modestr << " mode"; |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 | 141 |
| 140 ChannelNacl::~ChannelNacl() { | 142 ChannelNacl::~ChannelNacl() { |
| 141 Close(); | 143 Close(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 #endif // IPC_MESSAGE_LOG_ENABLED | 212 #endif // IPC_MESSAGE_LOG_ENABLED |
| 211 | 213 |
| 212 message->TraceMessageBegin(); | 214 message->TraceMessageBegin(); |
| 213 output_queue_.push_back(linked_ptr<Message>(message_ptr.release())); | 215 output_queue_.push_back(linked_ptr<Message>(message_ptr.release())); |
| 214 if (!waiting_connect_) | 216 if (!waiting_connect_) |
| 215 return ProcessOutgoingMessages(); | 217 return ProcessOutgoingMessages(); |
| 216 | 218 |
| 217 return true; | 219 return true; |
| 218 } | 220 } |
| 219 | 221 |
| 222 AttachmentBroker* ChannelNacl::GetAttachmentBroker() { |
| 223 return broker_; |
| 224 } |
| 225 |
| 220 void ChannelNacl::DidRecvMsg(scoped_ptr<MessageContents> contents) { | 226 void ChannelNacl::DidRecvMsg(scoped_ptr<MessageContents> contents) { |
| 221 // Close sets the pipe to -1. It's possible we'll get a buffer sent to us from | 227 // Close sets the pipe to -1. It's possible we'll get a buffer sent to us from |
| 222 // the reader thread after Close is called. If so, we ignore it. | 228 // the reader thread after Close is called. If so, we ignore it. |
| 223 if (pipe_ == -1) | 229 if (pipe_ == -1) |
| 224 return; | 230 return; |
| 225 | 231 |
| 226 linked_ptr<std::vector<char> > data(new std::vector<char>); | 232 linked_ptr<std::vector<char> > data(new std::vector<char>); |
| 227 data->swap(contents->data); | 233 data->swap(contents->data); |
| 228 read_queue_.push_back(data); | 234 read_queue_.push_back(data); |
| 229 | 235 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 371 |
| 366 void ChannelNacl::HandleInternalMessage(const Message& msg) { | 372 void ChannelNacl::HandleInternalMessage(const Message& msg) { |
| 367 // The trusted side IPC::Channel should handle the "hello" handshake; we | 373 // The trusted side IPC::Channel should handle the "hello" handshake; we |
| 368 // should not receive the "Hello" message. | 374 // should not receive the "Hello" message. |
| 369 NOTREACHED(); | 375 NOTREACHED(); |
| 370 } | 376 } |
| 371 | 377 |
| 372 // Channel's methods | 378 // Channel's methods |
| 373 | 379 |
| 374 // static | 380 // static |
| 375 scoped_ptr<Channel> Channel::Create( | 381 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, |
| 376 const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { | 382 Mode mode, |
| 383 Listener* listener, |
| 384 AttachmentBroker* broker) { |
| 377 return scoped_ptr<Channel>( | 385 return scoped_ptr<Channel>( |
| 378 new ChannelNacl(channel_handle, mode, listener)); | 386 new ChannelNacl(channel_handle, mode, listener, broker)); |
| 379 } | 387 } |
| 380 | 388 |
| 381 } // namespace IPC | 389 } // namespace IPC |
| OLD | NEW |