Skip to content

Commit

Permalink
Backout change 39e167bbd14c, a80140872ea5, adae9be2294d and b71ccef9c…
Browse files Browse the repository at this point in the history
…674 (bug 970307).
  • Loading branch information
Cervantes Yu committed May 19, 2015
1 parent 836d8fd commit 55152ad
Show file tree
Hide file tree
Showing 24 changed files with 27 additions and 598 deletions.
9 changes: 2 additions & 7 deletions dom/apps/AppsServiceChild.jsm
Expand Up @@ -103,20 +103,13 @@ this.DOMApplicationRegistry = {
this.cpmm.addMessageListener(aMsgName, this);
}).bind(this));

this.resetList();

Services.obs.addObserver(this, "xpcom-shutdown", false);
},

resetList: function() {
this.cpmm.sendAsyncMessage("Webapps:RegisterForMessages", {
messages: APPS_IPC_MSG_NAMES
});

// We need to prime the cache with the list of apps.
let list = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0];
this.webapps = list.webapps;

// We need a fast mapping from localId -> app, so we add an index.
// We also add the manifest to the app object.
this.localIdIndex = { };
Expand All @@ -125,6 +118,8 @@ this.DOMApplicationRegistry = {
this.localIdIndex[app.localId] = app;
app.manifest = list.manifests[id];
}

Services.obs.addObserver(this, "xpcom-shutdown", false);
},

observe: function(aSubject, aTopic, aData) {
Expand Down
79 changes: 19 additions & 60 deletions dom/ipc/ContentChild.cpp
Expand Up @@ -538,12 +538,6 @@ NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback)

ContentChild* ContentChild::sSingleton;

static void
PostForkPreload()
{
TabChild::PostForkPreload();
}

// Performs initialization that is not fork-safe, i.e. that must be done after
// forking from the Nuwa process.
static void
Expand All @@ -554,7 +548,6 @@ InitOnContentProcessCreated()
if (IsNuwaProcess()) {
return;
}
PostForkPreload();

nsCOMPtr<nsIPermissionManager> permManager =
services::GetPermissionManager();
Expand Down Expand Up @@ -1356,6 +1349,7 @@ ContentChild::RecvPBrowserConstructor(PBrowserChild* aActor,
{
// This runs after AllocPBrowserChild() returns and the IPC machinery for this
// PBrowserChild has been set up.

nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
nsITabChild* tc =
Expand Down Expand Up @@ -2201,11 +2195,8 @@ bool
ContentChild::RecvFlushMemory(const nsString& reason)
{
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess() || ManagedPBrowserChild().Length() == 0) {
if (IsNuwaProcess()) {
// Don't flush memory in the nuwa process: the GC thread could be frozen.
// If there's no PBrowser child, don't flush memory, either. GC writes
// to copy-on-write pages and makes preallocated process take more memory
// before it actually becomes an app.
return true;
}
#endif
Expand Down Expand Up @@ -2299,35 +2290,20 @@ ContentChild::RecvAppInit()
// BrowserElementChild.js.
if ((mIsForApp || mIsForBrowser)
#ifdef MOZ_NUWA_PROCESS
&& IsNuwaProcess()
&& !IsNuwaProcess()
#endif
) {
PreloadSlowThings();
#ifndef MOZ_NUWA_PROCESS
PostForkPreload();
#endif
}

#ifdef MOZ_NUWA_PROCESS
// Some modules are initialized in preloading. We need to wait until the
// tasks they dispatched to chrome process are done.
if (IsNuwaProcess()) {
SendNuwaWaitForFreeze();
}
#endif
return true;
}

bool
ContentChild::RecvNuwaFreeze()
{
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess()) {
ContentChild::GetSingleton()->RecvGarbageCollect();
MessageLoop::current()->PostTask(
FROM_HERE, NewRunnableFunction(OnFinishNuwaPreparation));
}
#endif

return true;
}

Expand Down Expand Up @@ -2604,36 +2580,6 @@ RunNuwaFork()
DoNuwaFork();
}
}

class NuwaForkCaller: public nsRunnable
{
public:
NS_IMETHODIMP
Run() {
// We want to ensure that the PBackground actor gets cloned in the Nuwa
// process before we freeze. Also, we have to do this to avoid deadlock.
// Protocols that are "opened" (e.g. PBackground, PCompositor) block the
// main thread to wait for the IPC thread during the open operation.
// NuwaSpawnWait() blocks the IPC thread to wait for the main thread when
// the Nuwa process is forked. Unless we ensure that the two cannot happen
// at the same time then we risk deadlock. Spinning the event loop here
// guarantees the ordering is safe for PBackground.
if (!BackgroundChild::GetForCurrentThread()) {
// Dispatch ourself again.
NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL);
} else {
MessageLoop* ioloop = XRE_GetIOMessageLoop();
ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork));
}
return NS_OK;
}
private:
virtual
~NuwaForkCaller()
{
}
};

