| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/thread_local.h" | 9 #include "base/thread_local.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // a local global stack of send done watchers to ensure that nested sync | 193 // a local global stack of send done watchers to ensure that nested sync |
| 194 // message loops complete correctly. | 194 // message loops complete correctly. |
| 195 base::WaitableEventWatcher* top_send_done_watcher_; | 195 base::WaitableEventWatcher* top_send_done_watcher_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 base::LazyInstance<base::ThreadLocalPointer<SyncChannel::ReceivedSyncMsgQueue> > | 198 base::LazyInstance<base::ThreadLocalPointer<SyncChannel::ReceivedSyncMsgQueue> > |
| 199 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_(base::LINKER_INITIALIZED); | 199 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_(base::LINKER_INITIALIZED); |
| 200 | 200 |
| 201 SyncChannel::SyncContext::SyncContext( | 201 SyncChannel::SyncContext::SyncContext( |
| 202 Channel::Listener* listener, | 202 Channel::Listener* listener, |
| 203 MessageFilter* filter, | |
| 204 MessageLoop* ipc_thread, | 203 MessageLoop* ipc_thread, |
| 205 WaitableEvent* shutdown_event) | 204 WaitableEvent* shutdown_event) |
| 206 : ChannelProxy::Context(listener, filter, ipc_thread), | 205 : ChannelProxy::Context(listener, ipc_thread), |
| 207 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()), | 206 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()), |
| 208 shutdown_event_(shutdown_event) { | 207 shutdown_event_(shutdown_event) { |
| 209 } | 208 } |
| 210 | 209 |
| 211 SyncChannel::SyncContext::~SyncContext() { | 210 SyncChannel::SyncContext::~SyncContext() { |
| 212 while (!deserializers_.empty()) | 211 while (!deserializers_.empty()) |
| 213 Pop(); | 212 Pop(); |
| 214 } | 213 } |
| 215 | 214 |
| 216 // Adds information about an outgoing sync message to the context so that | 215 // Adds information about an outgoing sync message to the context so that |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 CancelPendingSends(); | 348 CancelPendingSends(); |
| 350 } else { | 349 } else { |
| 351 // We got the reply, timed out or the process shutdown. | 350 // We got the reply, timed out or the process shutdown. |
| 352 DCHECK(event == GetSendDoneEvent()); | 351 DCHECK(event == GetSendDoneEvent()); |
| 353 MessageLoop::current()->QuitNow(); | 352 MessageLoop::current()->QuitNow(); |
| 354 } | 353 } |
| 355 } | 354 } |
| 356 | 355 |
| 357 | 356 |
| 358 SyncChannel::SyncChannel( | 357 SyncChannel::SyncChannel( |
| 359 const std::string& channel_id, Channel::Mode mode, | 358 const std::string& channel_id, |
| 360 Channel::Listener* listener, MessageFilter* filter, | 359 Channel::Mode mode, |
| 361 MessageLoop* ipc_message_loop, bool create_pipe_now, | 360 Channel::Listener* listener, |
| 361 MessageLoop* ipc_message_loop, |
| 362 bool create_pipe_now, |
| 362 WaitableEvent* shutdown_event) | 363 WaitableEvent* shutdown_event) |
| 363 : ChannelProxy( | 364 : ChannelProxy( |
| 364 channel_id, mode, ipc_message_loop, | 365 channel_id, mode, ipc_message_loop, |
| 365 new SyncContext(listener, filter, ipc_message_loop, shutdown_event), | 366 new SyncContext(listener, ipc_message_loop, shutdown_event), |
| 366 create_pipe_now), | 367 create_pipe_now), |
| 367 sync_messages_with_no_timeout_allowed_(true) { | 368 sync_messages_with_no_timeout_allowed_(true) { |
| 368 // Ideally we only want to watch this object when running a nested message | 369 // Ideally we only want to watch this object when running a nested message |
| 369 // loop. However, we don't know when it exits if there's another nested | 370 // loop. However, we don't know when it exits if there's another nested |
| 370 // message loop running under it or not, so we wouldn't know whether to | 371 // message loop running under it or not, so we wouldn't know whether to |
| 371 // stop or keep watching. So we always watch it, and create the event as | 372 // stop or keep watching. So we always watch it, and create the event as |
| 372 // manual reset since the object watcher might otherwise reset the event | 373 // manual reset since the object watcher might otherwise reset the event |
| 373 // when we're doing a WaitMany. | 374 // when we're doing a WaitMany. |
| 374 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 375 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
| 375 } | 376 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { | 485 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { |
| 485 DCHECK(event == sync_context()->GetDispatchEvent()); | 486 DCHECK(event == sync_context()->GetDispatchEvent()); |
| 486 // The call to DispatchMessages might delete this object, so reregister | 487 // The call to DispatchMessages might delete this object, so reregister |
| 487 // the object watcher first. | 488 // the object watcher first. |
| 488 event->Reset(); | 489 event->Reset(); |
| 489 dispatch_watcher_.StartWatching(event, this); | 490 dispatch_watcher_.StartWatching(event, this); |
| 490 sync_context()->DispatchMessages(); | 491 sync_context()->DispatchMessages(); |
| 491 } | 492 } |
| 492 | 493 |
| 493 } // namespace IPC | 494 } // namespace IPC |
| OLD | NEW |