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

Unified Diff: extensions/renderer/extension_port.h

Issue 2547753002: [Extensions] Extension Port Ids and Initialization 2.0 (Closed)
Patch Set: rkaplow Created 4 years 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
« no previous file with comments | « extensions/renderer/extension_frame_helper.cc ('k') | extensions/renderer/extension_port.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/extension_port.h
diff --git a/extensions/renderer/extension_port.h b/extensions/renderer/extension_port.h
index def591073886e3f0e3f52d0ca890dd02926eb5b6..aa584a97b5f02484e4f32cb2a5ae3396ac26fac9 100644
--- a/extensions/renderer/extension_port.h
+++ b/extensions/renderer/extension_port.h
@@ -6,31 +6,25 @@
#define EXTENSIONS_RENDERER_EXTENSION_PORT_H_
#include <memory>
+#include <utility>
#include <vector>
#include "base/macros.h"
-
-namespace content {
-class RenderFrame;
-}
+#include "extensions/common/api/messaging/port_id.h"
namespace extensions {
-
struct Message;
+struct PortId;
class ScriptContext;
// A class representing information about a specific extension message port that
-// handles sending related IPCs to the browser. Since global port IDs are
-// assigned asynchronously, this object caches pending messages.
+// handles sending related IPCs to the browser. This consists of a port id and
+// a separate js_id which is exposed only to the JavaScript context.
class ExtensionPort {
public:
- ExtensionPort(ScriptContext* script_context, int local_id);
+ ExtensionPort(ScriptContext* script_context, const PortId& id, int js_id);
~ExtensionPort();
- // Sets the global id of the port (that is, the id used in the browser
- // process to send/receive messages). Any pending messages will be sent.
- void SetGlobalId(int id);
-
// Posts a new message to the port. If the port is not initialized, the
// message will be queued until it is.
void PostExtensionMessage(std::unique_ptr<Message> message);
@@ -39,36 +33,20 @@ class ExtensionPort {
// assuming initialization completes (after which, the port will close).
void Close(bool close_channel);
- int local_id() const { return local_id_; }
- int global_id() const { return global_id_; }
- bool initialized() const { return global_id_ != -1; }
+ const PortId& id() const { return id_; }
+ int js_id() const { return js_id_; }
private:
- // Helper function to send the post message IPC.
- void PostMessageImpl(content::RenderFrame* render_frame,
- const Message& message);
-
- // Sends the message to the browser that this port has been disconnected.
- void SendDisconnected(content::RenderFrame* render_frame);
-
// The associated ScriptContext for this port. Since these objects are owned
// by a NativeHandler, this should always be valid.
ScriptContext* script_context_ = nullptr;
- // The local id of the port (used within JS bindings).
- int local_id_ = -1;
-
- // The global id of the port (used by the browser process).
- int global_id_ = -1;
-
- // The queue of any pending messages to be sent once the port is initialized.
- std::vector<std::unique_ptr<Message>> pending_messages_;
-
- // Whether or not the port is disconnected.
- bool is_disconnected_ = false;
+ const PortId id_;
- // Whether to close the full message channel.
- bool close_channel_ = false;
+ // The id used in the JS bindings. If this is a receiver port, this is not the
+ // same as the port_number in the PortId. This should be used only as an
+ // identifier in the JS context this port is from.
+ int js_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(ExtensionPort);
};
« no previous file with comments | « extensions/renderer/extension_frame_helper.cc ('k') | extensions/renderer/extension_port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698