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 // static | 407 SyncChannel::SyncChannel( |
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( | |
422 const IPC::ChannelHandle& channel_handle, | 408 const IPC::ChannelHandle& channel_handle, |
| 409 Channel::Mode mode, |
423 Listener* listener, | 410 Listener* listener, |
424 base::SingleThreadTaskRunner* ipc_task_runner, | 411 base::SingleThreadTaskRunner* ipc_task_runner, |
425 bool create_pipe_now, | 412 bool create_pipe_now, |
426 base::WaitableEvent* shutdown_event) { | 413 WaitableEvent* shutdown_event) |
427 scoped_ptr<SyncChannel> channel = Create( | 414 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { |
428 listener, ipc_task_runner, shutdown_event); | 415 // The current (listener) thread must be distinct from the IPC thread, or else |
429 channel->InitServer(channel_handle, create_pipe_now); | 416 // sending synchronous messages will deadlock. |
430 return channel.Pass(); | 417 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); |
431 } | 418 ChannelProxy::Init(channel_handle, mode, create_pipe_now); |
432 | 419 StartWatching(); |
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)); | |
466 } | 420 } |
467 | 421 |
468 SyncChannel::SyncChannel( | 422 SyncChannel::SyncChannel( |
469 Listener* listener, | 423 Listener* listener, |
470 base::SingleThreadTaskRunner* ipc_task_runner, | 424 base::SingleThreadTaskRunner* ipc_task_runner, |
471 WaitableEvent* shutdown_event) | 425 WaitableEvent* shutdown_event) |
472 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { | 426 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { |
473 // The current (listener) thread must be distinct from the IPC thread, or else | 427 // The current (listener) thread must be distinct from the IPC thread, or else |
474 // sending synchronous messages will deadlock. | 428 // sending synchronous messages will deadlock. |
475 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); | 429 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // manual reset since the object watcher might otherwise reset the event | 556 // manual reset since the object watcher might otherwise reset the event |
603 // when we're doing a WaitMany. | 557 // when we're doing a WaitMany. |
604 dispatch_watcher_callback_ = | 558 dispatch_watcher_callback_ = |
605 base::Bind(&SyncChannel::OnWaitableEventSignaled, | 559 base::Bind(&SyncChannel::OnWaitableEventSignaled, |
606 base::Unretained(this)); | 560 base::Unretained(this)); |
607 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), | 561 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), |
608 dispatch_watcher_callback_); | 562 dispatch_watcher_callback_); |
609 } | 563 } |
610 | 564 |
611 } // namespace IPC | 565 } // namespace IPC |
OLD | NEW |