Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/common/webmessageportchannel_impl.h

Issue 16328003: Move a bunch of child-only code from content/common to content/child (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #ifndef CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
6 #define CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
7
8 #include <queue>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/string16.h"
14 #include "base/synchronization/lock.h"
15 #include "ipc/ipc_listener.h"
16 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
17
18 namespace content {
19
20 // This is thread safe.
21 class WebMessagePortChannelImpl
22 : public WebKit::WebMessagePortChannel,
23 public IPC::Listener,
24 public base::RefCountedThreadSafe<WebMessagePortChannelImpl> {
25 public:
26 WebMessagePortChannelImpl();
27 WebMessagePortChannelImpl(int route_id, int message_port_id);
28
29 // Queues received and incoming messages until there are no more in-flight
30 // messages, then sends all of them to the browser process.
31 void QueueMessages();
32 int message_port_id() const { return message_port_id_; }
33
34 private:
35 friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>;
36 virtual ~WebMessagePortChannelImpl();
37
38 // WebMessagePortChannel implementation.
39 virtual void setClient(WebKit::WebMessagePortChannelClient* client);
40 virtual void destroy();
41 virtual void entangle(WebKit::WebMessagePortChannel* channel);
42 virtual void postMessage(const WebKit::WebString& message,
43 WebKit::WebMessagePortChannelArray* channels);
44 virtual bool tryGetMessage(WebKit::WebString* message,
45 WebKit::WebMessagePortChannelArray& channels);
46
47 void Init();
48 void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel);
49 void Send(IPC::Message* message);
50
51 // IPC::Listener implementation.
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
53
54 void OnMessage(const string16& message,
55 const std::vector<int>& sent_message_port_ids,
56 const std::vector<int>& new_routing_ids);
57 void OnMessagedQueued();
58
59 struct Message {
60 Message();
61 ~Message();
62
63 string16 message;
64 std::vector<WebMessagePortChannelImpl*> ports;
65 };
66
67 typedef std::queue<Message> MessageQueue;
68 MessageQueue message_queue_;
69
70 WebKit::WebMessagePortChannelClient* client_;
71 base::Lock lock_; // Locks access to above.
72
73 int route_id_; // The routing id for this object.
74 int message_port_id_; // A globally unique identifier for this message port.
75
76 DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl);
77 };
78
79 } // namespace content
80
81 #endif // CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
OLDNEW
« no previous file with comments | « content/common/webkitplatformsupport_impl.cc ('k') | content/common/webmessageportchannel_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698