Skip to content

Commit

Permalink
Backed out changeset 725b7db309c3 (bug 1013571) for causing the failu…
Browse files Browse the repository at this point in the history
…res in 1032783
  • Loading branch information
KWierso committed Jul 8, 2014
1 parent 960777d commit 1386772
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 244 deletions.
146 changes: 5 additions & 141 deletions dom/workers/RuntimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "nsPIDOMWindow.h"

#include <algorithm>
#include "BackgroundChild.h"
#include "GeckoProfiler.h"
#include "js/OldDebugAPI.h"
#include "jsfriendapi.h"
Expand All @@ -41,7 +40,6 @@
#include "nsContentUtils.h"
#include "nsCycleCollector.h"
#include "nsDOMJSUtils.h"
#include "nsIIPCBackgroundChildCreateCallback.h"
#include "nsISupportsImpl.h"
#include "nsLayoutStatics.h"
#include "nsNetUtil.h"
Expand All @@ -66,12 +64,6 @@
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"

#ifdef ENABLE_TESTS
#include "BackgroundChildImpl.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "prrng.h"
#endif

using namespace mozilla;
using namespace mozilla::dom;

Expand Down Expand Up @@ -169,10 +161,6 @@ RuntimeService* gRuntimeService = nullptr;
// Only non-null during the call to Init.
RuntimeService* gRuntimeServiceDuringInit = nullptr;

#ifdef ENABLE_TESTS
bool gTestPBackground = false;
#endif // ENABLE_TESTS

enum {
ID_Worker = 0,
ID_ChromeWorker,
Expand Down Expand Up @@ -913,38 +901,6 @@ class WorkerJSRuntime : public mozilla::CycleCollectedJSRuntime
WorkerPrivate* mWorkerPrivate;
};

class WorkerBackgroundChildCallback MOZ_FINAL :
public nsIIPCBackgroundChildCreateCallback
{
bool* mDone;

public:
WorkerBackgroundChildCallback(bool* aDone)
: mDone(aDone)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(mDone);
}

NS_DECL_ISUPPORTS

private:
~WorkerBackgroundChildCallback()
{ }

virtual void
ActorCreated(PBackgroundChild* aActor) MOZ_OVERRIDE
{
*mDone = true;
}

virtual void
ActorFailed() MOZ_OVERRIDE
{
*mDone = true;
}
};

class WorkerThreadPrimaryRunnable MOZ_FINAL : public nsRunnable
{
WorkerPrivate* mWorkerPrivate;
Expand Down Expand Up @@ -987,9 +943,6 @@ class WorkerThreadPrimaryRunnable MOZ_FINAL : public nsRunnable
~WorkerThreadPrimaryRunnable()
{ }

nsresult
SynchronouslyCreatePBackground();

NS_DECL_NSIRUNNABLE
};

Expand Down Expand Up @@ -1089,28 +1042,6 @@ class RuntimeService::WorkerThread MOZ_FINAL : public nsThread
}
#endif

#ifdef ENABLE_TESTS
void
TestPBackground()
{
using namespace mozilla::ipc;
if (gTestPBackground) {
// Randomize value to validate workers are not cross-posting messages.
uint32_t testValue;
PRSize randomSize = PR_GetRandomNoise(&testValue, sizeof(testValue));
MOZ_RELEASE_ASSERT(randomSize == sizeof(testValue));
nsCString testStr;
testStr.AppendInt(testValue);
testStr.AppendInt(reinterpret_cast<int64_t>(PR_GetCurrentThread()));
PBackgroundChild* existingBackgroundChild =
BackgroundChild::GetForCurrentThread();
MOZ_RELEASE_ASSERT(existingBackgroundChild);
bool ok = existingBackgroundChild->SendPBackgroundTestConstructor(testStr);
MOZ_RELEASE_ASSERT(ok);
}
}
#endif // #ENABLE_TESTS

private:
WorkerThread()
: nsThread(nsThread::NOT_MAIN_THREAD, WORKER_STACK_SIZE),
Expand Down Expand Up @@ -1316,10 +1247,6 @@ RuntimeService::GetOrCreateService()
return nullptr;
}

#ifdef ENABLE_TESTS
gTestPBackground = mozilla::Preferences::GetBool("pbackground.testing", false);
#endif // ENABLE_TESTS

// The observer service now owns us until shutdown.
gRuntimeService = service;
}
Expand Down Expand Up @@ -1609,6 +1536,10 @@ RuntimeService::ScheduleWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
return false;
}

#ifdef DEBUG
thread->SetAcceptingNonWorkerRunnables(false);
#endif

return true;
}

