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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 310 } |
311 | 311 |
312 if (!msg->is_reply_error()) { | 312 if (!msg->is_reply_error()) { |
313 bool send_result = deserializers_.back().deserializer-> | 313 bool send_result = deserializers_.back().deserializer-> |
314 SerializeOutputParameters(*msg); | 314 SerializeOutputParameters(*msg); |
315 deserializers_.back().send_result = send_result; | 315 deserializers_.back().send_result = send_result; |
316 DVLOG_IF(1, !send_result) << "Couldn't deserialize reply message"; | 316 DVLOG_IF(1, !send_result) << "Couldn't deserialize reply message"; |
317 } else { | 317 } else { |
318 DVLOG(1) << "Received error reply"; | 318 DVLOG(1) << "Received error reply"; |
319 } | 319 } |
320 deserializers_.back().done_event->Signal(); | 320 |
| 321 base::WaitableEvent* done_event = deserializers_.back().done_event; |
| 322 TRACE_EVENT_FLOW_BEGIN0( |
| 323 TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
| 324 "SyncChannel::SyncContext::TryToUnblockListener", done_event); |
| 325 |
| 326 done_event->Signal(); |
321 | 327 |
322 return true; | 328 return true; |
323 } | 329 } |
324 | 330 |
325 void SyncChannel::SyncContext::Clear() { | 331 void SyncChannel::SyncContext::Clear() { |
326 CancelPendingSends(); | 332 CancelPendingSends(); |
327 received_sync_msgs_->RemoveContext(this); | 333 received_sync_msgs_->RemoveContext(this); |
328 Context::Clear(); | 334 Context::Clear(); |
329 } | 335 } |
330 | 336 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 base::Unretained(this))); | 368 base::Unretained(this))); |
363 Context::OnChannelOpened(); | 369 Context::OnChannelOpened(); |
364 } | 370 } |
365 | 371 |
366 void SyncChannel::SyncContext::OnChannelClosed() { | 372 void SyncChannel::SyncContext::OnChannelClosed() { |
367 CancelPendingSends(); | 373 CancelPendingSends(); |
368 shutdown_watcher_.StopWatching(); | 374 shutdown_watcher_.StopWatching(); |
369 Context::OnChannelClosed(); | 375 Context::OnChannelClosed(); |
370 } | 376 } |
371 | 377 |
372 void SyncChannel::SyncContext::OnSendTimeout(int message_id) { | |
373 base::AutoLock auto_lock(deserializers_lock_); | |
374 PendingSyncMessageQueue::iterator iter; | |
375 DVLOG(1) << "Send timeout"; | |
376 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { | |
377 if (iter->id == message_id) { | |
378 iter->done_event->Signal(); | |
379 break; | |
380 } | |
381 } | |
382 } | |
383 | |
384 void SyncChannel::SyncContext::CancelPendingSends() { | 378 void SyncChannel::SyncContext::CancelPendingSends() { |
385 base::AutoLock auto_lock(deserializers_lock_); | 379 base::AutoLock auto_lock(deserializers_lock_); |
386 PendingSyncMessageQueue::iterator iter; | 380 PendingSyncMessageQueue::iterator iter; |
387 DVLOG(1) << "Canceling pending sends"; | 381 DVLOG(1) << "Canceling pending sends"; |
388 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) | 382 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { |
| 383 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
| 384 "SyncChannel::SyncContext::CancelPendingSends", |
| 385 iter->done_event); |
389 iter->done_event->Signal(); | 386 iter->done_event->Signal(); |
| 387 } |
390 } | 388 } |
391 | 389 |
392 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { | 390 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { |
393 if (event == shutdown_event_) { | 391 if (event == shutdown_event_) { |
394 // Process shut down before we can get a reply to a synchronous message. | 392 // Process shut down before we can get a reply to a synchronous message. |
395 // Cancel pending Send calls, which will end up setting the send done event. | 393 // Cancel pending Send calls, which will end up setting the send done event. |
396 CancelPendingSends(); | 394 CancelPendingSends(); |
397 } else { | 395 } else { |
398 // We got the reply, timed out or the process shutdown. | 396 // We got the reply, timed out or the process shutdown. |
399 DCHECK_EQ(GetSendDoneEvent(), event); | 397 DCHECK_EQ(GetSendDoneEvent(), event); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); | 494 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); |
497 context->Push(sync_msg); | 495 context->Push(sync_msg); |
498 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); | 496 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); |
499 | 497 |
500 ChannelProxy::Send(message); | 498 ChannelProxy::Send(message); |
501 | 499 |
502 // Wait for reply, or for any other incoming synchronous messages. | 500 // Wait for reply, or for any other incoming synchronous messages. |
503 // *this* might get deleted, so only call static functions at this point. | 501 // *this* might get deleted, so only call static functions at this point. |
504 WaitForReply(context.get(), pump_messages_event); | 502 WaitForReply(context.get(), pump_messages_event); |
505 | 503 |
| 504 TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
| 505 "SyncChannel::Send", context->GetSendDoneEvent()); |
| 506 |
506 return context->Pop(); | 507 return context->Pop(); |
507 } | 508 } |
508 | 509 |
509 void SyncChannel::WaitForReply( | 510 void SyncChannel::WaitForReply( |
510 SyncContext* context, WaitableEvent* pump_messages_event) { | 511 SyncContext* context, WaitableEvent* pump_messages_event) { |
511 context->DispatchMessages(); | 512 context->DispatchMessages(); |
512 while (true) { | 513 while (true) { |
513 WaitableEvent* objects[] = { | 514 WaitableEvent* objects[] = { |
514 context->GetDispatchEvent(), | 515 context->GetDispatchEvent(), |
515 context->GetSendDoneEvent(), | 516 context->GetSendDoneEvent(), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 597 |
597 void SyncChannel::OnChannelInit() { | 598 void SyncChannel::OnChannelInit() { |
598 for (const auto& filter : pre_init_sync_message_filters_) { | 599 for (const auto& filter : pre_init_sync_message_filters_) { |
599 filter->set_is_channel_send_thread_safe( | 600 filter->set_is_channel_send_thread_safe( |
600 context()->IsChannelSendThreadSafe()); | 601 context()->IsChannelSendThreadSafe()); |
601 } | 602 } |
602 pre_init_sync_message_filters_.clear(); | 603 pre_init_sync_message_filters_.clear(); |
603 } | 604 } |
604 | 605 |
605 } // namespace IPC | 606 } // namespace IPC |
OLD | NEW |