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

Unified Diff: content/child/webmessageportchannel_impl.h

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add missing ScopedAsyncTaskScheduler instance for the new unit tests; required by a recent change t… Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/child/webmessageportchannel_impl.h
diff --git a/content/child/webmessageportchannel_impl.h b/content/child/webmessageportchannel_impl.h
index 6fa60806f4291676e79aee4bf90bc25dbc6b1b6c..70a04b1766171f0fbba35cce72e53a9257011904 100644
--- a/content/child/webmessageportchannel_impl.h
+++ b/content/child/webmessageportchannel_impl.h
@@ -6,120 +6,47 @@
#define CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_
#include <memory>
-#include <queue>
#include <vector>
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/strings/string16.h"
-#include "base/synchronization/lock.h"
-#include "ipc/ipc_listener.h"
+#include "content/common/message_port.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
-namespace base {
-class SingleThreadTaskRunner;
-}
-
namespace content {
// This is thread safe.
-class WebMessagePortChannelImpl
- : public blink::WebMessagePortChannel,
- public IPC::Listener,
- public base::RefCountedThreadSafe<WebMessagePortChannelImpl> {
+class WebMessagePortChannelImpl : public blink::WebMessagePortChannel {
public:
- explicit WebMessagePortChannelImpl(
- const scoped_refptr<base::SingleThreadTaskRunner>&
- main_thread_task_runner);
- WebMessagePortChannelImpl(
- int route_id,
- int port_id,
- const scoped_refptr<base::SingleThreadTaskRunner>&
- main_thread_task_runner);
-
- static void CreatePair(
- const scoped_refptr<base::SingleThreadTaskRunner>&
- main_thread_task_runner,
- blink::WebMessagePortChannel** channel1,
- blink::WebMessagePortChannel** channel2);
-
- // Extracts port IDs for passing on to the browser process, and queues any
- // received messages.
- static std::vector<int> ExtractMessagePortIDs(
- std::unique_ptr<blink::WebMessagePortChannelArray> channels);
+ ~WebMessagePortChannelImpl() override;
+ explicit WebMessagePortChannelImpl(MessagePort message_port);
- // Extracts port IDs for passing on to the browser process, and queues any
- // received messages.
- static std::vector<int> ExtractMessagePortIDs(
- const blink::WebMessagePortChannelArray& channels);
+ static void CreatePair(blink::WebMessagePortChannel** channel1,
+ blink::WebMessagePortChannel** channel2);
- // Extracts port IDs for passing on to the browser process, but doesn't
- // send a separate IPC to the browser to initiate queueing messages. Instead
- // calling code is responsible for initiating the queueing in the browser
- // process. This is useful when transfering ports over an IPC channel that
- // does not share ordering guarentees with regular IPC.
- static std::vector<int>
- ExtractMessagePortIDsWithoutQueueing(
- std::unique_ptr<blink::WebMessagePortChannelArray> channels);
+ // Extracts MessagePorts for passing on to other processes.
+ static std::vector<MessagePort> ExtractMessagePorts(
+ blink::WebMessagePortChannelArray channels);
- // Creates WebMessagePortChannelImpl instances for port IDs passed in from the
- // browser process.
- static blink::WebMessagePortChannelArray CreatePorts(
- const std::vector<int>& message_ports,
- const std::vector<int>& new_routing_ids,
- const scoped_refptr<base::SingleThreadTaskRunner>&
- main_thread_task_runner);
+ // Creates WebMessagePortChannelImpl instances for MessagePorts passed in from
+ // other processes.
+ static blink::WebMessagePortChannelArray CreateFromMessagePorts(
+ const std::vector<MessagePort>& message_ports);
+ static blink::WebMessagePortChannelArray CreateFromMessagePipeHandles(
+ std::vector<mojo::ScopedMessagePipeHandle> handles);
- // 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_; }
+ MessagePort ReleaseMessagePort();
private:
- friend class base::RefCountedThreadSafe<WebMessagePortChannelImpl>;
- ~WebMessagePortChannelImpl() override;
+ explicit WebMessagePortChannelImpl(mojo::ScopedMessagePipeHandle handle);
// WebMessagePortChannel implementation.
void setClient(blink::WebMessagePortChannelClient* client) override;
- void destroy() override;
- void postMessage(const blink::WebString& message,
- blink::WebMessagePortChannelArray* channels_ptr) override;
- bool tryGetMessage(blink::WebString* message,
+ void postMessage(const blink::WebString& encoded_message,
+ blink::WebMessagePortChannelArray channels) override;
+ bool tryGetMessage(blink::WebString* encoded_message,
blink::WebMessagePortChannelArray& channels) override;
- void Init();
- void Entangle(scoped_refptr<WebMessagePortChannelImpl> channel);
- void Send(IPC::Message* message);
- void SendPostMessage(
- const base::string16& message,
- std::unique_ptr<blink::WebMessagePortChannelArray> channels);
-
- // IPC::Listener implementation.
- bool OnMessageReceived(const IPC::Message& message) override;
-
- void OnMessage(const base::string16& message,
- const std::vector<int>& sent_message_ports,
- const std::vector<int>& new_routing_ids);
- void OnMessagesQueued();
-
- struct Message {
- Message();
- Message(const Message& other);
- ~Message();
-
- base::string16 message;
- blink::WebMessagePortChannelArray ports;
- };
-
- typedef std::queue<Message> MessageQueue;
- MessageQueue message_queue_;
-
- blink::WebMessagePortChannelClient* client_;
- base::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.
- scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+ MessagePort port_;
DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl);
};
« no previous file with comments | « content/child/service_worker/web_service_worker_impl.cc ('k') | content/child/webmessageportchannel_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698