OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 SyncChannel::SyncChannel( | 374 SyncChannel::SyncChannel( |
375 const IPC::ChannelHandle& channel_handle, | 375 const IPC::ChannelHandle& channel_handle, |
376 Channel::Mode mode, | 376 Channel::Mode mode, |
377 Channel::Listener* listener, | 377 Channel::Listener* listener, |
378 base::MessageLoopProxy* ipc_message_loop, | 378 base::MessageLoopProxy* ipc_message_loop, |
379 bool create_pipe_now, | 379 bool create_pipe_now, |
380 WaitableEvent* shutdown_event) | 380 WaitableEvent* shutdown_event) |
381 : ChannelProxy( | 381 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), |
382 channel_handle, mode, ipc_message_loop, | |
383 new SyncContext(listener, ipc_message_loop, shutdown_event), | |
384 create_pipe_now), | |
385 sync_messages_with_no_timeout_allowed_(true) { | 382 sync_messages_with_no_timeout_allowed_(true) { |
386 // Ideally we only want to watch this object when running a nested message | 383 ChannelProxy::Init(channel_handle, mode, create_pipe_now); |
387 // loop. However, we don't know when it exits if there's another nested | 384 StartWatching(); |
388 // message loop running under it or not, so we wouldn't know whether to | 385 } |
389 // stop or keep watching. So we always watch it, and create the event as | 386 |
390 // manual reset since the object watcher might otherwise reset the event | 387 SyncChannel::SyncChannel( |
391 // when we're doing a WaitMany. | 388 Channel::Listener* listener, |
392 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 389 base::MessageLoopProxy* ipc_message_loop, |
| 390 WaitableEvent* shutdown_event) |
| 391 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), |
| 392 sync_messages_with_no_timeout_allowed_(true) { |
| 393 StartWatching(); |
393 } | 394 } |
394 | 395 |
395 SyncChannel::~SyncChannel() { | 396 SyncChannel::~SyncChannel() { |
396 } | 397 } |
397 | 398 |
398 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { | 399 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { |
399 sync_context()->set_restrict_dispatch(value); | 400 sync_context()->set_restrict_dispatch(value); |
400 } | 401 } |
401 | 402 |
402 bool SyncChannel::Send(Message* message) { | 403 bool SyncChannel::Send(Message* message) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 508 |
508 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { | 509 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { |
509 DCHECK(event == sync_context()->GetDispatchEvent()); | 510 DCHECK(event == sync_context()->GetDispatchEvent()); |
510 // The call to DispatchMessages might delete this object, so reregister | 511 // The call to DispatchMessages might delete this object, so reregister |
511 // the object watcher first. | 512 // the object watcher first. |
512 event->Reset(); | 513 event->Reset(); |
513 dispatch_watcher_.StartWatching(event, this); | 514 dispatch_watcher_.StartWatching(event, this); |
514 sync_context()->DispatchMessages(); | 515 sync_context()->DispatchMessages(); |
515 } | 516 } |
516 | 517 |
| 518 void SyncChannel::StartWatching() { |
| 519 // Ideally we only want to watch this object when running a nested message |
| 520 // loop. However, we don't know when it exits if there's another nested |
| 521 // message loop running under it or not, so we wouldn't know whether to |
| 522 // stop or keep watching. So we always watch it, and create the event as |
| 523 // manual reset since the object watcher might otherwise reset the event |
| 524 // when we're doing a WaitMany. |
| 525 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
| 526 } |
| 527 |
517 } // namespace IPC | 528 } // namespace IPC |
OLD | NEW |