OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // static | 216 // static |
217 scoped_ptr<ChannelFactory> ChannelMojo::CreateClientFactory( | 217 scoped_ptr<ChannelFactory> ChannelMojo::CreateClientFactory( |
218 mojo::ScopedMessagePipeHandle handle) { | 218 mojo::ScopedMessagePipeHandle handle) { |
219 return make_scoped_ptr( | 219 return make_scoped_ptr( |
220 new MojoChannelFactory(std::move(handle), Channel::MODE_CLIENT)); | 220 new MojoChannelFactory(std::move(handle), Channel::MODE_CLIENT)); |
221 } | 221 } |
222 | 222 |
223 ChannelMojo::ChannelMojo(mojo::ScopedMessagePipeHandle handle, | 223 ChannelMojo::ChannelMojo(mojo::ScopedMessagePipeHandle handle, |
224 Mode mode, | 224 Mode mode, |
225 Listener* listener) | 225 Listener* listener) |
226 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 226 : pipe_(handle.get()), |
227 pipe_(handle.get()), | |
228 listener_(listener), | 227 listener_(listener), |
229 waiting_connect_(true), | 228 waiting_connect_(true), |
230 weak_factory_(this) { | 229 weak_factory_(this) { |
231 // Create MojoBootstrap after all members are set as it touches | 230 // Create MojoBootstrap after all members are set as it touches |
232 // ChannelMojo from a different thread. | 231 // ChannelMojo from a different thread. |
233 bootstrap_ = MojoBootstrap::Create(std::move(handle), mode, this); | 232 bootstrap_ = MojoBootstrap::Create(std::move(handle), mode, this); |
234 } | 233 } |
235 | 234 |
236 ChannelMojo::~ChannelMojo() { | 235 ChannelMojo::~ChannelMojo() { |
237 Close(); | 236 Close(); |
238 } | 237 } |
239 | 238 |
240 bool ChannelMojo::Connect() { | 239 bool ChannelMojo::Connect() { |
241 base::AutoLock lock(lock_); | 240 base::AutoLock lock(lock_); |
| 241 DCHECK(!task_runner_); |
| 242 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
242 DCHECK(!message_reader_); | 243 DCHECK(!message_reader_); |
243 bootstrap_->Connect(); | 244 bootstrap_->Connect(); |
244 return true; | 245 return true; |
245 } | 246 } |
246 | 247 |
247 void ChannelMojo::Close() { | 248 void ChannelMojo::Close() { |
248 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> reader; | 249 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> reader; |
249 { | 250 { |
250 base::AutoLock lock(lock_); | 251 base::AutoLock lock(lock_); |
251 if (!message_reader_) | 252 if (!message_reader_) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 306 } |
306 } | 307 } |
307 | 308 |
308 if (connected) | 309 if (connected) |
309 listener_->OnChannelConnected(static_cast<int32_t>(GetPeerPID())); | 310 listener_->OnChannelConnected(static_cast<int32_t>(GetPeerPID())); |
310 else | 311 else |
311 OnPipeError(); | 312 OnPipeError(); |
312 } | 313 } |
313 | 314 |
314 void ChannelMojo::OnPipeError() { | 315 void ChannelMojo::OnPipeError() { |
| 316 DCHECK(task_runner_); |
315 if (task_runner_->RunsTasksOnCurrentThread()) { | 317 if (task_runner_->RunsTasksOnCurrentThread()) { |
316 listener_->OnChannelError(); | 318 listener_->OnChannelError(); |
317 } else { | 319 } else { |
318 task_runner_->PostTask( | 320 task_runner_->PostTask( |
319 FROM_HERE, | 321 FROM_HERE, |
320 base::Bind(&ChannelMojo::OnPipeError, weak_factory_.GetWeakPtr())); | 322 base::Bind(&ChannelMojo::OnPipeError, weak_factory_.GetWeakPtr())); |
321 } | 323 } |
322 } | 324 } |
323 | 325 |
324 bool ChannelMojo::Send(Message* message) { | 326 bool ChannelMojo::Send(Message* message) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 DCHECK(ok); | 426 DCHECK(ok); |
425 if (!ok) { | 427 if (!ok) { |
426 LOG(ERROR) << "Failed to add new Mojo handle."; | 428 LOG(ERROR) << "Failed to add new Mojo handle."; |
427 return MOJO_RESULT_UNKNOWN; | 429 return MOJO_RESULT_UNKNOWN; |
428 } | 430 } |
429 } | 431 } |
430 return MOJO_RESULT_OK; | 432 return MOJO_RESULT_OK; |
431 } | 433 } |
432 | 434 |
433 } // namespace IPC | 435 } // namespace IPC |
OLD | NEW |