Chromium Code Reviews| 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/stack_trace.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" |
| 15 #include "ipc/ipc_sync_message.h" | 16 #include "ipc/ipc_sync_message.h" |
| 16 | 17 |
| 17 using base::TimeDelta; | 18 using base::TimeDelta; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 !SyncMessage::IsMessageReplyTo(*msg, deserializers_.back().id)) { | 301 !SyncMessage::IsMessageReplyTo(*msg, deserializers_.back().id)) { |
| 301 return false; | 302 return false; |
| 302 } | 303 } |
| 303 | 304 |
| 304 // TODO(bauerb): Remove logging once investigation of http://crbug.com/141055 | 305 // TODO(bauerb): Remove logging once investigation of http://crbug.com/141055 |
| 305 // has finished. | 306 // has finished. |
| 306 if (!msg->is_reply_error()) { | 307 if (!msg->is_reply_error()) { |
| 307 bool send_result = deserializers_.back().deserializer-> | 308 bool send_result = deserializers_.back().deserializer-> |
| 308 SerializeOutputParameters(*msg); | 309 SerializeOutputParameters(*msg); |
| 309 deserializers_.back().send_result = send_result; | 310 deserializers_.back().send_result = send_result; |
| 310 LOG_IF(ERROR, !send_result) << "Couldn't deserialize reply message"; | 311 VLOG_IF(1, !send_result) << "Couldn't deserialize reply message"; |
| 311 } else { | 312 } else { |
| 312 LOG(ERROR) << "Received error reply"; | 313 VLOG(1) << "Received error reply"; |
| 313 } | 314 } |
| 314 deserializers_.back().done_event->Signal(); | 315 deserializers_.back().done_event->Signal(); |
| 315 | 316 |
| 316 return true; | 317 return true; |
| 317 } | 318 } |
| 318 | 319 |
| 319 void SyncChannel::SyncContext::Clear() { | 320 void SyncChannel::SyncContext::Clear() { |
| 320 CancelPendingSends(); | 321 CancelPendingSends(); |
| 321 received_sync_msgs_->RemoveContext(this); | 322 received_sync_msgs_->RemoveContext(this); |
| 322 Context::Clear(); | 323 Context::Clear(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 | 357 |
| 357 void SyncChannel::SyncContext::OnChannelClosed() { | 358 void SyncChannel::SyncContext::OnChannelClosed() { |
| 358 CancelPendingSends(); | 359 CancelPendingSends(); |
| 359 shutdown_watcher_.StopWatching(); | 360 shutdown_watcher_.StopWatching(); |
| 360 Context::OnChannelClosed(); | 361 Context::OnChannelClosed(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 void SyncChannel::SyncContext::OnSendTimeout(int message_id) { | 364 void SyncChannel::SyncContext::OnSendTimeout(int message_id) { |
| 364 base::AutoLock auto_lock(deserializers_lock_); | 365 base::AutoLock auto_lock(deserializers_lock_); |
| 365 PendingSyncMessageQueue::iterator iter; | 366 PendingSyncMessageQueue::iterator iter; |
| 366 LOG(ERROR) << "Send timeout"; | 367 VLOG(1) << "Send timeout"; |
| 367 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { | 368 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { |
| 368 if (iter->id == message_id) { | 369 if (iter->id == message_id) { |
| 369 iter->done_event->Signal(); | 370 iter->done_event->Signal(); |
| 370 break; | 371 break; |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 void SyncChannel::SyncContext::CancelPendingSends() { | 376 void SyncChannel::SyncContext::CancelPendingSends() { |
| 376 base::AutoLock auto_lock(deserializers_lock_); | 377 base::AutoLock auto_lock(deserializers_lock_); |
| 377 PendingSyncMessageQueue::iterator iter; | 378 PendingSyncMessageQueue::iterator iter; |
| 378 LOG(ERROR) << "Canceling pending sends"; | 379 #if !defined(OS_ANDROID) && !defined(OS_NACL) |
|
piman
2012/08/16 17:57:10
Can you add a reference to that bug here too?
Bernhard Bauer
2012/08/16 19:14:18
Done.
| |
| 380 if (VLOG_IS_ON(1)) { | |
| 381 VLOG(1) << "Canceling pending sends"; | |
| 382 base::debug::StackTrace trace; | |
| 383 trace.PrintBacktrace(); | |
| 384 } | |
| 385 #endif | |
| 379 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) | 386 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) |
| 380 iter->done_event->Signal(); | 387 iter->done_event->Signal(); |
| 381 } | 388 } |
| 382 | 389 |
| 383 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { | 390 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { |
| 384 if (event == shutdown_event_) { | 391 if (event == shutdown_event_) { |
| 385 // 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. |
| 386 // 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. |
| 387 CancelPendingSends(); | 394 CancelPendingSends(); |
| 388 } else { | 395 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 | 435 |
| 429 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { | 436 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { |
| 430 if (!message->is_sync()) { | 437 if (!message->is_sync()) { |
| 431 ChannelProxy::Send(message); | 438 ChannelProxy::Send(message); |
| 432 return true; | 439 return true; |
| 433 } | 440 } |
| 434 | 441 |
| 435 // *this* might get deleted in WaitForReply. | 442 // *this* might get deleted in WaitForReply. |
| 436 scoped_refptr<SyncContext> context(sync_context()); | 443 scoped_refptr<SyncContext> context(sync_context()); |
| 437 if (context->shutdown_event()->IsSignaled()) { | 444 if (context->shutdown_event()->IsSignaled()) { |
| 438 LOG(ERROR) << "shutdown event is signaled"; | 445 VLOG(1) << "shutdown event is signaled"; |
| 439 delete message; | 446 delete message; |
| 440 return false; | 447 return false; |
| 441 } | 448 } |
| 442 | 449 |
| 443 DCHECK(sync_messages_with_no_timeout_allowed_ || | 450 DCHECK(sync_messages_with_no_timeout_allowed_ || |
| 444 timeout_ms != base::kNoTimeout); | 451 timeout_ms != base::kNoTimeout); |
| 445 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); | 452 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); |
| 446 context->Push(sync_msg); | 453 context->Push(sync_msg); |
| 447 int message_id = SyncMessage::GetMessageId(*sync_msg); | 454 int message_id = SyncMessage::GetMessageId(*sync_msg); |
| 448 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); | 455 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 // Ideally we only want to watch this object when running a nested message | 549 // Ideally we only want to watch this object when running a nested message |
| 543 // loop. However, we don't know when it exits if there's another nested | 550 // loop. However, we don't know when it exits if there's another nested |
| 544 // message loop running under it or not, so we wouldn't know whether to | 551 // message loop running under it or not, so we wouldn't know whether to |
| 545 // stop or keep watching. So we always watch it, and create the event as | 552 // stop or keep watching. So we always watch it, and create the event as |
| 546 // manual reset since the object watcher might otherwise reset the event | 553 // manual reset since the object watcher might otherwise reset the event |
| 547 // when we're doing a WaitMany. | 554 // when we're doing a WaitMany. |
| 548 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 555 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
| 549 } | 556 } |
| 550 | 557 |
| 551 } // namespace IPC | 558 } // namespace IPC |
| OLD | NEW |