OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ | 5 #ifndef CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ |
6 #define CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ | 6 #define CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "ipc/ipc_listener.h" | 15 #include "ipc/ipc_listener.h" |
16 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 16 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class MessageLoopProxy; | 19 class MessageLoopProxy; |
20 } | 20 } |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class ChildThread; | 23 class ChildThread; |
24 | 24 |
25 // This is thread safe. | 25 // This is thread safe. |
26 class WebMessagePortChannelImpl | 26 class WebMessagePortChannelImpl |
27 : public WebKit::WebMessagePortChannel, | 27 : public blink::WebMessagePortChannel, |
28 public IPC::Listener, | 28 public IPC::Listener, |
29 public base::RefCountedThreadSafe<WebMessagePortChannelImpl> { | 29 public base::RefCountedThreadSafe<WebMessagePortChannelImpl> { |
30 public: | 30 public: |
31 explicit WebMessagePortChannelImpl(base::MessageLoopProxy* child_thread_loop); | 31 explicit WebMessagePortChannelImpl(base::MessageLoopProxy* child_thread_loop); |
32 WebMessagePortChannelImpl(int route_id, | 32 WebMessagePortChannelImpl(int route_id, |
33 int message_port_id, | 33 int message_port_id, |
34 base::MessageLoopProxy* child_thread_loop); | 34 base::MessageLoopProxy* child_thread_loop); |
35 | 35 |
36 // Queues received and incoming messages until there are no more in-flight | 36 // Queues received and incoming messages until there are no more in-flight |
37 // messages, then sends all of them to the browser process. | 37 // messages, then sends all of them to the browser process. |
38 void QueueMessages(); | 38 void QueueMessages(); |
39 int message_port_id() const { return message_port_id_; } | 39 int message_port_id() const { return message_port_id_; } |
40 | 40 |
41 private: | 41 private: |
42 friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>; | 42 friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>; |
43 virtual ~WebMessagePortChannelImpl(); | 43 virtual ~WebMessagePortChannelImpl(); |
44 | 44 |
45 // WebMessagePortChannel implementation. | 45 // WebMessagePortChannel implementation. |
46 virtual void setClient(WebKit::WebMessagePortChannelClient* client); | 46 virtual void setClient(blink::WebMessagePortChannelClient* client); |
47 virtual void destroy(); | 47 virtual void destroy(); |
48 virtual void entangle(WebKit::WebMessagePortChannel* channel); | 48 virtual void entangle(blink::WebMessagePortChannel* channel); |
49 virtual void postMessage(const WebKit::WebString& message, | 49 virtual void postMessage(const blink::WebString& message, |
50 WebKit::WebMessagePortChannelArray* channels); | 50 blink::WebMessagePortChannelArray* channels); |
51 virtual bool tryGetMessage(WebKit::WebString* message, | 51 virtual bool tryGetMessage(blink::WebString* message, |
52 WebKit::WebMessagePortChannelArray& channels); | 52 blink::WebMessagePortChannelArray& channels); |
53 | 53 |
54 void Init(); | 54 void Init(); |
55 void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel); | 55 void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel); |
56 void Send(IPC::Message* message); | 56 void Send(IPC::Message* message); |
57 | 57 |
58 // IPC::Listener implementation. | 58 // IPC::Listener implementation. |
59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
60 | 60 |
61 void OnMessage(const string16& message, | 61 void OnMessage(const string16& message, |
62 const std::vector<int>& sent_message_port_ids, | 62 const std::vector<int>& sent_message_port_ids, |
63 const std::vector<int>& new_routing_ids); | 63 const std::vector<int>& new_routing_ids); |
64 void OnMessagesQueued(); | 64 void OnMessagesQueued(); |
65 | 65 |
66 struct Message { | 66 struct Message { |
67 Message(); | 67 Message(); |
68 ~Message(); | 68 ~Message(); |
69 | 69 |
70 string16 message; | 70 string16 message; |
71 std::vector<WebMessagePortChannelImpl*> ports; | 71 std::vector<WebMessagePortChannelImpl*> ports; |
72 }; | 72 }; |
73 | 73 |
74 typedef std::queue<Message> MessageQueue; | 74 typedef std::queue<Message> MessageQueue; |
75 MessageQueue message_queue_; | 75 MessageQueue message_queue_; |
76 | 76 |
77 WebKit::WebMessagePortChannelClient* client_; | 77 blink::WebMessagePortChannelClient* client_; |
78 base::Lock lock_; // Locks access to above. | 78 base::Lock lock_; // Locks access to above. |
79 | 79 |
80 int route_id_; // The routing id for this object. | 80 int route_id_; // The routing id for this object. |
81 int message_port_id_; // A globally unique identifier for this message port. | 81 int message_port_id_; // A globally unique identifier for this message port. |
82 scoped_refptr<base::MessageLoopProxy> child_thread_loop_; | 82 scoped_refptr<base::MessageLoopProxy> child_thread_loop_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl); | 84 DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl); |
85 }; | 85 }; |
86 | 86 |
87 } // namespace content | 87 } // namespace content |
88 | 88 |
89 #endif // CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ | 89 #endif // CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_ |
OLD | NEW |