#endif

bool
Expand All @@ -2645,9 +2591,22 @@ ContentChild::RecvNuwaFork()
}
sNuwaForking = true;

nsRefPtr<NuwaForkCaller> runnable = new NuwaForkCaller();
NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL);
// We want to ensure that the PBackground actor gets cloned in the Nuwa
// process before we freeze. Also, we have to do this to avoid deadlock.
// Protocols that are "opened" (e.g. PBackground, PCompositor) block the
// main thread to wait for the IPC thread during the open operation.
// NuwaSpawnWait() blocks the IPC thread to wait for the main thread when
// the Nuwa process is forked. Unless we ensure that the two cannot happen
// at the same time then we risk deadlock. Spinning the event loop here
// guarantees the ordering is safe for PBackground.
while (!BackgroundChild::GetForCurrentThread()) {
if (NS_WARN_IF(!NS_ProcessNextEvent())) {
return false;
}
}

MessageLoop* ioloop = XRE_GetIOMessageLoop();
ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork));
return true;
#else
return false; // Makes the underlying IPC channel abort.
Expand Down
2 changes: 0 additions & 2 deletions dom/ipc/ContentChild.h
Expand Up @@ -379,8 +379,6 @@ class ContentChild final : public PContentChild

virtual bool RecvNotifyPhoneStateChange(const nsString& state) override;

virtual bool RecvNuwaFreeze() override;

void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS);
void RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS);
virtual bool RecvNotifyIdleObserver(const uint64_t& aObserver,
Expand Down
40 changes: 1 addition & 39 deletions dom/ipc/ContentParent.cpp
Expand Up @@ -140,7 +140,6 @@
#include "nsServiceManagerUtils.h"
#include "nsStyleSheetService.h"
#include "nsThreadUtils.h"
#include "nsThreadManager.h"
#include "nsToolkitCompsCID.h"
#include "nsWidgetsCID.h"
#include "PreallocatedProcessManager.h"
Expand Down Expand Up @@ -1563,28 +1562,6 @@ StaticAutoPtr<LinkedList<SystemMessageHandledListener> >
NS_IMPL_ISUPPORTS(SystemMessageHandledListener,
nsITimerCallback)

#ifdef MOZ_NUWA_PROCESS
class NuwaFreezeListener : public nsThreadManager::AllThreadsWereIdleListener
{
public:
NuwaFreezeListener(ContentParent* parent)
: mParent(parent)
{
}

void OnAllThreadsWereIdle()
{
unused << mParent->SendNuwaFreeze();
nsThreadManager::get()->RemoveAllThreadsWereIdleListener(this);
}
private:
nsRefPtr<ContentParent> mParent;
virtual ~NuwaFreezeListener()
{
}
};
#endif // MOZ_NUWA_PROCESS

} // anonymous namespace

void
Expand Down Expand Up @@ -2362,8 +2339,6 @@ ContentParent::ContentParent(ContentParent* aTemplate,
priority = PROCESS_PRIORITY_FOREGROUND;
}

mSendPermissionUpdates = aTemplate->mSendPermissionUpdates;

InitInternal(priority,
false, /* Setup Off-main thread compositing */
false /* Send registered chrome */);
Expand Down Expand Up @@ -2527,7 +2502,7 @@ ContentParent::IsForApp()

#ifdef MOZ_NUWA_PROCESS
bool
ContentParent::IsNuwaProcess() const
ContentParent::IsNuwaProcess()
{
return mIsNuwaProcess;
}
Expand Down Expand Up @@ -2902,19 +2877,6 @@ ContentParent::RecvNuwaReady()
#endif
}

bool
ContentParent::RecvNuwaWaitForFreeze()
{
#ifdef MOZ_NUWA_PROCESS
nsRefPtr<NuwaFreezeListener> listener = new NuwaFreezeListener(this);
nsThreadManager::get()->AddAllThreadsWereIdleListener(listener);
return true;
#else // MOZ_NUWA_PROCESS
NS_ERROR("ContentParent::RecvNuwaWaitForFreeze() not implemented!");
return false;
#endif // MOZ_NUWA_PROCESS
}

bool
ContentParent::RecvAddNewProcess(const uint32_t& aPid,
InfallibleTArray<ProtocolFdMapping>&& aFds)
Expand Down
8 changes: 1 addition & 7 deletions dom/ipc/ContentParent.h
Expand Up @@ -233,7 +233,7 @@ class ContentParent final : public PContentParent
return mIsForBrowser;
}
#ifdef MOZ_NUWA_PROCESS
bool IsNuwaProcess() const;
bool IsNuwaProcess();
#endif

GeckoChildProcessHost* Process() {
Expand All @@ -247,11 +247,7 @@ class ContentParent final : public PContentParent
}

