OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 const IPC::ChannelHandle& channel_handle, | 371 const IPC::ChannelHandle& channel_handle, |
372 Channel::Mode mode, | 372 Channel::Mode mode, |
373 Channel::Listener* listener, | 373 Channel::Listener* listener, |
374 MessageLoop* ipc_message_loop, | 374 MessageLoop* ipc_message_loop, |
375 bool create_pipe_now, | 375 bool create_pipe_now, |
376 WaitableEvent* shutdown_event) | 376 WaitableEvent* shutdown_event) |
377 : ChannelProxy( | 377 : ChannelProxy( |
378 channel_handle, mode, ipc_message_loop, | 378 channel_handle, mode, ipc_message_loop, |
379 new SyncContext(listener, ipc_message_loop, shutdown_event), | 379 new SyncContext(listener, ipc_message_loop, shutdown_event), |
380 create_pipe_now), | 380 create_pipe_now), |
381 sync_messages_with_no_timeout_allowed_(true) { | 381 sync_messages_with_no_timeout_allowed_(true), |
| 382 outgoing_message_filter_(NULL) { |
382 // Ideally we only want to watch this object when running a nested message | 383 // Ideally we only want to watch this object when running a nested message |
383 // loop. However, we don't know when it exits if there's another nested | 384 // loop. However, we don't know when it exits if there's another nested |
384 // message loop running under it or not, so we wouldn't know whether to | 385 // message loop running under it or not, so we wouldn't know whether to |
385 // stop or keep watching. So we always watch it, and create the event as | 386 // stop or keep watching. So we always watch it, and create the event as |
386 // manual reset since the object watcher might otherwise reset the event | 387 // manual reset since the object watcher might otherwise reset the event |
387 // when we're doing a WaitMany. | 388 // when we're doing a WaitMany. |
388 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); | 389 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); |
389 } | 390 } |
390 | 391 |
391 SyncChannel::~SyncChannel() { | 392 SyncChannel::~SyncChannel() { |
392 } | 393 } |
393 | 394 |
394 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { | 395 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { |
395 sync_context()->set_restrict_dispatch(value); | 396 sync_context()->set_restrict_dispatch(value); |
396 } | 397 } |
397 | 398 |
398 bool SyncChannel::Send(Message* message) { | 399 bool SyncChannel::Send(Message* message) { |
399 return SendWithTimeout(message, base::kNoTimeout); | 400 return SendWithTimeout(message, base::kNoTimeout); |
400 } | 401 } |
401 | 402 |
402 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { | 403 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { |
| 404 if (outgoing_message_filter_) |
| 405 message = outgoing_message_filter_->Rewrite(message); |
| 406 |
403 if (!message->is_sync()) { | 407 if (!message->is_sync()) { |
404 ChannelProxy::Send(message); | 408 ChannelProxy::Send(message); |
405 return true; | 409 return true; |
406 } | 410 } |
407 | 411 |
408 // *this* might get deleted in WaitForReply. | 412 // *this* might get deleted in WaitForReply. |
409 scoped_refptr<SyncContext> context(sync_context()); | 413 scoped_refptr<SyncContext> context(sync_context()); |
410 if (context->shutdown_event()->IsSignaled()) { | 414 if (context->shutdown_event()->IsSignaled()) { |
411 delete message; | 415 delete message; |
412 return false; | 416 return false; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { | 507 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { |
504 DCHECK(event == sync_context()->GetDispatchEvent()); | 508 DCHECK(event == sync_context()->GetDispatchEvent()); |
505 // The call to DispatchMessages might delete this object, so reregister | 509 // The call to DispatchMessages might delete this object, so reregister |
506 // the object watcher first. | 510 // the object watcher first. |
507 event->Reset(); | 511 event->Reset(); |
508 dispatch_watcher_.StartWatching(event, this); | 512 dispatch_watcher_.StartWatching(event, this); |
509 sync_context()->DispatchMessages(); | 513 sync_context()->DispatchMessages(); |
510 } | 514 } |
511 | 515 |
512 } // namespace IPC | 516 } // namespace IPC |
OLD | NEW |