Backed out changeset a6bc2efcdf26 (bug 1212333) for bustage

This commit is contained in:
Carsten "Tomcat" Book 2016-02-05 16:09:28 +01:00
parent d24491b6d8
commit 940ea6bf9d
4 changed files with 58 additions and 132 deletions

View File

@ -1974,6 +1974,12 @@ RuntimeService::Shutdown()
// That's it, no more workers.
mShuttingDown = true;
// Remove all listeners from the worker debugger manager to ensure that it
// gets properly destroyed.
if (NS_FAILED(ClearWorkerDebuggerManagerListeners())) {
NS_WARNING("Failed to clear worker debugger manager listeners!");
}
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_WARN_IF_FALSE(obs, "Failed to get observer service?!");

View File

@ -8,23 +8,22 @@
#include "nsISimpleEnumerator.h"
#include "mozilla/ClearOnShutdown.h"
#include "WorkerPrivate.h"
USING_WORKERS_NAMESPACE
namespace {
class RegisterDebuggerMainThreadRunnable final : public nsRunnable
{
RefPtr<WorkerDebuggerManager> mManager;
WorkerPrivate* mWorkerPrivate;
bool mNotifyListeners;
public:
RegisterDebuggerMainThreadRunnable(WorkerPrivate* aWorkerPrivate,
RegisterDebuggerMainThreadRunnable(WorkerDebuggerManager* aManager,
WorkerPrivate* aWorkerPrivate,
bool aNotifyListeners)
: mWorkerPrivate(aWorkerPrivate),
: mManager(aManager),
mWorkerPrivate(aWorkerPrivate),
mNotifyListeners(aNotifyListeners)
{ }
@ -35,21 +34,21 @@ private:
NS_IMETHOD
Run() override
{
WorkerDebuggerManager* manager = WorkerDebuggerManager::Get();
MOZ_ASSERT(manager);
mManager->RegisterDebuggerMainThread(mWorkerPrivate, mNotifyListeners);
manager->RegisterDebuggerMainThread(mWorkerPrivate, mNotifyListeners);
return NS_OK;
}
};
class UnregisterDebuggerMainThreadRunnable final : public nsRunnable
{
RefPtr<WorkerDebuggerManager> mManager;
WorkerPrivate* mWorkerPrivate;
public:
UnregisterDebuggerMainThreadRunnable(WorkerPrivate* aWorkerPrivate)
: mWorkerPrivate(aWorkerPrivate)
UnregisterDebuggerMainThreadRunnable(WorkerDebuggerManager* aManager,
WorkerPrivate* aWorkerPrivate)
: mManager(aManager), mWorkerPrivate(aWorkerPrivate)
{ }
private:
@ -59,19 +58,12 @@ private:
NS_IMETHOD
Run() override
{
WorkerDebuggerManager* manager = WorkerDebuggerManager::Get();
MOZ_ASSERT(manager);
mManager->UnregisterDebuggerMainThread(mWorkerPrivate);
manager->UnregisterDebuggerMainThread(mWorkerPrivate);
return NS_OK;
}
};
// Does not hold an owning reference.
static WorkerDebuggerManager* gWorkerDebuggerManager;
} /* anonymous namespace */
BEGIN_WORKERS_NAMESPACE
class WorkerDebuggerEnumerator final : public nsISimpleEnumerator
@ -124,54 +116,7 @@ WorkerDebuggerManager::~WorkerDebuggerManager()
AssertIsOnMainThread();
}
// static
already_AddRefed<WorkerDebuggerManager>
WorkerDebuggerManager::GetInstance()
{
RefPtr<WorkerDebuggerManager> manager = WorkerDebuggerManager::GetOrCreate();
return manager.forget();
}
// static
WorkerDebuggerManager*
WorkerDebuggerManager::GetOrCreate()
{
AssertIsOnMainThread();
if (!gWorkerDebuggerManager) {
// The observer service now owns us until shutdown.
gWorkerDebuggerManager = new WorkerDebuggerManager();
if (NS_FAILED(gWorkerDebuggerManager->Init())) {
NS_WARNING("Failed to initialize worker debugger manager!");
gWorkerDebuggerManager = nullptr;
return nullptr;
}
}
return gWorkerDebuggerManager;
}
WorkerDebuggerManager*
WorkerDebuggerManager::Get()
{
MOZ_ASSERT(gWorkerDebuggerManager);
return gWorkerDebuggerManager;
}
NS_IMPL_ISUPPORTS(WorkerDebuggerManager, nsIObserver, nsIWorkerDebuggerManager);
NS_IMETHODIMP
WorkerDebuggerManager::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
Shutdown();
return NS_OK;
}
NS_NOTREACHED("Unknown observer topic!");
return NS_OK;
}
NS_IMPL_ISUPPORTS(WorkerDebuggerManager, nsIWorkerDebuggerManager);
NS_IMETHODIMP
WorkerDebuggerManager::GetWorkerDebuggerEnumerator(
@ -216,20 +161,8 @@ WorkerDebuggerManager::RemoveListener(
return NS_OK;
}
nsresult
WorkerDebuggerManager::Init()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_ERROR_FAILURE);
nsresult rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
void
WorkerDebuggerManager::Shutdown()
WorkerDebuggerManager::ClearListeners()
{
AssertIsOnMainThread();
@ -272,7 +205,8 @@ WorkerDebuggerManager::RegisterDebugger(WorkerPrivate* aWorkerPrivate)
}
nsCOMPtr<nsIRunnable> runnable =
new RegisterDebuggerMainThreadRunnable(aWorkerPrivate, hasListeners);
new RegisterDebuggerMainThreadRunnable(this, aWorkerPrivate,
hasListeners);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL)));
@ -291,7 +225,7 @@ WorkerDebuggerManager::UnregisterDebugger(WorkerPrivate* aWorkerPrivate)
UnregisterDebuggerMainThread(aWorkerPrivate);
} else {
nsCOMPtr<nsIRunnable> runnable =
new UnregisterDebuggerMainThreadRunnable(aWorkerPrivate);
new UnregisterDebuggerMainThreadRunnable(this, aWorkerPrivate);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL)));