bool NeedsPermissionsUpdate() const {
#ifdef MOZ_NUWA_PROCESS
return !IsNuwaProcess() && mSendPermissionUpdates;
#else
return mSendPermissionUpdates;
#endif
}

bool NeedsDataStoreInfos() const {
Expand Down Expand Up @@ -783,8 +779,6 @@ class ContentParent final : public PContentParent

virtual bool RecvNuwaReady() override;

virtual bool RecvNuwaWaitForFreeze() override;

virtual bool RecvAddNewProcess(const uint32_t& aPid,
InfallibleTArray<ProtocolFdMapping>&& aFds) override;

Expand Down
4 changes: 0 additions & 4 deletions dom/ipc/PContent.ipdl
Expand Up @@ -632,7 +632,6 @@ child:
InvokeDragSession(IPCDataTransfer[] transfers, uint32_t action);

EndDragSession(bool aDoneDrag, bool aUserCancelled);
NuwaFreeze();

async DomainSetChanged(uint32_t aSetType, uint32_t aChangeType, OptionalURIParams aDomain);

Expand Down Expand Up @@ -899,9 +898,6 @@ parent:
async SystemMessageHandled();

NuwaReady();
// Sent when nuwa finished its initialization process and is waiting for
// parent's signal to make it freeze.
NuwaWaitForFreeze();

sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds);

Expand Down
15 changes: 0 additions & 15 deletions dom/ipc/TabChild.cpp
Expand Up @@ -775,21 +775,6 @@ TabChild::PreloadSlowThings()
ClearOnShutdown(&sPreallocatedTab);
}

/*static*/ void
TabChild::PostForkPreload()
{
// Preallocated Tab can be null if we are forked directly from b2g. In such
// case we don't need to preload anything, just return.
if (!sPreallocatedTab) {
return;
}

// Rebuild connections to parent.
sPreallocatedTab->RecvLoadRemoteScript(
NS_LITERAL_STRING("chrome://global/content/post-fork-preload.js"),
true);
}

/*static*/ already_AddRefed<TabChild>
TabChild::Create(nsIContentChild* aManager,
const TabId& aTabId,
Expand Down
1 change: 0 additions & 1 deletion dom/ipc/TabChild.h
Expand Up @@ -263,7 +263,6 @@ class TabChild final : public TabChildBase,
* on the critical path.
*/
static void PreloadSlowThings();
static void PostForkPreload();

/** Return a TabChild with the given attributes. */
static already_AddRefed<TabChild>
Expand Down
1 change: 0 additions & 1 deletion dom/ipc/jar.mn
Expand Up @@ -12,4 +12,3 @@ toolkit.jar:
content/global/manifestMessages.js (manifestMessages.js)
content/global/PushServiceChildPreload.js (../push/PushServiceChildPreload.js)
content/global/preload.js (preload.js)
content/global/post-fork-preload.js (post-fork-preload.js)
20 changes: 0 additions & 20 deletions dom/ipc/post-fork-preload.js

This file was deleted.

2 changes: 1 addition & 1 deletion dom/ipc/preload.js
Expand Up @@ -6,7 +6,6 @@
//
// This script is run when the preallocated process starts. It is injected as
// a frame script.
// If nuwa is enabled, this script will run in Nuwa process before frozen.

const BrowserElementIsPreloaded = true;

Expand Down Expand Up @@ -59,6 +58,7 @@ const BrowserElementIsPreloaded = true;
Cc["@mozilla.org/network/idn-service;1"].getService(Ci["nsIIDNService"]);
Cc["@mozilla.org/network/io-service;1"].getService(Ci["nsIIOService2"]);
Cc["@mozilla.org/network/mime-hdrparam;1"].getService(Ci["nsIMIMEHeaderParam"]);
Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(Ci["nsIProtocolProxyService"]);
Cc["@mozilla.org/network/socket-transport-service;1"].getService(Ci["nsISocketTransportService"]);
Cc["@mozilla.org/network/stream-transport-service;1"].getService(Ci["nsIStreamTransportService"]);
Cc["@mozilla.org/network/url-parser;1?auth=maybe"].getService(Ci["nsIURLParser"]);
Expand Down
3 changes: 0 additions & 3 deletions dom/wifi/WifiProxyService.cpp
Expand Up @@ -67,9 +67,6 @@ class EventRunnable : public nsRunnable
NS_IMETHOD Run()
{
MOZ_ASSERT(!NS_IsMainThread());
#ifdef MOZ_NUWA_PROCESS
NS_SetIgnoreStatusOfCurrentThread();
#endif
nsAutoString event;
gWpaSupplicant->WaitForEvent(event, mInterface);
if (!event.IsEmpty()) {
Expand Down

0 comments on commit 55152ad

Please sign in to comment.