| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 10 #include "base/location.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/synchronization/waitable_event_watcher.h" | 13 #include "base/synchronization/waitable_event_watcher.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread_local.h" | 15 #include "base/threading/thread_local.h" |
| 16 #include "ipc/ipc_logging.h" |
| 17 #include "ipc/ipc_message_macros.h" |
| 15 #include "ipc/ipc_sync_message.h" | 18 #include "ipc/ipc_sync_message.h" |
| 16 | 19 |
| 17 using base::TimeDelta; | 20 using base::TimeDelta; |
| 18 using base::TimeTicks; | 21 using base::TimeTicks; |
| 19 using base::WaitableEvent; | 22 using base::WaitableEvent; |
| 20 | 23 |
| 21 namespace IPC { | 24 namespace IPC { |
| 22 // When we're blocked in a Send(), we need to process incoming synchronous | 25 // When we're blocked in a Send(), we need to process incoming synchronous |
| 23 // messages right away because it could be blocking our reply (either | 26 // messages right away because it could be blocking our reply (either |
| 24 // directly from the same object we're calling, or indirectly through one or | 27 // directly from the same object we're calling, or indirectly through one or |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 424 |
| 422 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { | 425 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { |
| 423 sync_context()->set_restrict_dispatch_group(group); | 426 sync_context()->set_restrict_dispatch_group(group); |
| 424 } | 427 } |
| 425 | 428 |
| 426 bool SyncChannel::Send(Message* message) { | 429 bool SyncChannel::Send(Message* message) { |
| 427 return SendWithTimeout(message, base::kNoTimeout); | 430 return SendWithTimeout(message, base::kNoTimeout); |
| 428 } | 431 } |
| 429 | 432 |
| 430 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { | 433 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { |
| 434 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 435 Logging* logger = Logging::GetInstance(); |
| 436 std::string name; |
| 437 logger->GetMessageText(message->type(), &name, message, NULL); |
| 438 TRACE_EVENT1("task", "SyncChannel::SendWithTimeout", |
| 439 "name", name); |
| 440 #else |
| 441 TRACE_EVENT2("task", "SyncChannel::SendWithTimeout", |
| 442 "class", IPC_MESSAGE_ID_CLASS(message->type()), |
| 443 "line", IPC_MESSAGE_ID_LINE(message->type())); |
| 444 #endif |
| 431 if (!message->is_sync()) { | 445 if (!message->is_sync()) { |
| 432 ChannelProxy::Send(message); | 446 ChannelProxy::Send(message); |
| 433 return true; | 447 return true; |
| 434 } | 448 } |
| 435 | 449 |
| 436 // *this* might get deleted in WaitForReply. | 450 // *this* might get deleted in WaitForReply. |
| 437 scoped_refptr<SyncContext> context(sync_context()); | 451 scoped_refptr<SyncContext> context(sync_context()); |
| 438 if (context->shutdown_event()->IsSignaled()) { | 452 if (context->shutdown_event()->IsSignaled()) { |
| 439 VLOG(1) << "shutdown event is signaled"; | 453 VLOG(1) << "shutdown event is signaled"; |
| 440 delete message; | 454 delete message; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 // Ideally we only want to watch this object when running a nested message | 557 // Ideally we only want to watch this object when running a nested message |
| 544 // loop. However, we don't know when it exits if there's another nested | 558 // loop. However, we don't know when it exits if there's another nested |
| 545 // message loop running under it or not, so we wouldn't know whether to | 559 // message loop running under it or not, so we wouldn't know whether to |
| 546 // stop or keep watching. So we always watch it, and create the event as | 560 // stop or keep watching. So we always watch it, and create the event as |
| 547 // manual reset since the object watcher might otherwise reset the event | 561 // manual reset since the object watcher might otherwise reset the event |
| 548 // when we're doing a WaitMany. | 562 // when we're doing a WaitMany. |
| 549 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 563 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
| 550 } | 564 } |
| 551 | 565 |
| 552 } // namespace IPC | 566 } // namespace IPC |
| OLD | NEW |