diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/workers/WorkerDebuggerManager.h | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/workers/WorkerDebuggerManager.h')
-rw-r--r-- | dom/workers/WorkerDebuggerManager.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/dom/workers/WorkerDebuggerManager.h b/dom/workers/WorkerDebuggerManager.h new file mode 100644 index 0000000000..7c22a6b62c --- /dev/null +++ b/dom/workers/WorkerDebuggerManager.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_workers_workerdebuggermanager_h +#define mozilla_dom_workers_workerdebuggermanager_h + +#include "MainThreadUtils.h" +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/Mutex.h" +#include "nsCOMPtr.h" +#include "nsDebug.h" +#include "nsIObserver.h" +#include "nsISupports.h" +#include "nsIWorkerDebuggerManager.h" +#include "nsTArray.h" + +#define WORKERDEBUGGERMANAGER_CID \ + { \ + 0x62ec8731, 0x55ad, 0x4246, { \ + 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d \ + } \ + } +#define WORKERDEBUGGERMANAGER_CONTRACTID \ + "@mozilla.org/dom/workers/workerdebuggermanager;1" + +namespace mozilla::dom { + +class WorkerDebugger; +class WorkerPrivate; + +class WorkerDebuggerManager final : public nsIObserver, + public nsIWorkerDebuggerManager { + Mutex mMutex MOZ_UNANNOTATED; + + // Protected by mMutex. + nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners; + + // Only touched on the main thread. + nsTArray<RefPtr<WorkerDebugger>> mDebuggers; + + public: + static already_AddRefed<WorkerDebuggerManager> GetInstance(); + + static WorkerDebuggerManager* GetOrCreate(); + + static WorkerDebuggerManager* Get(); + + WorkerDebuggerManager(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_NSIWORKERDEBUGGERMANAGER + + nsresult Init(); + + void Shutdown(); + + void RegisterDebugger(WorkerPrivate* aWorkerPrivate); + + void RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate, + bool aNotifyListeners); + + void UnregisterDebugger(WorkerPrivate* aWorkerPrivate); + + void UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate); + + uint32_t GetDebuggersLength() const; + + WorkerDebugger* GetDebuggerAt(uint32_t aIndex) const; + + private: + nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> CloneListeners(); + + virtual ~WorkerDebuggerManager(); +}; + +inline nsresult RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate) { + WorkerDebuggerManager* manager; + + if (NS_IsMainThread()) { + manager = WorkerDebuggerManager::GetOrCreate(); + if (!manager) { + NS_WARNING("Failed to create worker debugger manager!"); + return NS_ERROR_FAILURE; + } + } else { + manager = WorkerDebuggerManager::Get(); + } + + manager->RegisterDebugger(aWorkerPrivate); + return NS_OK; +} + +inline nsresult UnregisterWorkerDebugger(WorkerPrivate* aWorkerPrivate) { + WorkerDebuggerManager* manager; + + if (NS_IsMainThread()) { + manager = WorkerDebuggerManager::GetOrCreate(); + if (!manager) { + NS_WARNING("Failed to create worker debugger manager!"); + return NS_ERROR_FAILURE; + } + } else { + manager = WorkerDebuggerManager::Get(); + } + + manager->UnregisterDebugger(aWorkerPrivate); + return NS_OK; +} + +} // namespace mozilla::dom + +#endif // mozilla_dom_workers_workerdebuggermanager_h |