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

Side by Side Diff: extensions/renderer/extension_port.h

Issue 2300453002: [Extensions] Begin making Extension port initialization asynchronous (Closed)
Patch Set: Nasko's Created 4 years, 3 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 representing information about a specific extension message port that
23 // handles sending related IPCs to the browser. Since global port IDs are
24 // assigned asynchronously, this object caches pending 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 Close(bool close_channel);
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; }
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;
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_
OLDNEW
« 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