summaryrefslogtreecommitdiffstats
path: root/chrome/common/webmessageportchannel_impl.h
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 02:00:56 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 02:00:56 +0000
commita5da6d613f41ecf35c027e8744dd6d3a41e4010c (patch)
treedad6a3e159fcc21df62180f481a0024db97d5b0d /chrome/common/webmessageportchannel_impl.h
parente23ed5427d0892d07480781f45b4367adebc0c00 (diff)
downloadchromium_src-a5da6d613f41ecf35c027e8744dd6d3a41e4010c.zip
chromium_src-a5da6d613f41ecf35c027e8744dd6d3a41e4010c.tar.gz
chromium_src-a5da6d613f41ecf35c027e8744dd6d3a41e4010c.tar.bz2
Cross-process Message Port implementation.
I'm sending this first, then I'll add support to workers in another changelist to avoid making this change larger. TEST=running message port related layout tests in ui_tests Review URL: http://codereview.chromium.org/159372 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22356 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/webmessageportchannel_impl.h')
-rw-r--r--chrome/common/webmessageportchannel_impl.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/chrome/common/webmessageportchannel_impl.h b/chrome/common/webmessageportchannel_impl.h
new file mode 100644
index 0000000..ee26e66
--- /dev/null
+++ b/chrome/common/webmessageportchannel_impl.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef CHROME_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
+#define CHROME_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
+
+#include <queue>
+
+#include "base/basictypes.h"
+#include "base/lock.h"
+#include "base/string16.h"
+#include "base/ref_counted.h"
+#include "ipc/ipc_channel.h"
+#include "webkit/api/public/WebMessagePortChannel.h"
+
+// This is thread safe.
+class WebMessagePortChannelImpl
+ : public WebKit::WebMessagePortChannel,
+ public IPC::Channel::Listener,
+ public base::RefCountedThreadSafe<WebMessagePortChannelImpl> {
+ public:
+ WebMessagePortChannelImpl();
+ WebMessagePortChannelImpl(int route_id, int message_port_id);
+
+ // Queues received and incoming messages until there are no more in-flight
+ // messages, then sends all of them to the browser process.
+ void QueueMessages();
+ int message_port_id() const { return message_port_id_; }
+
+ private:
+ friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>;
+ ~WebMessagePortChannelImpl();
+
+ // WebMessagePortChannel implementation.
+ virtual void setClient(WebKit::WebMessagePortChannelClient* client);
+ virtual void destroy();
+ virtual void entangle(WebKit::WebMessagePortChannel* channel);
+ virtual void postMessage(const WebKit::WebString& message,
+ WebKit::WebMessagePortChannel* channel);
+ virtual bool tryGetMessage(WebKit::WebString* message,
+ WebKit::WebMessagePortChannel** channel);
+
+ void Init();
+ void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel);
+ void Send(IPC::Message* message);
+
+ // IPC::Channel::Listener implementation.
+ virtual void OnMessageReceived(const IPC::Message& message);
+
+ void OnMessage(const string16& message,
+ int sent_message_port_id,
+ int new_routing_id);
+ void OnMessagedQueued();
+
+ struct Message {
+ string16 message;
+ scoped_refptr<WebMessagePortChannelImpl> port;
+ };
+
+ typedef std::queue<Message> MessageQueue;
+ MessageQueue message_queue_;
+
+ WebKit::WebMessagePortChannelClient* client_;
+ Lock lock_; // Locks access to above.
+
+ int route_id_; // The routing id for this object.
+ int message_port_id_; // A globally unique identifier for this message port.
+
+ DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl);
+};
+
+#endif // CHROME_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_