Bug 797239 - Defer scheduling prelaunch app until child goes idle. r=cjones, a=blocking-basecamp

This commit is contained in:
Dave Hylands 2012-10-08 22:46:19 -06:00
Родитель e08238b617
Коммит f8fb4173f6
4 изменённых файлов: 40 добавлений и 2 удалений

Просмотреть файл

@ -470,10 +470,21 @@ ContentChild::AllocPImageBridge(mozilla::ipc::Transport* aTransport,
return ImageBridgeChild::StartUpInChildProcess(aTransport, aOtherProcess); return ImageBridgeChild::StartUpInChildProcess(aTransport, aOtherProcess);
} }
static void FirstIdle(void)
{
ContentChild::GetSingleton()->SendFirstIdle();
}
PBrowserChild* PBrowserChild*
ContentChild::AllocPBrowser(const uint32_t& aChromeFlags, ContentChild::AllocPBrowser(const uint32_t& aChromeFlags,
const bool& aIsBrowserElement, const AppId& aApp) const bool& aIsBrowserElement, const AppId& aApp)
{ {
static bool firstIdleTaskPosted = false;
if (!firstIdleTaskPosted) {
MessageLoop::current()->PostIdleTask(FROM_HERE, NewRunnableFunction(FirstIdle));
firstIdleTaskPosted = true;
}
nsRefPtr<TabChild> child = nsRefPtr<TabChild> child =
TabChild::Create(aChromeFlags, aIsBrowserElement, aApp.get_uint32_t()); TabChild::Create(aChromeFlags, aIsBrowserElement, aApp.get_uint32_t());
// The ref here is released below. // The ref here is released below.

Просмотреть файл

@ -227,10 +227,17 @@ ContentParent::MaybeTakePreallocatedAppProcess()
{ {
nsRefPtr<ContentParent> process = sPreallocatedAppProcess.get(); nsRefPtr<ContentParent> process = sPreallocatedAppProcess.get();
sPreallocatedAppProcess = nullptr; sPreallocatedAppProcess = nullptr;
ScheduleDelayedPreallocateAppProcess();
return process.forget(); return process.forget();
} }
/*static*/ void
ContentParent::FirstIdle(void)
{
// The parent has gone idle for the first time. This would be a good
// time to preallocate an app process.
ScheduleDelayedPreallocateAppProcess();
}
/*static*/ void /*static*/ void
ContentParent::StartUp() ContentParent::StartUp()
{ {
@ -247,7 +254,10 @@ ContentParent::StartUp()
"dom.ipc.processPrelaunch.delayMs", 1000); "dom.ipc.processPrelaunch.delayMs", 1000);
MOZ_ASSERT(!sPreallocateAppProcessTask); MOZ_ASSERT(!sPreallocateAppProcessTask);
ScheduleDelayedPreallocateAppProcess();
// Let's not slow down the main process initialization. Wait until
// the main process goes idle before we preallocate a process
MessageLoop::current()->PostIdleTask(FROM_HERE, NewRunnableFunction(FirstIdle));
} }
} }
@ -1003,6 +1013,17 @@ ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
return true; return true;
} }
bool
ContentParent::RecvFirstIdle()
{
// When the ContentChild goes idle, it sends us a FirstIdle message
// which we use as a good time to prelaunch another process. If we
// prelaunch any sooner than this, then we'll be competing with the
// child process and slowing it down.
ScheduleDelayedPreallocateAppProcess();
return true;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent, NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
nsIObserver, nsIObserver,
nsIThreadObserver, nsIThreadObserver,

Просмотреть файл

@ -144,6 +144,7 @@ private:
static void DelayedPreallocateAppProcess(); static void DelayedPreallocateAppProcess();
static void ScheduleDelayedPreallocateAppProcess(); static void ScheduleDelayedPreallocateAppProcess();
static already_AddRefed<ContentParent> MaybeTakePreallocatedAppProcess(); static already_AddRefed<ContentParent> MaybeTakePreallocatedAppProcess();
static void FirstIdle();
// Hide the raw constructor methods since we don't want client code // Hide the raw constructor methods since we don't want client code
// using them. // using them.
@ -308,6 +309,8 @@ private:
virtual bool RecvPrivateDocShellsExist(const bool& aExist); virtual bool RecvPrivateDocShellsExist(const bool& aExist);
virtual bool RecvFirstIdle();
virtual void ProcessingError(Result what) MOZ_OVERRIDE; virtual void ProcessingError(Result what) MOZ_OVERRIDE;
GeckoChildProcessHost* mSubprocess; GeckoChildProcessHost* mSubprocess;

Просмотреть файл

@ -346,6 +346,9 @@ parent:
// Notify the parent of the presence or absence of private docshells // Notify the parent of the presence or absence of private docshells
PrivateDocShellsExist(bool aExist); PrivateDocShellsExist(bool aExist);
// Tell the parent that the child has gone idle for the first time
async FirstIdle();
both: both:
AsyncMessage(nsString aMessage, ClonedMessageData aData); AsyncMessage(nsString aMessage, ClonedMessageData aData);
}; };