Chromium Code Reviews| 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/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 } | 369 } |
| 370 | 370 |
| 371 | 371 |
| 372 SyncChannel::SyncChannel( | 372 SyncChannel::SyncChannel( |
| 373 const IPC::ChannelHandle& channel_handle, | 373 const IPC::ChannelHandle& channel_handle, |
| 374 Channel::Mode mode, | 374 Channel::Mode mode, |
| 375 Channel::Listener* listener, | 375 Channel::Listener* listener, |
| 376 base::MessageLoopProxy* ipc_message_loop, | 376 base::MessageLoopProxy* ipc_message_loop, |
| 377 bool create_pipe_now, | 377 bool create_pipe_now, |
| 378 WaitableEvent* shutdown_event) | 378 WaitableEvent* shutdown_event) |
| 379 : ChannelProxy( | 379 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), |
| 380 channel_handle, mode, ipc_message_loop, | 380 sync_messages_with_no_timeout_allowed_(true) { |
| 381 new SyncContext(listener, ipc_message_loop, shutdown_event), | 381 Init(channel_handle, mode, create_pipe_now); |
| 382 create_pipe_now), | 382 // Ideally we only want to watch this object when running a nested message |
| 383 // loop. However, we don't know when it exits if there's another nested | |
| 384 // message loop running under it or not, so we wouldn't know whether to | |
|
dmac
2011/11/04 22:30:44
would be nice to get rid of this duplicated code b
kkania
2011/11/07 20:25:16
Done.
| |
| 385 // stop or keep watching. So we always watch it, and create the event as | |
| 386 // manual reset since the object watcher might otherwise reset the event | |
| 387 // when we're doing a WaitMany. | |
| 388 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | |
| 389 } | |
| 390 | |
| 391 SyncChannel::SyncChannel( | |
| 392 Channel::Listener* listener, | |
| 393 base::MessageLoopProxy* ipc_message_loop, | |
| 394 WaitableEvent* shutdown_event) | |
| 395 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), | |
| 383 sync_messages_with_no_timeout_allowed_(true) { | 396 sync_messages_with_no_timeout_allowed_(true) { |
| 384 // Ideally we only want to watch this object when running a nested message | 397 // Ideally we only want to watch this object when running a nested message |
| 385 // loop. However, we don't know when it exits if there's another nested | 398 // loop. However, we don't know when it exits if there's another nested |
| 386 // message loop running under it or not, so we wouldn't know whether to | 399 // message loop running under it or not, so we wouldn't know whether to |
| 387 // stop or keep watching. So we always watch it, and create the event as | 400 // stop or keep watching. So we always watch it, and create the event as |
| 388 // manual reset since the object watcher might otherwise reset the event | 401 // manual reset since the object watcher might otherwise reset the event |
| 389 // when we're doing a WaitMany. | 402 // when we're doing a WaitMany. |
| 390 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 403 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
| 391 } | 404 } |
| 392 | 405 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { | 518 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { |
| 506 DCHECK(event == sync_context()->GetDispatchEvent()); | 519 DCHECK(event == sync_context()->GetDispatchEvent()); |
| 507 // The call to DispatchMessages might delete this object, so reregister | 520 // The call to DispatchMessages might delete this object, so reregister |
| 508 // the object watcher first. | 521 // the object watcher first. |
| 509 event->Reset(); | 522 event->Reset(); |
| 510 dispatch_watcher_.StartWatching(event, this); | 523 dispatch_watcher_.StartWatching(event, this); |
| 511 sync_context()->DispatchMessages(); | 524 sync_context()->DispatchMessages(); |
| 512 } | 525 } |
| 513 | 526 |
| 514 } // namespace IPC | 527 } // namespace IPC |
| OLD | NEW |