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.
5 #include "chrome_frame/sync_msg_reply_dispatcher.h"
7 #include "ipc/ipc_sync_message.h"
9 void SyncMessageReplyDispatcher::Push(IPC::SyncMessage
* msg
,
10 SyncMessageCallContext
* context
,
13 context
->message_type_
= msg
->type();
14 context
->id_
= IPC::SyncMessage::GetMessageId(*msg
);
17 base::AutoLock
lock(message_queue_lock_
);
18 message_queue_
.push_back(context
);
22 bool SyncMessageReplyDispatcher::HandleMessageType(
23 const IPC::Message
& msg
, SyncMessageCallContext
* context
) {
27 bool SyncMessageReplyDispatcher::OnMessageReceived(const IPC::Message
& msg
) {
28 SyncMessageCallContext
* context
= GetContext(msg
);
29 // No context e.g. no return values and/or don't care
34 return HandleMessageType(msg
, context
);
37 void SyncMessageReplyDispatcher::Cancel(void* key
) {
39 base::AutoLock
lock(message_queue_lock_
);
40 PendingSyncMessageQueue::iterator it
= message_queue_
.begin();
41 while (it
!= message_queue_
.end()) {
42 SyncMessageCallContext
* context
= *it
;
43 if (context
->key_
== key
) {
44 it
= message_queue_
.erase(it
);
52 SyncMessageReplyDispatcher::SyncMessageCallContext
*
53 SyncMessageReplyDispatcher::GetContext(const IPC::Message
& msg
) {
57 int id
= IPC::SyncMessage::GetMessageId(msg
);
58 base::AutoLock
lock(message_queue_lock_
);
59 PendingSyncMessageQueue::iterator it
;
60 for (it
= message_queue_
.begin(); it
!= message_queue_
.end(); ++it
) {
61 SyncMessageCallContext
* context
= *it
;
62 if (context
->id_
== id
) {
63 message_queue_
.erase(it
);