Bug 1691109 [wpt PR 27513] - Increase timeout duration for wpt/fetch/api/basic/keepal...
[gecko.git] / dom / workers / WorkerDebuggerManager.h
blob53fe35f1cb5c2b9388f535af9267fde1d8d01a7a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_workers_workerdebuggermanager_h
8 #define mozilla_dom_workers_workerdebuggermanager_h
10 #include "MainThreadUtils.h"
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/Mutex.h"
13 #include "nsCOMPtr.h"
14 #include "nsDebug.h"
15 #include "nsIObserver.h"
16 #include "nsISupports.h"
17 #include "nsIWorkerDebuggerManager.h"
18 #include "nsTArray.h"
20 #define WORKERDEBUGGERMANAGER_CID \
21 { \
22 0x62ec8731, 0x55ad, 0x4246, { \
23 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d \
24 } \
26 #define WORKERDEBUGGERMANAGER_CONTRACTID \
27 "@mozilla.org/dom/workers/workerdebuggermanager;1"
29 namespace mozilla {
30 namespace dom {
32 class WorkerDebugger;
33 class WorkerPrivate;
35 class WorkerDebuggerManager final : public nsIObserver,
36 public nsIWorkerDebuggerManager {
37 Mutex mMutex;
39 // Protected by mMutex.
40 nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners;
42 // Only touched on the main thread.
43 nsTArray<RefPtr<WorkerDebugger>> mDebuggers;
45 public:
46 static already_AddRefed<WorkerDebuggerManager> GetInstance();
48 static WorkerDebuggerManager* GetOrCreate();
50 static WorkerDebuggerManager* Get();
52 WorkerDebuggerManager();
54 NS_DECL_ISUPPORTS
55 NS_DECL_NSIOBSERVER
56 NS_DECL_NSIWORKERDEBUGGERMANAGER
58 nsresult Init();
60 void Shutdown();
62 void RegisterDebugger(WorkerPrivate* aWorkerPrivate);
64 void RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
65 bool aNotifyListeners);
67 void UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
69 void UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
71 uint32_t GetDebuggersLength() const;
73 WorkerDebugger* GetDebuggerAt(uint32_t aIndex) const;
75 private:
76 nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> CloneListeners();
78 virtual ~WorkerDebuggerManager();
81 inline nsresult RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate) {
82 WorkerDebuggerManager* manager;
84 if (NS_IsMainThread()) {
85 manager = WorkerDebuggerManager::GetOrCreate();
86 if (!manager) {
87 NS_WARNING("Failed to create worker debugger manager!");
88 return NS_ERROR_FAILURE;
90 } else {
91 manager = WorkerDebuggerManager::Get();
94 manager->RegisterDebugger(aWorkerPrivate);
95 return NS_OK;
98 inline nsresult UnregisterWorkerDebugger(WorkerPrivate* aWorkerPrivate) {
99 WorkerDebuggerManager* manager;
101 if (NS_IsMainThread()) {
102 manager = WorkerDebuggerManager::GetOrCreate();
103 if (!manager) {
104 NS_WARNING("Failed to create worker debugger manager!");
105 return NS_ERROR_FAILURE;
107 } else {
108 manager = WorkerDebuggerManager::Get();
111 manager->UnregisterDebugger(aWorkerPrivate);
112 return NS_OK;
115 } // namespace dom
116 } // namespace mozilla
118 #endif // mozilla_dom_workers_workerdebuggermanager_h