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