Index: extensions/common/api/messaging/port_id.h |
diff --git a/extensions/common/api/messaging/port_id.h b/extensions/common/api/messaging/port_id.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a82667d79b58caf3c618d405fcb457cfece3e1da |
--- /dev/null |
+++ b/extensions/common/api/messaging/port_id.h |
@@ -0,0 +1,54 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef EXTENSIONS_COMMON_API_MESSAGING_PORT_ID_H_ |
+#define EXTENSIONS_COMMON_API_MESSAGING_PORT_ID_H_ |
+ |
+#include <string> |
+ |
+namespace extensions { |
+ |
+// A unique identifier for an extension port. The id is composed of three parts: |
+// - context_id: A GUID that uniquely identifies the creation context of the |
+// port. |
+// - port_number: A simple identifer that uniquely identifies the port *within |
+// the creation context*. That is, each creation context may |
+// have a port with number '1', but there should only be a single |
+// port with the number '1' in each. |
+// - is_opener: Whether or not this port id is for the opener port (false |
+// indicating it is the receiver port). |
+// A few more notes: |
+// - There should only be a single existent opener port. That is, in all the |
+// contexts, there should only be one with a given context_id, port_number, |
+// and is_opener set to true. However, each port can have multiple receivers, |
+// thus there may be multiple ports with a given context_id, port_number, and |
+// is_opener set to false. |
+// - The context_id and port_number refer to the values at *creation*, and are |
+// conceptually immutable. Receiver ports will always have a context id other |
+// than the one they are hosted in (since we don't dispatch messages to the |
+// same context). Only in the case of opener ports do these identify the |
+// current context. |
+// - Context id and port number are set in the renderer process. Theoretically, |
+// - this means that multiple contexts could have the same id. However, GUIDs |
robwu
2016/12/02 11:58:54
Nit: "-" is superfluous.
Devlin
2016/12/02 17:16:32
Whoops! Didn't mean to have that one there. Than
|
+// are sufficiently random as to be globally unique in practice (the chance |
+// of a duplicate is about the same as the sun exploding right now). |
+struct PortId { |
+ std::string context_id; |
+ int port_number = 0; |
+ bool is_opener = false; |
+ |
+ PortId(); |
+ PortId(const std::string& context_id, int port_number, bool is_opener); |
+ ~PortId(); |
+ PortId(PortId&& other); |
+ PortId(const PortId& other); |
+ PortId& operator=(const PortId& other); |
+ |
+ bool operator==(const PortId& other) const; |
+ bool operator<(const PortId& other) const; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_COMMON_API_MESSAGING_PORT_ID_H_ |