Skip to content

Commit 66382ab

Browse files
eugeneotargos
authored andcommitted
inspector: reduce InspectorIo API surface
This is a cleanup, allowing for a better separation of concerns. PR-URL: #28526 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 75c6281 commit 66382ab

File tree

6 files changed

+21
-44
lines changed

6 files changed

+21
-44
lines changed

src/inspector_agent.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,12 @@ std::shared_ptr<WorkerManager> Agent::GetWorkerManager() {
977977
return client_->getWorkerManager();
978978
}
979979

980+
std::string Agent::GetWsUrl() const {
981+
if (io_ == nullptr)
982+
return "";
983+
return io_->GetWsUrl();
984+
}
985+
980986
SameThreadInspectorSession::~SameThreadInspectorSession() {
981987
auto client = client_.lock();
982988
if (client)
@@ -990,7 +996,5 @@ void SameThreadInspectorSession::Dispatch(
990996
client->dispatchMessageFromFrontend(session_id_, message);
991997
}
992998

993-
994-
995999
} // namespace inspector
9961000
} // namespace node

src/inspector_agent.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ class Agent {
9494

9595
void PauseOnNextJavascriptStatement(const std::string& reason);
9696

97-
InspectorIo* io() {
98-
return io_.get();
99-
}
97+
std::string GetWsUrl() const;
10098

10199
// Can only be called from the main thread.
102100
bool StartIoThread();

src/inspector_io.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace {
2323
using v8_inspector::StringBuffer;
2424
using v8_inspector::StringView;
2525

26+
// kKill closes connections and stops the server, kStop only stops the server
27+
enum class TransportAction { kKill, kSendMessage, kStop };
28+
2629
std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
2730
std::string script_path;
2831

@@ -177,12 +180,6 @@ class RequestQueue {
177180
data_->Post(session_id, action, std::move(message));
178181
}
179182

180-
void SetServer(InspectorSocketServer* server) {
181-
Mutex::ScopedLock scoped_lock(lock_);
182-
if (data_ != nullptr)
183-
data_->SetServer(server);
184-
}
185-
186183
bool Expired() {
187184
Mutex::ScopedLock scoped_lock(lock_);
188185
return data_ == nullptr;
@@ -315,8 +312,8 @@ void InspectorIo::ThreadMain() {
315312
CheckedUvLoopClose(&loop);
316313
}
317314

318-
std::vector<std::string> InspectorIo::GetTargetIds() const {
319-
return { id_ };
315+
std::string InspectorIo::GetWsUrl() const {
316+
return FormatWsAddress(host_port_->host(), host_port_->port(), id_, true);
320317
}
321318

322319
InspectorIoDelegate::InspectorIoDelegate(

src/inspector_io.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,14 @@
1414
#include <cstddef>
1515
#include <memory>
1616

17-
18-
namespace v8_inspector {
19-
class StringBuffer;
20-
class StringView;
21-
} // namespace v8_inspector
22-
2317
namespace node {
2418
// Forward declaration to break recursive dependency chain with src/env.h.
2519
class Environment;
2620
namespace inspector {
2721

28-
std::string FormatWsAddress(const std::string& host, int port,
29-
const std::string& target_id,
30-
bool include_protocol);
31-
32-
class InspectorIoDelegate;
3322
class MainThreadHandle;
3423
class RequestQueue;
3524

36-
// kKill closes connections and stops the server, kStop only stops the server
37-
enum class TransportAction {
38-
kKill,
39-
kSendMessage,
40-
kStop
41-
};
42-
4325
class InspectorIo {
4426
public:
4527
// Start the inspector agent thread, waiting for it to initialize
@@ -55,9 +37,7 @@ class InspectorIo {
5537
~InspectorIo();
5638

5739
void StopAcceptingNewConnections();
58-
const std::string& host() const { return host_port_->host(); }
59-
int port() const { return host_port_->port(); }
60-
std::vector<std::string> GetTargetIds() const;
40+
std::string GetWsUrl() const;
6141

6242
private:
6343
InspectorIo(std::shared_ptr<MainThreadHandle> handle,

src/inspector_js_api.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,10 @@ void Open(const FunctionCallbackInfo<Value>& args) {
259259

260260
void Url(const FunctionCallbackInfo<Value>& args) {
261261
Environment* env = Environment::GetCurrent(args);
262-
Agent* agent = env->inspector_agent();
263-
InspectorIo* io = agent->io();
264-
265-
if (!io) return;
266-
267-
std::vector<std::string> ids = io->GetTargetIds();
268-
269-
if (ids.empty()) return;
270-
271-
std::string url = FormatWsAddress(io->host(), io->port(), ids[0], true);
262+
std::string url = env->inspector_agent()->GetWsUrl();
263+
if (url.length() == 0) {
264+
return;
265+
}
272266
args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));
273267
}
274268

src/inspector_socket_server.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
namespace node {
1919
namespace inspector {
2020

21+
std::string FormatWsAddress(const std::string& host, int port,
22+
const std::string& target_id,
23+
bool include_protocol);
24+
2125
class InspectorSocketServer;
2226
class SocketSession;
2327
class ServerSocket;

0 commit comments

Comments
 (0)