Revert 199284 "[Downloads] Clear current_path_ when deleting int..."
[chromium-blink-merge.git] / content / common / webmessageportchannel_impl.h
blobddf5757fef1cc2ff8b99bd499c50b25ee3d842a2
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.
5 #ifndef CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
6 #define CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_
8 #include <queue>
9 #include <vector>
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/Source/Platform/chromium/public/WebMessagePortChannel.h"
18 namespace content {
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);
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_; }
34 private:
35 friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>;
36 virtual ~WebMessagePortChannelImpl();
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);
47 void Init();
48 void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel);
49 void Send(IPC::Message* message);
51 // IPC::Listener implementation.
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
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();
59 struct Message {
60 Message();
61 ~Message();
63 string16 message;
64 std::vector<WebMessagePortChannelImpl*> ports;
67 typedef std::queue<Message> MessageQueue;
68 MessageQueue message_queue_;
70 WebKit::WebMessagePortChannelClient* client_;
71 base::Lock lock_; // Locks access to above.
73 int route_id_; // The routing id for this object.
74 int message_port_id_; // A globally unique identifier for this message port.
76 DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl);
79 } // namespace content
81 #endif // CONTENT_COMMON_WEBMESSAGEPORTCHANNEL_IMPL_H_