OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome_frame/sync_msg_reply_dispatcher.h" |
| 6 |
| 7 #include "ipc/ipc_sync_message.h" |
| 8 |
| 9 void SyncMessageReplyDispatcher::Push(IPC::SyncMessage* msg, void* callback, |
| 10 void* key) { |
| 11 MessageSent pending(IPC::SyncMessage::GetMessageId(*msg), |
| 12 msg->type(), callback, key); |
| 13 AutoLock lock(message_queue_lock_); |
| 14 message_queue_.push_back(pending); |
| 15 } |
| 16 |
| 17 bool SyncMessageReplyDispatcher::HandleMessageType(const IPC::Message& msg, |
| 18 const MessageSent& origin) { |
| 19 return false; |
| 20 } |
| 21 |
| 22 bool SyncMessageReplyDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 23 MessageSent origin; |
| 24 if (!Pop(msg, &origin)) { |
| 25 return false; |
| 26 } |
| 27 |
| 28 // No callback e.g. no return values and/or don't care |
| 29 if (origin.callback == NULL) |
| 30 return true; |
| 31 |
| 32 return HandleMessageType(msg, origin); |
| 33 } |
| 34 |
| 35 void SyncMessageReplyDispatcher::Cancel(void* key) { |
| 36 DCHECK(key != NULL); |
| 37 AutoLock lock(message_queue_lock_); |
| 38 PendingSyncMessageQueue::iterator it; |
| 39 for (it = message_queue_.begin(); it != message_queue_.end(); ++it) { |
| 40 if (it->key == key) { |
| 41 it->key = NULL; |
| 42 } |
| 43 } |
| 44 } |
| 45 |
| 46 bool SyncMessageReplyDispatcher::Pop(const IPC::Message& msg, MessageSent* t) { |
| 47 if (!msg.is_reply()) |
| 48 return false; |
| 49 |
| 50 int id = IPC::SyncMessage::GetMessageId(msg); |
| 51 AutoLock lock(message_queue_lock_); |
| 52 PendingSyncMessageQueue::iterator it; |
| 53 for (it = message_queue_.begin(); it != message_queue_.end(); ++it) { |
| 54 if (it->id == id) { |
| 55 *t = *it; |
| 56 message_queue_.erase(it); |
| 57 return true; |
| 58 } |
| 59 } |
| 60 return false; |
| 61 } |
OLD | NEW |