2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-10-27 20:00:05 +03:00
|
|
|
/* 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 "Workers.h"
|
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
#include "nsIObserver.h"
|
2014-10-27 20:00:05 +03:00
|
|
|
#include "nsIWorkerDebuggerManager.h"
|
|
|
|
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2016-03-16 21:51:11 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2014-10-27 20:00:05 +03:00
|
|
|
|
|
|
|
#define WORKERDEBUGGERMANAGER_CID \
|
|
|
|
{ 0x62ec8731, 0x55ad, 0x4246, \
|
|
|
|
{ 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d } }
|
|
|
|
#define WORKERDEBUGGERMANAGER_CONTRACTID \
|
|
|
|
"@mozilla.org/dom/workers/workerdebuggermanager;1"
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class WorkerDebugger;
|
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
class WorkerDebuggerManager final : public nsIObserver,
|
|
|
|
public nsIWorkerDebuggerManager
|
2014-10-27 20:00:05 +03:00
|
|
|
{
|
2016-01-07 15:35:31 +03:00
|
|
|
Mutex mMutex;
|
2014-10-27 20:00:05 +03:00
|
|
|
|
|
|
|
// Protected by mMutex.
|
|
|
|
nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners;
|
|
|
|
|
|
|
|
// Only touched on the main thread.
|
2016-01-07 15:35:31 +03:00
|
|
|
nsTArray<RefPtr<WorkerDebugger>> mDebuggers;
|
2014-10-27 20:00:05 +03:00
|
|
|
|
|
|
|
public:
|
2016-02-10 12:45:02 +03:00
|
|
|
static already_AddRefed<WorkerDebuggerManager>
|
|
|
|
GetInstance();
|
|
|
|
|
2016-02-05 00:04:25 +03:00
|
|
|
static WorkerDebuggerManager*
|
2016-02-10 12:45:02 +03:00
|
|
|
GetOrCreate();
|
|
|
|
|
|
|
|
static WorkerDebuggerManager*
|
|
|
|
Get();
|
2014-10-27 20:00:05 +03:00
|
|
|
|
|
|
|
WorkerDebuggerManager();
|
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2014-10-27 20:00:05 +03:00
|
|
|
NS_DECL_NSIWORKERDEBUGGERMANAGER
|
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
nsresult
|
|
|
|
Init();
|
2015-03-17 13:15:19 +03:00
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
void
|
|
|
|
Shutdown();
|
2014-10-27 20:00:05 +03:00
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
void
|
|
|
|
RegisterDebugger(WorkerPrivate* aWorkerPrivate);
|
2014-10-27 20:00:05 +03:00
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
void
|
|
|
|
RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
|
|
|
|
bool aNotifyListeners);
|
2015-12-22 16:11:27 +03:00
|
|
|
|
2016-02-10 12:45:02 +03:00
|
|
|
void
|
|
|
|
UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
|
2015-12-22 16:11:27 +03:00
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
private:
|
|
|
|
virtual ~WorkerDebuggerManager();
|
2014-10-27 20:00:05 +03:00
|
|
|
};
|
|
|
|
|
2016-02-05 18:09:28 +03:00
|
|
|
inline nsresult
|
|
|
|
RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
2016-02-10 12:45:02 +03:00
|
|
|
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();
|
2014-10-27 20:00:05 +03:00
|
|
|
}
|
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
manager->RegisterDebugger(aWorkerPrivate);
|
2014-10-27 20:00:05 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsresult
|
2016-01-07 15:35:31 +03:00
|
|
|
UnregisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
|
2014-10-27 20:00:05 +03:00
|
|
|
{
|
2016-02-10 12:45:02 +03:00
|
|
|
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();
|
2014-10-27 20:00:05 +03:00
|
|
|
}
|
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
manager->UnregisterDebugger(aWorkerPrivate);
|
2014-10-27 20:00:05 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_workerdebuggermanager_h
|