Skip to content

Commit

Permalink
inspector: reduce InspectorIo API surface
Browse files Browse the repository at this point in the history
This is a cleanup, allowing for a better separation of concerns.

PR-URL: #28526
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Aleksei Koziatinskii <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
eugeneo authored and targos committed Jul 20, 2019
1 parent 75c6281 commit 66382ab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 44 deletions.
8 changes: 6 additions & 2 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -990,7 +996,5 @@ void SameThreadInspectorSession::Dispatch(
client->dispatchMessageFromFrontend(session_id_, message);
}



} // namespace inspector
} // namespace node
4 changes: 1 addition & 3 deletions src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 1 addition & 21 deletions src/inspector_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
14 changes: 4 additions & 10 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
4 changes: 4 additions & 0 deletions src/inspector_socket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 66382ab

Please sign in to comment.