Skip to content
Permalink
Browse files

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>
  • Loading branch information...
eugeneo authored and targos committed Jul 3, 2019
1 parent 75c6281 commit 66382abe29d8408db4ff5466c1dd54bbcbaa49d5
Showing with 21 additions and 44 deletions.
  1. +6 −2 src/inspector_agent.cc
  2. +1 −3 src/inspector_agent.h
  3. +5 −8 src/inspector_io.cc
  4. +1 −21 src/inspector_io.h
  5. +4 −10 src/inspector_js_api.cc
  6. +4 −0 src/inspector_socket_server.h
@@ -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
@@ -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();
@@ -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(
@@ -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,
@@ -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()));
}

@@ -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;

0 comments on commit 66382ab

Please sign in to comment.
You can’t perform that action at this time.