Expand Down Expand Up @@ -2597,20 +2528,8 @@ RuntimeService::WorkerThread::Observer::OnProcessNextEvent(
bool aMayWait,
uint32_t aRecursionDepth)
{
using mozilla::ipc::BackgroundChild;

mWorkerPrivate->AssertIsOnWorkerThread();

// If the PBackground child is not created yet, then we must permit
// blocking event processing to support SynchronouslyCreatePBackground().
// If this occurs then we are spinning on the event queue at the start of
// PrimaryWorkerRunnable::Run() and don't want to process the event in
// mWorkerPrivate yet.
if (aMayWait) {
MOZ_ASSERT(aRecursionDepth == 2);
MOZ_ASSERT(!BackgroundChild::GetForCurrentThread());
return NS_OK;
}
MOZ_ASSERT(!aMayWait);

mWorkerPrivate->OnProcessNextEvent(aRecursionDepth);
return NS_OK;
Expand Down Expand Up @@ -2654,15 +2573,11 @@ LogViolationDetailsRunnable::Run()
return NS_OK;
}

NS_IMPL_ISUPPORTS(WorkerBackgroundChildCallback, nsIIPCBackgroundChildCreateCallback)

NS_IMPL_ISUPPORTS_INHERITED0(WorkerThreadPrimaryRunnable, nsRunnable)

NS_IMETHODIMP
WorkerThreadPrimaryRunnable::Run()
{
using mozilla::ipc::BackgroundChild;

#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess()) {
NS_ASSERTION(NuwaMarkCurrentThread != nullptr,
Expand All @@ -2681,19 +2596,6 @@ WorkerThreadPrimaryRunnable::Run()

profiler_register_thread(threadName.get(), &stackBaseGuess);

// Note: SynchronouslyCreatePBackground() must be called prior to
// mThread->SetWorker() in order to avoid accidentally consuming
// worker messages here.
nsresult rv = SynchronouslyCreatePBackground();
if (NS_WARN_IF(NS_FAILED(rv))) {
// XXX need to fire an error at parent.
return rv;
}

#ifdef ENABLE_TESTS
mThread->TestPBackground();
#endif

mThread->SetWorker(mWorkerPrivate);

mWorkerPrivate->AssertIsOnWorkerThread();
Expand Down Expand Up @@ -2727,12 +2629,6 @@ WorkerThreadPrimaryRunnable::Run()
JS_ReportPendingException(cx);
}

#ifdef ENABLE_TESTS
mThread->TestPBackground();
#endif

BackgroundChild::CloseForCurrentThread();

#ifdef MOZ_ENABLE_PROFILER_SPS
if (stack) {
stack->sampleRuntime(nullptr);
Expand Down Expand Up @@ -2771,38 +2667,6 @@ WorkerThreadPrimaryRunnable::Run()
return NS_OK;
}

nsresult
WorkerThreadPrimaryRunnable::SynchronouslyCreatePBackground()
{
using mozilla::ipc::BackgroundChild;

MOZ_ASSERT(!BackgroundChild::GetForCurrentThread());

bool done = false;
nsCOMPtr<nsIIPCBackgroundChildCreateCallback> callback =
new WorkerBackgroundChildCallback(&done);

if (NS_WARN_IF(!BackgroundChild::GetOrCreateForCurrentThread(callback))) {
return NS_ERROR_FAILURE;
}

while (!done) {
if (NS_WARN_IF(!NS_ProcessNextEvent(mThread, true /* aMayWait */))) {
return NS_ERROR_FAILURE;
}
}

if (NS_WARN_IF(!BackgroundChild::GetForCurrentThread())) {
return NS_ERROR_FAILURE;
}

#ifdef DEBUG
mThread->SetAcceptingNonWorkerRunnables(false);
#endif

return NS_OK;
}

NS_IMPL_ISUPPORTS_INHERITED0(WorkerThreadPrimaryRunnable::FinishedRunnable,
nsRunnable)

Expand Down
9 changes: 0 additions & 9 deletions ipc/glue/BackgroundChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class PBackgroundChild;
// (assuming success) GetForCurrentThread() will return the same actor every
// time.
//
// CloseForCurrentThread() will close the current PBackground actor. Subsequent
// calls to GetForCurrentThread will return null. CloseForCurrentThread() may
// only be called exactly once for each thread-specific actor. Currently it is
// illegal to call this before the PBackground actor has been created.
//
// The PBackgroundChild actor and all its sub-protocol actors will be
// automatically destroyed when its designated thread completes.
class BackgroundChild MOZ_FINAL
Expand All @@ -61,10 +56,6 @@ class BackgroundChild MOZ_FINAL
static bool
GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback);

// See above.
static void
CloseForCurrentThread();

private:
// Only called by ContentChild or ContentParent.
static void
Expand Down
Loading

0 comments on commit 1386772

Please sign in to comment.