GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/inspector/worker_inspector.h Lines: 17 17 100.0 %
Date: 2019-09-26 22:31:05 Branches: 1 2 50.0 %

Line Branch Exec Source
1
#ifndef SRC_INSPECTOR_WORKER_INSPECTOR_H_
2
#define SRC_INSPECTOR_WORKER_INSPECTOR_H_
3
4
#if !HAVE_INSPECTOR
5
#error("This header can only be used when inspector is enabled")
6
#endif
7
8
#include <memory>
9
#include <string>
10
#include <unordered_map>
11
#include <unordered_set>
12
13
namespace node {
14
namespace inspector {
15
class InspectorSession;
16
class InspectorSessionDelegate;
17
class MainThreadHandle;
18
class WorkerManager;
19
20
7
class WorkerDelegate {
21
 public:
22
  virtual void WorkerCreated(const std::string& title,
23
                             const std::string& url,
24
                             bool waiting,
25
                             std::shared_ptr<MainThreadHandle> worker) = 0;
26
7
  virtual ~WorkerDelegate() = default;
27
};
28
29
class WorkerManagerEventHandle {
30
 public:
31
7
  explicit WorkerManagerEventHandle(std::shared_ptr<WorkerManager> manager,
32
                                    int id)
33
7
                                    : manager_(manager), id_(id) {}
34
  void SetWaitOnStart(bool wait_on_start);
35
  ~WorkerManagerEventHandle();
36
37
 private:
38
  std::shared_ptr<WorkerManager> manager_;
39
  int id_;
40
};
41
42
630
struct WorkerInfo {
43
209
  WorkerInfo(const std::string& target_title,
44
             const std::string& target_url,
45
             std::shared_ptr<MainThreadHandle> worker_thread)
46
             : title(target_title),
47
               url(target_url),
48
209
               worker_thread(worker_thread) {}
49
  std::string title;
50
  std::string url;
51
  std::shared_ptr<MainThreadHandle> worker_thread;
52
};
53
54
class ParentInspectorHandle {
55
 public:
56
  ParentInspectorHandle(int id, const std::string& url,
57
                        std::shared_ptr<MainThreadHandle> parent_thread,
58
                        bool wait_for_connect);
59
  ~ParentInspectorHandle();
60
4
  std::unique_ptr<ParentInspectorHandle> NewParentInspectorHandle(
61
      int thread_id, const std::string& url) {
62
    return std::make_unique<ParentInspectorHandle>(thread_id,
63
                                                   url,
64
                                                   parent_thread_,
65
4
                                                   wait_);
66
  }
67
  void WorkerStarted(std::shared_ptr<MainThreadHandle> worker_thread,
68
                     bool waiting);
69
210
  bool WaitForConnect() {
70
210
    return wait_;
71
  }
72
210
  const std::string& url() const { return url_; }
73
  std::unique_ptr<inspector::InspectorSession> Connect(
74
      std::unique_ptr<inspector::InspectorSessionDelegate> delegate,
75
      bool prevent_shutdown);
76
77
 private:
78
  int id_;
79
  std::string url_;
80
  std::shared_ptr<MainThreadHandle> parent_thread_;
81
  bool wait_;
82
};
83
84
4480
class WorkerManager : public std::enable_shared_from_this<WorkerManager> {
85
 public:
86
4888
  explicit WorkerManager(std::shared_ptr<MainThreadHandle> thread)
87
4888
                         : thread_(thread) {}
88
89
  std::unique_ptr<ParentInspectorHandle> NewParentHandle(
90
      int thread_id, const std::string& url);
91
  void WorkerStarted(int session_id, const WorkerInfo& info, bool waiting);
92
  void WorkerFinished(int session_id);
93
  std::unique_ptr<WorkerManagerEventHandle> SetAutoAttach(
94
      std::unique_ptr<WorkerDelegate> attach_delegate);
95
  void SetWaitOnStartForDelegate(int id, bool wait);
96
  void RemoveAttachDelegate(int id);
97
5131
  std::shared_ptr<MainThreadHandle> MainThread() {
98
5131
    return thread_;
99
  }
100
101
 private:
102
  std::shared_ptr<MainThreadHandle> thread_;
103
  std::unordered_map<int, WorkerInfo> children_;
104
  std::unordered_map<int, std::unique_ptr<WorkerDelegate>> delegates_;
105
  // If any one needs it, workers stop for all
106
  std::unordered_set<int> delegates_waiting_on_start_;
107
  int next_delegate_id_ = 0;
108
};
109
}  // namespace inspector
110
}  // namespace node
111
112
#endif  // SRC_INSPECTOR_WORKER_INSPECTOR_H_