| 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_sync_channel.h" | 5 #include "ipc/ipc_sync_channel.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 DCHECK_EQ(GetSendDoneEvent(), event); | 397 DCHECK_EQ(GetSendDoneEvent(), event); |
| 398 base::MessageLoop::current()->QuitNow(); | 398 base::MessageLoop::current()->QuitNow(); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 base::WaitableEventWatcher::EventCallback | 402 base::WaitableEventWatcher::EventCallback |
| 403 SyncChannel::SyncContext::MakeWaitableEventCallback() { | 403 SyncChannel::SyncContext::MakeWaitableEventCallback() { |
| 404 return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this); | 404 return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this); |
| 405 } | 405 } |
| 406 | 406 |
| 407 SyncChannel::SyncChannel( | 407 // static |
| 408 scoped_ptr<SyncChannel> SyncChannel::CreateClient( |
| 409 const IPC::ChannelHandle& channel_handle, |
| 410 Listener* listener, |
| 411 base::SingleThreadTaskRunner* ipc_task_runner, |
| 412 bool create_pipe_now, |
| 413 base::WaitableEvent* shutdown_event) { |
| 414 scoped_ptr<SyncChannel> channel = Create( |
| 415 listener, ipc_task_runner, shutdown_event); |
| 416 channel->InitClient(channel_handle, create_pipe_now); |
| 417 return channel.Pass(); |
| 418 } |
| 419 |
| 420 // static |
| 421 scoped_ptr<SyncChannel> SyncChannel::CreateServer( |
| 408 const IPC::ChannelHandle& channel_handle, | 422 const IPC::ChannelHandle& channel_handle, |
| 409 Channel::Mode mode, | |
| 410 Listener* listener, | 423 Listener* listener, |
| 411 base::SingleThreadTaskRunner* ipc_task_runner, | 424 base::SingleThreadTaskRunner* ipc_task_runner, |
| 412 bool create_pipe_now, | 425 bool create_pipe_now, |
| 413 WaitableEvent* shutdown_event) | 426 base::WaitableEvent* shutdown_event) { |
| 414 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { | 427 scoped_ptr<SyncChannel> channel = Create( |
| 415 // The current (listener) thread must be distinct from the IPC thread, or else | 428 listener, ipc_task_runner, shutdown_event); |
| 416 // sending synchronous messages will deadlock. | 429 channel->InitServer(channel_handle, create_pipe_now); |
| 417 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); | 430 return channel.Pass(); |
| 418 ChannelProxy::Init(channel_handle, mode, create_pipe_now); | 431 } |
| 419 StartWatching(); | 432 |
| 433 // static |
| 434 scoped_ptr<SyncChannel> SyncChannel::CreateNamedClient( |
| 435 const IPC::ChannelHandle& channel_handle, |
| 436 Listener* listener, |
| 437 base::SingleThreadTaskRunner* ipc_task_runner, |
| 438 bool create_pipe_now, |
| 439 base::WaitableEvent* shutdown_event) { |
| 440 scoped_ptr<SyncChannel> channel = Create( |
| 441 listener, ipc_task_runner, shutdown_event); |
| 442 channel->InitNamedClient(channel_handle, create_pipe_now); |
| 443 return channel.Pass(); |
| 444 } |
| 445 |
| 446 // static |
| 447 scoped_ptr<SyncChannel> SyncChannel::CreateNamedServer( |
| 448 const IPC::ChannelHandle& channel_handle, |
| 449 Listener* listener, |
| 450 base::SingleThreadTaskRunner* ipc_task_runner, |
| 451 bool create_pipe_now, |
| 452 base::WaitableEvent* shutdown_event) { |
| 453 scoped_ptr<SyncChannel> channel = Create( |
| 454 listener, ipc_task_runner, shutdown_event); |
| 455 channel->InitNamedServer(channel_handle, create_pipe_now); |
| 456 return channel.Pass(); |
| 457 } |
| 458 |
| 459 // static |
| 460 scoped_ptr<SyncChannel> SyncChannel::Create( |
| 461 Listener* listener, |
| 462 base::SingleThreadTaskRunner* ipc_task_runner, |
| 463 WaitableEvent* shutdown_event) { |
| 464 return make_scoped_ptr(new SyncChannel( |
| 465 listener, ipc_task_runner, shutdown_event)); |
| 420 } | 466 } |
| 421 | 467 |
| 422 SyncChannel::SyncChannel( | 468 SyncChannel::SyncChannel( |
| 423 Listener* listener, | 469 Listener* listener, |
| 424 base::SingleThreadTaskRunner* ipc_task_runner, | 470 base::SingleThreadTaskRunner* ipc_task_runner, |
| 425 WaitableEvent* shutdown_event) | 471 WaitableEvent* shutdown_event) |
| 426 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { | 472 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { |
| 427 // The current (listener) thread must be distinct from the IPC thread, or else | 473 // The current (listener) thread must be distinct from the IPC thread, or else |
| 428 // sending synchronous messages will deadlock. | 474 // sending synchronous messages will deadlock. |
| 429 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); | 475 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // manual reset since the object watcher might otherwise reset the event | 602 // manual reset since the object watcher might otherwise reset the event |
| 557 // when we're doing a WaitMany. | 603 // when we're doing a WaitMany. |
| 558 dispatch_watcher_callback_ = | 604 dispatch_watcher_callback_ = |
| 559 base::Bind(&SyncChannel::OnWaitableEventSignaled, | 605 base::Bind(&SyncChannel::OnWaitableEventSignaled, |
| 560 base::Unretained(this)); | 606 base::Unretained(this)); |
| 561 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), | 607 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), |
| 562 dispatch_watcher_callback_); | 608 dispatch_watcher_callback_); |
| 563 } | 609 } |
| 564 | 610 |
| 565 } // namespace IPC | 611 } // namespace IPC |
| OLD | NEW |