summaryrefslogtreecommitdiffstats
path: root/chrome_frame/sync_msg_reply_dispatcher.cc
diff options
context:
space:
mode:
authorslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
committerslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
commitf781782dd67077478e117c61dca4ea5eefce3544 (patch)
tree4801f724123cfdcbb69c4e7fe40a565b331723ae /chrome_frame/sync_msg_reply_dispatcher.cc
parent63cf4759efa2373e33436fb5df6849f930081226 (diff)
downloadchromium_src-f781782dd67077478e117c61dca4ea5eefce3544.zip
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.gz
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.bz2
Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming in a separate CL.
BUG=None TEST=None Review URL: http://codereview.chromium.org/218019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/sync_msg_reply_dispatcher.cc')
-rw-r--r--chrome_frame/sync_msg_reply_dispatcher.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome_frame/sync_msg_reply_dispatcher.cc b/chrome_frame/sync_msg_reply_dispatcher.cc
new file mode 100644
index 0000000..b301698
--- /dev/null
+++ b/chrome_frame/sync_msg_reply_dispatcher.cc
@@ -0,0 +1,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;
+}