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

Unified Diff: content/public/common/message_port.h

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add metrics and support for non-ASCII text messages to Java endpoints Created 3 years, 11 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/public/common/message_port.h
diff --git a/content/public/common/message_port.h b/content/public/common/message_port.h
new file mode 100644
index 0000000000000000000000000000000000000000..15d105f5f0c67b8471e0fbb3a9a86c59db52c934
--- /dev/null
+++ b/content/public/common/message_port.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
kinuko 2017/01/24 12:32:55 nit: 2017 (for all new files) =)
darin (slow to review) 2017/01/26 22:20:03 Thanks
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_MESSAGE_PORT_H_
jam 2017/01/23 18:08:56 nit: CONTENT_PUBLIC
+#define CONTENT_COMMON_MESSAGE_PORT_H_
+
+#include <vector>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/strings/string16.h"
+#include "content/common/content_export.h"
+#include "mojo/public/cpp/system/message_pipe.h"
+
+namespace content {
+
+// MessagePort corresponds to a HTML MessagePort. It is a thin wrapper around a
+// Mojo MessagePipeHandle and provides methods for reading and writing messages.
+//
+// TODO(darin): Make this class move-only once no longer used with Chrome IPC.
+//
+class CONTENT_EXPORT MessagePort {
jam 2017/01/23 18:08:56 I think none of these methods are used outside con
+ public:
+ ~MessagePort();
+ MessagePort();
+
+ // Shallow copy, resulting in multiple references to the same port.
+ MessagePort(const MessagePort& other);
+ MessagePort& operator=(const MessagePort& other);
+
+ explicit MessagePort(mojo::ScopedMessagePipeHandle handle);
+
+ const mojo::ScopedMessagePipeHandle& GetHandle() const;
+ mojo::ScopedMessagePipeHandle ReleaseHandle() const;
+
+ static std::vector<mojo::ScopedMessagePipeHandle> ReleaseHandles(
+ const std::vector<MessagePort>& ports);
+
+ // Sends an encoded message (along with ports to transfer) to this port's
+ // peer.
+ void PostMessage(const base::string16& encoded_message,
+ std::vector<MessagePort> ports);
+
+ // Get the next available encoded message if any. Returns true if a message
+ // was read.
+ bool GetMessage(base::string16* encoded_message,
+ std::vector<MessagePort>* ports);
+
+ // This callback will be invoked on a background thread when messages are
+ // available to be read via GetMessage.
+ void SetCallback(const base::Closure& callback);
+
+ // Clears any callback specified by a prior call to SetCallback.
+ void ClearCallback();
+
+ private:
+ class State : public base::RefCountedThreadSafe<State> {
+ public:
+ State();
+ State(mojo::ScopedMessagePipeHandle handle);
+
+ void AddWatch();
+ void CancelWatch();
+ static void OnHandleReady(uintptr_t context,
+ MojoResult result,
+ MojoHandleSignalsState signals_state,
+ MojoWatchNotificationFlags flags);
+
+ mojo::ScopedMessagePipeHandle handle_;
+ base::Closure callback_;
+
+ private:
+ friend class base::RefCountedThreadSafe<State>;
+ ~State();
+ };
+ mutable scoped_refptr<State> state_;
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_MESSAGE_PORT_H_

Powered by Google App Engine
This is Rietveld 408576698