2015-05-03 12:32:37 -07: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 10:00:05 -07: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"
|
|
|
|
|
|
|
|
#include "nsIWorkerDebuggerManager.h"
|
|
|
|
|
|
|
|
#include "nsServiceManagerUtils.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"
|
|
|
|
|
2015-12-22 05:11:27 -08:00
|
|
|
class RegisterDebuggerRunnable;
|
|
|
|
|
2014-10-27 10:00:05 -07:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class WorkerDebugger;
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class WorkerDebuggerManager final : public nsIWorkerDebuggerManager
|
2014-10-27 10:00:05 -07:00
|
|
|
{
|
2015-12-22 05:11:27 -08:00
|
|
|
friend class ::RegisterDebuggerRunnable;
|
|
|
|
|
|
|
|
mozilla::Mutex mMutex;
|
2014-10-27 10:00:05 -07:00
|
|
|
|
|
|
|
// Protected by mMutex.
|
|
|
|
nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners;
|
|
|
|
|
|
|
|
// Only touched on the main thread.
|
2015-12-22 05:11:27 -08:00
|
|
|
nsTArray<WorkerDebugger*> mDebuggers;
|
2014-10-27 10:00:05 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
static WorkerDebuggerManager*
|
|
|
|
GetOrCreateService()
|
|
|
|
{
|
2015-03-17 03:15:19 -07:00
|
|
|
nsCOMPtr<nsIWorkerDebuggerManager> manager =
|
2014-10-27 10:00:05 -07:00
|
|
|
do_GetService(WORKERDEBUGGERMANAGER_CONTRACTID);
|
2015-03-17 03:15:19 -07:00
|
|
|
return static_cast<WorkerDebuggerManager*>(manager.get());
|
2014-10-27 10:00:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
WorkerDebuggerManager();
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIWORKERDEBUGGERMANAGER
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
void ClearListeners();
|
|
|
|
|
2015-12-22 05:11:27 -08:00
|
|
|
void RegisterDebugger(WorkerDebugger* aDebugger);
|
2014-10-27 10:00:05 -07:00
|
|
|
|
2015-12-22 05:11:27 -08:00
|
|
|
void UnregisterDebugger(WorkerDebugger* aDebugger);
|
2014-10-27 10:00:05 -07:00
|
|
|
|
2015-12-22 03:46:57 -08:00
|
|
|
private:
|
|
|
|
virtual ~WorkerDebuggerManager();
|
2015-12-22 05:11:27 -08:00
|
|
|
|
|
|
|
void RegisterDebuggerOnMainThread(WorkerDebugger* aDebugger,
|
|
|
|
bool aHasListeners);
|
|
|
|
|
|
|
|
void UnregisterDebuggerOnMainThread(WorkerDebugger* aDebugger);
|
2014-10-27 10:00:05 -07:00
|
|
|
};
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
inline nsresult
|
|
|
|
ClearWorkerDebuggerManagerListeners()
|
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<WorkerDebuggerManager> manager =
|
2015-03-17 03:15:19 -07:00
|
|
|
WorkerDebuggerManager::GetOrCreateService();
|
|
|
|
if (!manager) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->ClearListeners();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-27 10:00:05 -07:00
|
|
|
inline nsresult
|
2015-12-22 05:11:27 -08:00
|
|
|
RegisterWorkerDebugger(WorkerDebugger* aDebugger)
|
2014-10-27 10:00:05 -07:00
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<WorkerDebuggerManager> manager =
|
2014-10-27 10:00:05 -07:00
|
|
|
WorkerDebuggerManager::GetOrCreateService();
|
|
|
|
if (!manager) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-12-22 05:11:27 -08:00
|
|
|
manager->RegisterDebugger(aDebugger);
|
2014-10-27 10:00:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsresult
|
2015-12-22 05:11:27 -08:00
|
|
|
UnregisterWorkerDebugger(WorkerDebugger* aDebugger)
|
2014-10-27 10:00:05 -07:00
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<WorkerDebuggerManager> manager =
|
2014-10-27 10:00:05 -07:00
|
|
|
WorkerDebuggerManager::GetOrCreateService();
|
|
|
|
if (!manager) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-12-22 05:11:27 -08:00
|
|
|
manager->UnregisterDebugger(aDebugger);
|
2014-10-27 10:00:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_workerdebuggermanager_h
|