mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Backed out changeset 725b7db309c3 (bug 1013571) for causing the failures in 1032783
This commit is contained in:
parent
51673d1d22
commit
25c80c8653
@ -21,7 +21,6 @@
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "BackgroundChild.h"
|
||||
#include "GeckoProfiler.h"
|
||||
#include "js/OldDebugAPI.h"
|
||||
#include "jsfriendapi.h"
|
||||
@ -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"
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
@ -913,38 +901,6 @@ private:
|
||||
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;
|
||||
@ -987,9 +943,6 @@ private:
|
||||
~WorkerThreadPrimaryRunnable()
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
SynchronouslyCreatePBackground();
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
};
|
||||
|
||||
@ -1089,28 +1042,6 @@ public:
|
||||
}
|
||||
#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),
|
||||
@ -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;
|
||||
}
|
||||
@ -1609,6 +1536,10 @@ RuntimeService::ScheduleWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
thread->SetAcceptingNonWorkerRunnables(false);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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,
|
||||
@ -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();
|
||||
@ -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);
|
||||
@ -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)
|
||||
|
||||
|
@ -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
|
||||
@ -61,10 +56,6 @@ public:
|
||||
static bool
|
||||
GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback);
|
||||
|
||||
// See above.
|
||||
static void
|
||||
CloseForCurrentThread();
|
||||
|
||||
private:
|
||||
// Only called by ContentChild or ContentParent.
|
||||
static void
|
||||
|
@ -350,8 +350,6 @@ class ChildImpl MOZ_FINAL : public BackgroundChildImpl
|
||||
nsIThread* mBoundThread;
|
||||
#endif
|
||||
|
||||
DebugOnly<bool> mActorDestroyed;
|
||||
|
||||
public:
|
||||
static bool
|
||||
OpenProtocolOnMainThread(nsIEventTarget* aEventTarget);
|
||||
@ -374,15 +372,8 @@ public:
|
||||
THREADSAFETY_ASSERT(current);
|
||||
}
|
||||
|
||||
void
|
||||
AssertActorDestroyed()
|
||||
{
|
||||
MOZ_ASSERT(mActorDestroyed, "ChildImpl::ActorDestroy not called in time");
|
||||
}
|
||||
|
||||
ChildImpl()
|
||||
: mBoundThread(nullptr)
|
||||
, mActorDestroyed(false)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
}
|
||||
@ -406,10 +397,6 @@ private:
|
||||
static bool
|
||||
GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback);
|
||||
|
||||
// Forwarded from BackgroundChild.
|
||||
static void
|
||||
CloseForCurrentThread();
|
||||
|
||||
// Forwarded from BackgroundChildImpl.
|
||||
static BackgroundChildImpl::ThreadLocal*
|
||||
GetThreadLocalForCurrentThread();
|
||||
@ -422,18 +409,6 @@ private:
|
||||
if (threadLocalInfo) {
|
||||
if (threadLocalInfo->mActor) {
|
||||
threadLocalInfo->mActor->Close();
|
||||
threadLocalInfo->mActor->AssertActorDestroyed();
|
||||
|
||||
// Since the actor is created on the main thread it must only
|
||||
// be released on the main thread as well.
|
||||
if (!NS_IsMainThread()) {
|
||||
ChildImpl* actor;
|
||||
threadLocalInfo->mActor.forget(&actor);
|
||||
|
||||
nsCOMPtr<nsIRunnable> releaser =
|
||||
NS_NewNonOwningRunnableMethod(actor, &ChildImpl::Release);
|
||||
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(releaser)));
|
||||
}
|
||||
}
|
||||
delete threadLocalInfo;
|
||||
}
|
||||
@ -444,9 +419,7 @@ private:
|
||||
|
||||
// This class is reference counted.
|
||||
~ChildImpl()
|
||||
{
|
||||
AssertActorDestroyed();
|
||||
}
|
||||
{ }
|
||||
|
||||
void
|
||||
SetBoundThread()
|
||||
@ -862,13 +835,6 @@ BackgroundChild::GetOrCreateForCurrentThread(
|
||||
return ChildImpl::GetOrCreateForCurrentThread(aCallback);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
BackgroundChild::CloseForCurrentThread()
|
||||
{
|
||||
ChildImpl::CloseForCurrentThread();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// BackgroundChildImpl Public Methods
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1612,11 +1578,7 @@ ChildImpl::GetForCurrentThread()
|
||||
auto threadLocalInfo =
|
||||
static_cast<ThreadLocalInfo*>(PR_GetThreadPrivate(sThreadLocalIndex));
|
||||
|
||||
if (!threadLocalInfo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return threadLocalInfo->mActor;
|
||||
return threadLocalInfo ? threadLocalInfo->mActor : nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
@ -1680,33 +1642,6 @@ ChildImpl::GetOrCreateForCurrentThread(
|
||||
return true;
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
ChildImpl::CloseForCurrentThread()
|
||||
{
|
||||
MOZ_ASSERT(sThreadLocalIndex != kBadThreadLocalIndex,
|
||||
"BackgroundChild::Startup() was never called!");
|
||||
auto threadLocalInfo =
|
||||
static_cast<ThreadLocalInfo*>(PR_GetThreadPrivate(sThreadLocalIndex));
|
||||
|
||||
// If we don't have a thread local we are in one of these conditions:
|
||||
// 1) Startup has not completed and we are racing
|
||||
// 2) We were called again after a previous close or shutdown
|
||||
// For now, these should not happen, so crash. We can add extra complexity
|
||||
// in the future if it turns out we need to support these cases.
|
||||
if (!threadLocalInfo) {
|
||||
MOZ_CRASH("Attempting to close a non-existent PBackground actor!");
|
||||
}
|
||||
|
||||
if (threadLocalInfo->mActor) {
|
||||
threadLocalInfo->mActor->FlushPendingInterruptQueue();
|
||||
}
|
||||
|
||||
// Clearing the thread local will synchronously close the actor.
|
||||
DebugOnly<PRStatus> status = PR_SetThreadPrivate(sThreadLocalIndex, nullptr);
|
||||
MOZ_ASSERT(status == PR_SUCCESS);
|
||||
}
|
||||
|
||||
// static
|
||||
BackgroundChildImpl::ThreadLocal*
|
||||
ChildImpl::GetThreadLocalForCurrentThread()
|
||||
@ -2011,9 +1946,6 @@ ChildImpl::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
AssertIsOnBoundThread();
|
||||
|
||||
MOZ_ASSERT(!mActorDestroyed);
|
||||
mActorDestroyed = true;
|
||||
|
||||
BackgroundChildImpl::ActorDestroy(aWhy);
|
||||
}
|
||||
|
||||
|
@ -1662,11 +1662,10 @@ MessageChannel::Close()
|
||||
}
|
||||
|
||||
if (ChannelOpening == mChannelState) {
|
||||
// SynchronouslyClose() waits for an ack from the other side, so
|
||||
// the opening sequence should complete before this returns.
|
||||
// Mimic CloseWithError().
|
||||
SynchronouslyClose();
|
||||
mChannelState = ChannelError;
|
||||
NotifyMaybeChannelError();
|
||||
PostErrorNotifyTask();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsICancelableRunnable.h"
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/logging.h"
|
||||
@ -41,7 +40,7 @@ static mozilla::DebugOnly<MessagePump::Delegate*> gFirstDelegate;
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
class DoWorkRunnable MOZ_FINAL : public nsICancelableRunnable,
|
||||
class DoWorkRunnable MOZ_FINAL : public nsIRunnable,
|
||||
public nsITimerCallback
|
||||
{
|
||||
public:
|
||||
@ -54,15 +53,12 @@ public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIRUNNABLE
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
NS_DECL_NSICANCELABLERUNNABLE
|
||||
|
||||
private:
|
||||
~DoWorkRunnable()
|
||||
{ }
|
||||
|
||||
MessagePump* mPump;
|
||||
// DoWorkRunnable is designed as a stateless singleton. Do not add stateful
|
||||
// members here!
|
||||
};
|
||||
|
||||
} /* namespace ipc */
|
||||
@ -215,8 +211,7 @@ MessagePump::DoDelayedWork(base::MessagePump::Delegate* aDelegate)
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(DoWorkRunnable, nsIRunnable, nsITimerCallback,
|
||||
nsICancelableRunnable)
|
||||
NS_IMPL_ISUPPORTS(DoWorkRunnable, nsIRunnable, nsITimerCallback)
|
||||
|
||||
NS_IMETHODIMP
|
||||
DoWorkRunnable::Run()
|
||||
@ -247,20 +242,6 @@ DoWorkRunnable::Notify(nsITimer* aTimer)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DoWorkRunnable::Cancel()
|
||||
{
|
||||
// Workers require cancelable runnables, but we can't really cancel cleanly
|
||||
// here. If we don't process this runnable then we will leave something
|
||||
// unprocessed in the message_loop. Therefore, eagerly complete our work
|
||||
// instead by immediately calling Run(). Run() should be called separately
|
||||
// after this. Unfortunately we cannot use flags to verify this because
|
||||
// DoWorkRunnable is a stateless singleton that can be in the event queue
|
||||
// multiple times simultaneously.
|
||||
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(Run()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
MessagePumpForChildProcess::Run(base::MessagePump::Delegate* aDelegate)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user