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

Side by Side Diff: ipc/ipc_channel_nacl.cc

Issue 10698138: PPAPI/NaCl: Make ipc_channel_nacl post to the correct thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/nacl_imc_api.h> 9 #include <sys/nacl_imc_api.h>
10 #include <sys/nacl_syscalls.h> 10 #include <sys/nacl_syscalls.h>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 waiting_connect_(true), 125 waiting_connect_(true),
126 pipe_(-1), 126 pipe_(-1),
127 pipe_name_(channel_handle.name), 127 pipe_name_(channel_handle.name),
128 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 128 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
129 if (!CreatePipe(channel_handle)) { 129 if (!CreatePipe(channel_handle)) {
130 // The pipe may have been closed already. 130 // The pipe may have been closed already.
131 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; 131 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client";
132 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name 132 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name
133 << "\" in " << modestr << " mode"; 133 << "\" in " << modestr << " mode";
134 } 134 }
135 reader_thread_runner_.reset(
136 new ReaderThreadRunner(
137 pipe_,
138 base::Bind(&Channel::ChannelImpl::DidRecvMsg,
139 weak_ptr_factory_.GetWeakPtr()),
140 base::Bind(&Channel::ChannelImpl::ReadDidFail,
141 weak_ptr_factory_.GetWeakPtr()),
142 base::MessageLoopProxy::current()));
143 reader_thread_.reset(
144 new base::DelegateSimpleThread(reader_thread_runner_.get(),
145 "ipc_channel_nacl reader thread"));
146 } 135 }
147 136
148 Channel::ChannelImpl::~ChannelImpl() { 137 Channel::ChannelImpl::~ChannelImpl() {
149 Close(); 138 Close();
150 } 139 }
151 140
152 bool Channel::ChannelImpl::Connect() { 141 bool Channel::ChannelImpl::Connect() {
153 if (pipe_ == -1) { 142 if (pipe_ == -1) {
154 DLOG(INFO) << "Channel creation failed: " << pipe_name_; 143 DLOG(INFO) << "Channel creation failed: " << pipe_name_;
155 return false; 144 return false;
156 } 145 }
157 146
147 // Note that Connect is called on the "Channel" thread (i.e., the same thread
148 // where Channel::Send will be called, and the same thread that should receive
149 // messages). The constructor might be invoked on another thread (see
150 // ChannelProxy for an example of that). Therefore, we must wait until Connect
151 // is called to decide which MessageLoopProxy to pass to ReaderThreadRunner
bbudge 2012/07/10 21:31:21 nit period.
152 reader_thread_runner_.reset(
153 new ReaderThreadRunner(
154 pipe_,
155 base::Bind(&Channel::ChannelImpl::DidRecvMsg,
156 weak_ptr_factory_.GetWeakPtr()),
157 base::Bind(&Channel::ChannelImpl::ReadDidFail,
158 weak_ptr_factory_.GetWeakPtr()),
159 base::MessageLoopProxy::current()));
160 reader_thread_.reset(
161 new base::DelegateSimpleThread(reader_thread_runner_.get(),
162 "ipc_channel_nacl reader thread"));
158 reader_thread_->Start(); 163 reader_thread_->Start();
159 waiting_connect_ = false; 164 waiting_connect_ = false;
160 // If there were any messages queued before connection, send them. 165 // If there were any messages queued before connection, send them.
161 ProcessOutgoingMessages(); 166 ProcessOutgoingMessages();
162 return true; 167 return true;
163 } 168 }
164 169
165 void Channel::ChannelImpl::Close() { 170 void Channel::ChannelImpl::Close() {
166 // For now, we assume that at shutdown, the reader thread will be woken with 171 // For now, we assume that at shutdown, the reader thread will be woken with
167 // a failure (see NaClIPCAdapter::BlockingRead and CloseChannel). Or... we 172 // a failure (see NaClIPCAdapter::BlockingRead and CloseChannel). Or... we
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // A random name is sufficient validation on posix systems, so we don't need 387 // A random name is sufficient validation on posix systems, so we don't need
383 // an additional shared secret. 388 // an additional shared secret.
384 std::string id = prefix; 389 std::string id = prefix;
385 if (!id.empty()) 390 if (!id.empty())
386 id.append("."); 391 id.append(".");
387 392
388 return id.append(GenerateUniqueRandomChannelID()); 393 return id.append(GenerateUniqueRandomChannelID());
389 } 394 }
390 395
391 } // namespace IPC 396 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698