Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef EXTENSIONS_RENDERER_EXTENSION_PORT_H_ | |
| 6 #define EXTENSIONS_RENDERER_EXTENSION_PORT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 | |
| 13 namespace content { | |
| 14 class RenderFrame; | |
| 15 } | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 struct Message; | |
| 20 class ScriptContext; | |
| 21 | |
| 22 // A class to handle sending message port-related IPCs to the browser. Since | |
|
lazyboy
2016/09/08 00:05:40
Also point out what this class represents, "info a
Devlin
2016/09/08 19:15:30
Done.
| |
| 23 // global port IDs are assigned asynchronously, this object caches pending | |
| 24 // messages. | |
| 25 class ExtensionPort { | |
| 26 public: | |
| 27 ExtensionPort(ScriptContext* script_context, int local_id); | |
| 28 ~ExtensionPort(); | |
| 29 | |
| 30 // Sets the global id of the port (that is, the id used in the browser | |
| 31 // process to send/receive messages). Any pending messages will be sent. | |
| 32 void SetGlobalId(int id); | |
| 33 | |
| 34 // Posts a new message to the port. If the port is not initialized, the | |
| 35 // message will be queued until it is. | |
| 36 void PostExtensionMessage(std::unique_ptr<Message> message); | |
| 37 | |
| 38 // Closes the port. If there are pending messages, they will still be sent | |
| 39 // assuming initialization completes (after which, the port will close). | |
| 40 void ClosePort(bool close_channel); | |
|
lazyboy
2016/09/08 00:05:40
"Port" prefix seems extraneous given |this| is a E
Devlin
2016/09/08 19:15:30
Fair enough, done.
| |
| 41 | |
| 42 int local_id() const { return local_id_; } | |
| 43 int global_id() const { return global_id_; } | |
| 44 bool initialized() const { return global_id_ != -1; } | |
|
lazyboy
2016/09/08 00:05:40
IsInitialized() and move definition to cc file.
Devlin
2016/09/08 19:15:30
Why? This is basically a simple accessor (it does
lazyboy
2016/09/08 21:59:16
I guess I simplified the meaning of simple accesso
| |
| 45 | |
| 46 private: | |
| 47 // Helper function to send the post message IPC. | |
| 48 void PostMessageImpl(content::RenderFrame* render_frame, | |
| 49 const Message& message); | |
| 50 | |
| 51 // Sends the message to the browser that this port has been disconnected. | |
| 52 void SendDisconnected(content::RenderFrame* render_frame); | |
| 53 | |
| 54 // The associated ScriptContext for this port. Since these objects are owned | |
| 55 // by a NativeHandler, this should always be valid. | |
| 56 ScriptContext* script_context_ = nullptr; | |
|
lazyboy
2016/09/08 00:05:40
Here and for local_id_: Do you need default member
Devlin
2016/09/08 19:15:30
I think yes, because we want a fallback if the cto
lazyboy
2016/09/08 21:59:16
Acknowledged.
| |
| 57 | |
| 58 // The local id of the port (used within JS bindings). | |
| 59 int local_id_ = -1; | |
| 60 | |
| 61 // The global id of the port (used by the browser process). | |
| 62 int global_id_ = -1; | |
| 63 | |
| 64 // The queue of any pending messages to be sent once the port is initialized. | |
| 65 std::vector<std::unique_ptr<Message>> pending_messages_; | |
| 66 | |
| 67 // Whether or not the port is disconnected. | |
| 68 bool is_disconnected_ = false; | |
| 69 | |
| 70 // Whether to close the full message channel. | |
| 71 bool close_channel_ = false; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ExtensionPort); | |
| 74 }; | |
| 75 | |
| 76 } // namespace extensions | |
| 77 | |
| 78 #endif // EXTENSIONS_RENDERER_EXTENSION_PORT_H_ | |
| OLD | NEW |