1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_workers_workerdebuggermanager_h
7 #define mozilla_dom_workers_workerdebuggermanager_h
11 #include "nsIWorkerDebuggerManager.h"
13 #include "nsServiceManagerUtils.h"
16 #define WORKERDEBUGGERMANAGER_CID \
17 { 0x62ec8731, 0x55ad, 0x4246, \
18 { 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d } }
19 #define WORKERDEBUGGERMANAGER_CONTRACTID \
20 "@mozilla.org/dom/workers/workerdebuggermanager;1"
22 class RegisterDebuggerRunnable
;
24 BEGIN_WORKERS_NAMESPACE
28 class WorkerDebuggerManager MOZ_FINAL
: public nsIWorkerDebuggerManager
30 friend class ::RegisterDebuggerRunnable
;
32 mozilla::Mutex mMutex
;
34 // Protected by mMutex.
35 nsTArray
<nsCOMPtr
<nsIWorkerDebuggerManagerListener
>> mListeners
;
37 // Only touched on the main thread.
38 nsTArray
<WorkerDebugger
*> mDebuggers
;
41 static WorkerDebuggerManager
*
44 nsCOMPtr
<nsIWorkerDebuggerManager
> wdm
=
45 do_GetService(WORKERDEBUGGERMANAGER_CONTRACTID
);
46 return static_cast<WorkerDebuggerManager
*>(wdm
.get());
49 WorkerDebuggerManager();
51 NS_DECL_THREADSAFE_ISUPPORTS
52 NS_DECL_NSIWORKERDEBUGGERMANAGER
54 void RegisterDebugger(WorkerDebugger
* aDebugger
);
56 void UnregisterDebugger(WorkerDebugger
* aDebugger
);
59 virtual ~WorkerDebuggerManager();
61 void RegisterDebuggerOnMainThread(WorkerDebugger
* aDebugger
,
64 void UnregisterDebuggerOnMainThread(WorkerDebugger
* aDebugger
);
68 RegisterWorkerDebugger(WorkerDebugger
* aDebugger
)
70 nsRefPtr
<WorkerDebuggerManager
> manager
=
71 WorkerDebuggerManager::GetOrCreateService();
73 return NS_ERROR_FAILURE
;
76 manager
->RegisterDebugger(aDebugger
);
81 UnregisterWorkerDebugger(WorkerDebugger
* aDebugger
)
83 nsRefPtr
<WorkerDebuggerManager
> manager
=
84 WorkerDebuggerManager::GetOrCreateService();
86 return NS_ERROR_FAILURE
;
89 manager
->UnregisterDebugger(aDebugger
);
95 #endif // mozilla_dom_workers_workerdebuggermanager_h