11#include "target_agent.h"
2- #include <iostream>
3- #include <memory>
4- #include <set>
5- #include <string>
6- #include <tuple>
7- #include <utility>
8- #include "inspector/node_string.h"
92#include "inspector/worker_inspector.h"
103#include "main_thread_interface.h"
114
125namespace node {
136namespace inspector {
147namespace protocol {
158
16- std::unordered_map<int,std::shared_ptr<MainThreadHandle>> TargetAgent::target_session_id_worker_map_ = std::unordered_map<int, std::shared_ptr<MainThreadHandle>>();
17-
18-
9+ std::unordered_map<int, std::shared_ptr<MainThreadHandle>>
10+ TargetAgent::target_session_id_worker_map_ =
11+ std::unordered_map<int, std::shared_ptr<MainThreadHandle>>();
12+ int TargetAgent::next_session_id_ = 1;
1913class WorkerTargetDelegate : public WorkerDelegate {
2014 public:
2115 explicit WorkerTargetDelegate(std::shared_ptr<TargetAgent> target_agent)
2216 : target_agent_(target_agent) {}
2317
24-
2518 void WorkerCreated(const std::string& title,
2619 const std::string& url,
2720 bool waiting,
2821 std::shared_ptr<MainThreadHandle> worker) override {
2922 std::string target_id = std::to_string(target_agent_->getNextTargetId());
3023 std::string type = "worker";
31-
24+
3225 target_agent_->targetCreated(target_id, type, title, url);
33- target_agent_->attachedToTarget(worker,target_id, type, title, url);
26+ target_agent_->attachedToTarget(worker, target_id, type, title, url);
3427 }
3528
3629 private:
3730 const std::shared_ptr<TargetAgent> target_agent_;
3831};
3932
40- std::unique_ptr<Target::TargetInfo> createTargetInfo(
41- const String& target_id,
42- const String& type,
43- const String& title,
44- const String& url) {
33+ std::unique_ptr<Target::TargetInfo> createTargetInfo(const String& target_id,
34+ const String& type,
35+ const String& title,
36+ const String& url) {
4537 return Target::TargetInfo::create()
4638 .setTargetId(target_id)
4739 .setType(type)
@@ -62,7 +54,8 @@ void TargetAgent::listenWorker(std::weak_ptr<WorkerManager> worker_manager) {
6254 if (!manager) {
6355 return;
6456 }
65- std::unique_ptr<WorkerDelegate> delegate(new WorkerTargetDelegate(shared_from_this()));
57+ std::unique_ptr<WorkerDelegate> delegate(
58+ new WorkerTargetDelegate(shared_from_this()));
6659 worker_event_handle_ = manager->SetAutoAttach(std::move(delegate));
6760}
6861
@@ -72,7 +65,10 @@ void TargetAgent::reset() {
7265 }
7366}
7467
75- void TargetAgent::targetCreated(const std::string &target_id,const std::string &type,const std::string &title,const std::string &url) {
68+ void TargetAgent::targetCreated(const std::string& target_id,
69+ const std::string& type,
70+ const std::string& title,
71+ const std::string& url) {
7672 frontend_->targetCreated(createTargetInfo(target_id, type, title, url));
7773}
7874
@@ -84,13 +80,19 @@ int TargetAgent::getNextTargetId() {
8480 return next_target_id_++;
8581}
8682
87- void TargetAgent::attachedToTarget(std::shared_ptr<MainThreadHandle> worker,const std::string &target_id, const std::string &type,const std::string &title,const std::string &url) {
83+ void TargetAgent::attachedToTarget(std::shared_ptr<MainThreadHandle> worker,
84+ const std::string& target_id,
85+ const std::string& type,
86+ const std::string& title,
87+ const std::string& url) {
8888 int session_id = getNextSessionId();
8989 target_session_id_worker_map_[session_id] = worker;
9090 worker->SetTargetSessionId(session_id);
91- frontend_->attachedToTarget(std::to_string(session_id), createTargetInfo(target_id, type, title, url), true);
91+ frontend_->attachedToTarget(std::to_string(session_id),
92+ createTargetInfo(target_id, type, title, url),
93+ true);
9294}
9395
94- } // namespace protocol
96+ } // namespace protocol
9597} // namespace inspector
9698} // namespace node
0 commit comments