summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Ostroukhov <eostroukhov@gmail.com>2019-07-03 11:32:31 -0700
committerAnna Henningsen <anna@addaleax.net>2019-07-06 20:04:03 +0200
commit17862fca5f6acfad5941ec651769493310a5c571 (patch)
tree203ae2d3a759a5b47244d1ae048ebbf7997de0f3 /src
parent33a8093411e984756869ab03226b21bdecd85795 (diff)
downloadandroid-node-v8-17862fca5f6acfad5941ec651769493310a5c571.tar.gz
android-node-v8-17862fca5f6acfad5941ec651769493310a5c571.tar.bz2
android-node-v8-17862fca5f6acfad5941ec651769493310a5c571.zip
inspector: reduce InspectorIo API surface
This is a cleanup, allowing for a better separation of concerns. PR-URL: https://github.com/nodejs/node/pull/28526 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/inspector_agent.cc8
-rw-r--r--src/inspector_agent.h4
-rw-r--r--src/inspector_io.cc13
-rw-r--r--src/inspector_io.h22
-rw-r--r--src/inspector_js_api.cc14
-rw-r--r--src/inspector_socket_server.h4
6 files changed, 21 insertions, 44 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index aebea4a556..df6a70d148 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -977,6 +977,12 @@ std::shared_ptr<WorkerManager> Agent::GetWorkerManager() {
return client_->getWorkerManager();
}
+std::string Agent::GetWsUrl() const {
+ if (io_ == nullptr)
+ return "";
+ return io_->GetWsUrl();
+}
+
SameThreadInspectorSession::~SameThreadInspectorSession() {
auto client = client_.lock();
if (client)
@@ -990,7 +996,5 @@ void SameThreadInspectorSession::Dispatch(
client->dispatchMessageFromFrontend(session_id_, message);
}
-
-
} // namespace inspector
} // namespace node
diff --git a/src/inspector_agent.h b/src/inspector_agent.h
index 5447a68485..4fb544f85b 100644
--- a/src/inspector_agent.h
+++ b/src/inspector_agent.h
@@ -94,9 +94,7 @@ class Agent {
void PauseOnNextJavascriptStatement(const std::string& reason);
- InspectorIo* io() {
- return io_.get();
- }
+ std::string GetWsUrl() const;
// Can only be called from the main thread.
bool StartIoThread();
diff --git a/src/inspector_io.cc b/src/inspector_io.cc
index 91384ca949..76e481c953 100644
--- a/src/inspector_io.cc
+++ b/src/inspector_io.cc
@@ -23,6 +23,9 @@ namespace {
using v8_inspector::StringBuffer;
using v8_inspector::StringView;
+// kKill closes connections and stops the server, kStop only stops the server
+enum class TransportAction { kKill, kSendMessage, kStop };
+
std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
std::string script_path;
@@ -177,12 +180,6 @@ class RequestQueue {
data_->Post(session_id, action, std::move(message));
}
- void SetServer(InspectorSocketServer* server) {
- Mutex::ScopedLock scoped_lock(lock_);
- if (data_ != nullptr)
- data_->SetServer(server);
- }
-
bool Expired() {
Mutex::ScopedLock scoped_lock(lock_);
return data_ == nullptr;
@@ -315,8 +312,8 @@ void InspectorIo::ThreadMain() {
CheckedUvLoopClose(&loop);
}
-std::vector<std::string> InspectorIo::GetTargetIds() const {
- return { id_ };
+std::string InspectorIo::GetWsUrl() const {
+ return FormatWsAddress(host_port_->host(), host_port_->port(), id_, true);
}
InspectorIoDelegate::InspectorIoDelegate(
diff --git a/src/inspector_io.h b/src/inspector_io.h
index 57facb2294..e9f9405673 100644
--- a/src/inspector_io.h
+++ b/src/inspector_io.h
@@ -14,32 +14,14 @@
#include <cstddef>
#include <memory>
-
-namespace v8_inspector {
-class StringBuffer;
-class StringView;
-} // namespace v8_inspector
-
namespace node {
// Forward declaration to break recursive dependency chain with src/env.h.
class Environment;
namespace inspector {
-std::string FormatWsAddress(const std::string& host, int port,
- const std::string& target_id,
- bool include_protocol);
-
-class InspectorIoDelegate;
class MainThreadHandle;
class RequestQueue;
-// kKill closes connections and stops the server, kStop only stops the server
-enum class TransportAction {
- kKill,
- kSendMessage,
- kStop
-};
-
class InspectorIo {
public:
// Start the inspector agent thread, waiting for it to initialize
@@ -55,9 +37,7 @@ class InspectorIo {
~InspectorIo();
void StopAcceptingNewConnections();
- const std::string& host() const { return host_port_->host(); }
- int port() const { return host_port_->port(); }
- std::vector<std::string> GetTargetIds() const;
+ std::string GetWsUrl() const;
private:
InspectorIo(std::shared_ptr<MainThreadHandle> handle,
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index 9d64938570..3131c6ad37 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -259,16 +259,10 @@ void Open(const FunctionCallbackInfo<Value>& args) {
void Url(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- Agent* agent = env->inspector_agent();
- InspectorIo* io = agent->io();
-
- if (!io) return;
-
- std::vector<std::string> ids = io->GetTargetIds();
-
- if (ids.empty()) return;
-
- std::string url = FormatWsAddress(io->host(), io->port(), ids[0], true);
+ std::string url = env->inspector_agent()->GetWsUrl();
+ if (url.length() == 0) {
+ return;
+ }
args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));
}
diff --git a/src/inspector_socket_server.h b/src/inspector_socket_server.h
index 42ab90ac90..98d4e7d015 100644
--- a/src/inspector_socket_server.h
+++ b/src/inspector_socket_server.h
@@ -18,6 +18,10 @@
namespace node {
namespace inspector {
+std::string FormatWsAddress(const std::string& host, int port,
+ const std::string& target_id,
+ bool include_protocol);
+
class InspectorSocketServer;
class SocketSession;
class ServerSocket;