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"
15 #include "nsIObserver.h"
16 #include "nsISupports.h"
17 #include "nsIWorkerDebuggerManager.h"
20 #define WORKERDEBUGGERMANAGER_CID \
22 0x62ec8731, 0x55ad, 0x4246, { \
23 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d \
26 #define WORKERDEBUGGERMANAGER_CONTRACTID \
27 "@mozilla.org/dom/workers/workerdebuggermanager;1"
35 class WorkerDebuggerManager final
: public nsIObserver
,
36 public nsIWorkerDebuggerManager
{
39 // Protected by mMutex.
40 nsTArray
<nsCOMPtr
<nsIWorkerDebuggerManagerListener
>> mListeners
;
42 // Only touched on the main thread.
43 nsTArray
<RefPtr
<WorkerDebugger
>> mDebuggers
;
46 static already_AddRefed
<WorkerDebuggerManager
> GetInstance();
48 static WorkerDebuggerManager
* GetOrCreate();
50 static WorkerDebuggerManager
* Get();
52 WorkerDebuggerManager();
56 NS_DECL_NSIWORKERDEBUGGERMANAGER
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;
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();
87 NS_WARNING("Failed to create worker debugger manager!");
88 return NS_ERROR_FAILURE
;
91 manager
= WorkerDebuggerManager::Get();
94 manager
->RegisterDebugger(aWorkerPrivate
);
98 inline nsresult
UnregisterWorkerDebugger(WorkerPrivate
* aWorkerPrivate
) {
99 WorkerDebuggerManager
* manager
;
101 if (NS_IsMainThread()) {
102 manager
= WorkerDebuggerManager::GetOrCreate();
104 NS_WARNING("Failed to create worker debugger manager!");
105 return NS_ERROR_FAILURE
;
108 manager
= WorkerDebuggerManager::Get();
111 manager
->UnregisterDebugger(aWorkerPrivate
);
116 } // namespace mozilla
118 #endif // mozilla_dom_workers_workerdebuggermanager_h