Simple Cache: a few tests for rare corner cases with CRC check missing.
[chromium-blink-merge.git] / chrome_frame / sync_msg_reply_dispatcher.cc
blobe2f197472d401707d3a1eefb9cc5ff9e0e39da6d
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,
11 void* key) {
12 if (context) {
13 context->message_type_ = msg->type();
14 context->id_ = IPC::SyncMessage::GetMessageId(*msg);
15 context->key_ = key;
17 base::AutoLock lock(message_queue_lock_);
18 message_queue_.push_back(context);
22 bool SyncMessageReplyDispatcher::HandleMessageType(
23 const IPC::Message& msg, SyncMessageCallContext* context) {
24 return false;
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
30 if (!context) {
31 return false;
34 return HandleMessageType(msg, context);
37 void SyncMessageReplyDispatcher::Cancel(void* key) {
38 DCHECK(key != NULL);
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);
45 delete context;
46 } else {
47 ++it;
52 SyncMessageReplyDispatcher::SyncMessageCallContext*
53 SyncMessageReplyDispatcher::GetContext(const IPC::Message& msg) {
54 if (!msg.is_reply())
55 return NULL;
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);
64 return context;
67 return NULL;