View File

@ -9,7 +9,6 @@
#include "Workers.h"
#include "nsIObserver.h"
#include "nsIWorkerDebuggerManager.h"
#include "nsServiceManagerUtils.h"
@ -25,8 +24,7 @@ BEGIN_WORKERS_NAMESPACE
class WorkerDebugger;
class WorkerDebuggerManager final : public nsIObserver,
public nsIWorkerDebuggerManager
class WorkerDebuggerManager final : public nsIWorkerDebuggerManager
{
Mutex mMutex;
@ -37,58 +35,54 @@ class WorkerDebuggerManager final : public nsIObserver,
nsTArray<RefPtr<WorkerDebugger>> mDebuggers;
public:
static already_AddRefed<WorkerDebuggerManager>
GetInstance();
static WorkerDebuggerManager*
GetOrCreate();
static WorkerDebuggerManager*
Get();
GetOrCreateService()
{
nsCOMPtr<nsIWorkerDebuggerManager> manager =
do_GetService(WORKERDEBUGGERMANAGER_CONTRACTID);
return static_cast<WorkerDebuggerManager*>(manager.get());
}
WorkerDebuggerManager();
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIWORKERDEBUGGERMANAGER
nsresult
Init();
void ClearListeners();
void
Shutdown();
void RegisterDebugger(WorkerPrivate* aWorkerPrivate);
void
RegisterDebugger(WorkerPrivate* aWorkerPrivate);
void UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
void
RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
bool aNotifyListeners);
void RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
bool aNotifyListeners);
void
UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
void
UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
void UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
private:
virtual ~WorkerDebuggerManager();
};
inline nsresult
ClearWorkerDebuggerManagerListeners()
{
RefPtr<WorkerDebuggerManager> manager =
WorkerDebuggerManager::GetOrCreateService();
if (!manager) {
return NS_ERROR_FAILURE;
}
manager->ClearListeners();
return NS_OK;
}
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();
RefPtr<WorkerDebuggerManager> manager =
WorkerDebuggerManager::GetOrCreateService();
if (!manager) {
return NS_ERROR_FAILURE;
}
manager->RegisterDebugger(aWorkerPrivate);
@ -98,17 +92,10 @@ RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
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();
RefPtr<WorkerDebuggerManager> manager =
WorkerDebuggerManager::GetOrCreateService();
if (!manager) {
return NS_ERROR_FAILURE;
}
manager->UnregisterDebugger(aWorkerPrivate);

View File

@ -322,8 +322,7 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(QuotaManagerService,
QuotaManagerService::FactoryCreate)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ServiceWorkerManager,
ServiceWorkerManager::GetInstance)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(WorkerDebuggerManager,
WorkerDebuggerManager::GetInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(WorkerDebuggerManager)
#ifdef MOZ_WIDGET_GONK
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemWorkerManager,