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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 received_sync_msgs_->DispatchMessages(this); | 294 received_sync_msgs_->DispatchMessages(this); |
295 } | 295 } |
296 | 296 |
297 bool SyncChannel::SyncContext::TryToUnblockListener(const Message* msg) { | 297 bool SyncChannel::SyncContext::TryToUnblockListener(const Message* msg) { |
298 base::AutoLock auto_lock(deserializers_lock_); | 298 base::AutoLock auto_lock(deserializers_lock_); |
299 if (deserializers_.empty() || | 299 if (deserializers_.empty() || |
300 !SyncMessage::IsMessageReplyTo(*msg, deserializers_.back().id)) { | 300 !SyncMessage::IsMessageReplyTo(*msg, deserializers_.back().id)) { |
301 return false; | 301 return false; |
302 } | 302 } |
303 | 303 |
| 304 // TODO(bauerb): Remove logging once investigation of http://crbug.com/141055 |
| 305 // has finished. |
304 if (!msg->is_reply_error()) { | 306 if (!msg->is_reply_error()) { |
305 deserializers_.back().send_result = deserializers_.back().deserializer-> | 307 bool send_result = deserializers_.back().deserializer-> |
306 SerializeOutputParameters(*msg); | 308 SerializeOutputParameters(*msg); |
| 309 deserializers_.back().send_result = send_result; |
| 310 LOG_IF(ERROR, !send_result) << "Couldn't deserialize reply message"; |
| 311 } else { |
| 312 LOG(ERROR) << "Received error reply"; |
307 } | 313 } |
308 deserializers_.back().done_event->Signal(); | 314 deserializers_.back().done_event->Signal(); |
309 | 315 |
310 return true; | 316 return true; |
311 } | 317 } |
312 | 318 |
313 void SyncChannel::SyncContext::Clear() { | 319 void SyncChannel::SyncContext::Clear() { |
314 CancelPendingSends(); | 320 CancelPendingSends(); |
315 received_sync_msgs_->RemoveContext(this); | 321 received_sync_msgs_->RemoveContext(this); |
316 Context::Clear(); | 322 Context::Clear(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 356 |
351 void SyncChannel::SyncContext::OnChannelClosed() { | 357 void SyncChannel::SyncContext::OnChannelClosed() { |
352 CancelPendingSends(); | 358 CancelPendingSends(); |
353 shutdown_watcher_.StopWatching(); | 359 shutdown_watcher_.StopWatching(); |
354 Context::OnChannelClosed(); | 360 Context::OnChannelClosed(); |
355 } | 361 } |
356 | 362 |
357 void SyncChannel::SyncContext::OnSendTimeout(int message_id) { | 363 void SyncChannel::SyncContext::OnSendTimeout(int message_id) { |
358 base::AutoLock auto_lock(deserializers_lock_); | 364 base::AutoLock auto_lock(deserializers_lock_); |
359 PendingSyncMessageQueue::iterator iter; | 365 PendingSyncMessageQueue::iterator iter; |
| 366 LOG(ERROR) << "Send timeout"; |
360 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { | 367 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) { |
361 if (iter->id == message_id) { | 368 if (iter->id == message_id) { |
362 iter->done_event->Signal(); | 369 iter->done_event->Signal(); |
363 break; | 370 break; |
364 } | 371 } |
365 } | 372 } |
366 } | 373 } |
367 | 374 |
368 void SyncChannel::SyncContext::CancelPendingSends() { | 375 void SyncChannel::SyncContext::CancelPendingSends() { |
369 base::AutoLock auto_lock(deserializers_lock_); | 376 base::AutoLock auto_lock(deserializers_lock_); |
370 PendingSyncMessageQueue::iterator iter; | 377 PendingSyncMessageQueue::iterator iter; |
| 378 LOG(ERROR) << "Canceling pending sends"; |
371 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) | 379 for (iter = deserializers_.begin(); iter != deserializers_.end(); iter++) |
372 iter->done_event->Signal(); | 380 iter->done_event->Signal(); |
373 } | 381 } |
374 | 382 |
375 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { | 383 void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) { |
376 if (event == shutdown_event_) { | 384 if (event == shutdown_event_) { |
377 // Process shut down before we can get a reply to a synchronous message. | 385 // Process shut down before we can get a reply to a synchronous message. |
378 // Cancel pending Send calls, which will end up setting the send done event. | 386 // Cancel pending Send calls, which will end up setting the send done event. |
379 CancelPendingSends(); | 387 CancelPendingSends(); |
380 } else { | 388 } else { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 428 |
421 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { | 429 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { |
422 if (!message->is_sync()) { | 430 if (!message->is_sync()) { |
423 ChannelProxy::Send(message); | 431 ChannelProxy::Send(message); |
424 return true; | 432 return true; |
425 } | 433 } |
426 | 434 |
427 // *this* might get deleted in WaitForReply. | 435 // *this* might get deleted in WaitForReply. |
428 scoped_refptr<SyncContext> context(sync_context()); | 436 scoped_refptr<SyncContext> context(sync_context()); |
429 if (context->shutdown_event()->IsSignaled()) { | 437 if (context->shutdown_event()->IsSignaled()) { |
| 438 LOG(ERROR) << "shutdown event is signaled"; |
430 delete message; | 439 delete message; |
431 return false; | 440 return false; |
432 } | 441 } |
433 | 442 |
434 DCHECK(sync_messages_with_no_timeout_allowed_ || | 443 DCHECK(sync_messages_with_no_timeout_allowed_ || |
435 timeout_ms != base::kNoTimeout); | 444 timeout_ms != base::kNoTimeout); |
436 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); | 445 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); |
437 context->Push(sync_msg); | 446 context->Push(sync_msg); |
438 int message_id = SyncMessage::GetMessageId(*sync_msg); | 447 int message_id = SyncMessage::GetMessageId(*sync_msg); |
439 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); | 448 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // Ideally we only want to watch this object when running a nested message | 542 // Ideally we only want to watch this object when running a nested message |
534 // loop. However, we don't know when it exits if there's another nested | 543 // loop. However, we don't know when it exits if there's another nested |
535 // message loop running under it or not, so we wouldn't know whether to | 544 // message loop running under it or not, so we wouldn't know whether to |
536 // stop or keep watching. So we always watch it, and create the event as | 545 // stop or keep watching. So we always watch it, and create the event as |
537 // manual reset since the object watcher might otherwise reset the event | 546 // manual reset since the object watcher might otherwise reset the event |
538 // when we're doing a WaitMany. | 547 // when we're doing a WaitMany. |
539 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 548 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
540 } | 549 } |
541 | 550 |
542 } // namespace IPC | 551 } // namespace IPC |
OLD | NEW |