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: 14 14 100.0 %
Date: 2019-02-23 22:23: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 MainThreadHandle;
16
class WorkerManager;
17
18
3
class WorkerDelegate {
19
 public:
20
  virtual void WorkerCreated(const std::string& title,
21
                             const std::string& url,
22
                             bool waiting,
23
                             std::shared_ptr<MainThreadHandle> worker) = 0;
24
3
  virtual ~WorkerDelegate() {}
25
};
26
27
class WorkerManagerEventHandle {
28
 public:
29
3
  explicit WorkerManagerEventHandle(std::shared_ptr<WorkerManager> manager,
30
                                    int id)
31
3
                                    : manager_(manager), id_(id) {}
32
  void SetWaitOnStart(bool wait_on_start);
33
  ~WorkerManagerEventHandle();
34
35
 private:
36
  std::shared_ptr<WorkerManager> manager_;
37
  int id_;
38
};
39
40
495
struct WorkerInfo {
41
165
  WorkerInfo(const std::string& target_title,
42
             const std::string& target_url,
43
             std::shared_ptr<MainThreadHandle> worker_thread)
44
             : title(target_title),
45
               url(target_url),
46
165
               worker_thread(worker_thread) {}
47
  std::string title;
48
  std::string url;
49
  std::shared_ptr<MainThreadHandle> worker_thread;
50
};
51
52
class ParentInspectorHandle {
53
 public:
54
  ParentInspectorHandle(int id, const std::string& url,
55
                        std::shared_ptr<MainThreadHandle> parent_thread,
56
                        bool wait_for_connect);
57
  ~ParentInspectorHandle();
58
  void WorkerStarted(std::shared_ptr<MainThreadHandle> worker_thread,
59
                     bool waiting);
60
322
  bool WaitForConnect() {
61
322
    return wait_;
62
  }
63
64
 private:
65
  int id_;
66
  std::string url_;
67
  std::shared_ptr<MainThreadHandle> parent_thread_;
68
  bool wait_;
69
};
70
71
4032
class WorkerManager : public std::enable_shared_from_this<WorkerManager> {
72
 public:
73
4401
  explicit WorkerManager(std::shared_ptr<MainThreadHandle> thread)
74
4401
                         : thread_(thread) {}
75
76
  std::unique_ptr<ParentInspectorHandle> NewParentHandle(
77
      int thread_id, const std::string& url);
78
  void WorkerStarted(int session_id, const WorkerInfo& info, bool waiting);
79
  void WorkerFinished(int session_id);
80
  std::unique_ptr<WorkerManagerEventHandle> SetAutoAttach(
81
      std::unique_ptr<WorkerDelegate> attach_delegate);
82
  void SetWaitOnStartForDelegate(int id, bool wait);
83
  void RemoveAttachDelegate(int id);
84
4607
  std::shared_ptr<MainThreadHandle> MainThread() {
85
4607
    return thread_;
86
  }
87
88
 private:
89
  std::shared_ptr<MainThreadHandle> thread_;
90
  std::unordered_map<int, WorkerInfo> children_;
91
  std::unordered_map<int, std::unique_ptr<WorkerDelegate>> delegates_;
92
  // If any one needs it, workers stop for all
93
  std::unordered_set<int> delegates_waiting_on_start_;
94
  int next_delegate_id_ = 0;
95
};
96
}  // namespace inspector
97
}  // namespace node
98
99
#endif  // SRC_INSPECTOR_WORKER_INSPECTOR_H_