Commit 0566b921 authored by dalecurtis@google.com's avatar dalecurtis@google.com

Control process backgrounding from within the child process on Windows.

Windows has a fancy backgrounding mode which lowers IO priority.
Sadly it can only be set from within the process to be backgrounded.
So add a new ChildProcessMsg to tell child processes when they should
enter and leave background mode.

This reduces glitching during background tab load. This should only be
landed along with https://codereview.chromium.org/298253004/ which
removes backgrounding for active audio tabs.

I expect this will reduce CPU and I/O load significantly for background
processes which will lead to power savings.

This is only done on Windows since ChromeOS / Linux require privileges
only available to the browser process for setting background mode.

BUG=362294
TEST=Play audio. Load background tabs. Observe less/no glitching.
R=jam@chromium.org, luken@chromium.org, nasko@chromium.org

Review URL: https://codereview.chromium.org/305533006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274071 0039d316-1c4b-4281-b951-d872f2087c98
parent cd901af7
......@@ -252,7 +252,9 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) {
// We don't change process priorities on Mac or Posix because the user lacks the
// permission to raise a process' priority even after lowering it.
#if defined(OS_WIN) || defined(OS_LINUX)
// TODO(dalecurtis): Reenable this on Windows after figuring out how to reliably
// wait for the renderer process to process IPC messages.
#if defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
if (!base::Process::CanBackgroundProcesses()) {
LOG(ERROR) << "Can't background processes";
......
......@@ -1973,9 +1973,16 @@ void RenderProcessHostImpl::SetBackgrounded(bool backgrounded) {
// is to not invoke the SetPriorityClass API if the dll is loaded.
if (GetModuleHandle(L"cbstext.dll"))
return;
#endif // OS_WIN
// Windows Vista+ has a fancy process backgrounding mode that can only be set
// from within the process. So notify the child process of background state.
Send(new ChildProcessMsg_SetProcessBackgrounded(backgrounded));
#else
// Backgrounding may require elevated privileges not available to renderer
// processes, so control backgrounding from the process host.
child_process_launcher_->SetProcessBackgrounded(backgrounded);
#endif // OS_WIN
}
void RenderProcessHostImpl::OnProcessLaunched() {
......@@ -1992,7 +1999,7 @@ void RenderProcessHostImpl::OnProcessLaunched() {
return;
}
child_process_launcher_->SetProcessBackgrounded(backgrounded_);
SetBackgrounded(backgrounded_);
}
// NOTE: This needs to be before sending queued messages because
......
......@@ -441,6 +441,10 @@ bool ChildThread::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData,
OnGetChildProfilerData)
IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded,
OnProcessBackgrounded)
#endif
#if defined(USE_TCMALLOC)
IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTcmallocStats, OnGetTcmallocStats)
#endif
......@@ -549,4 +553,10 @@ void ChildThread::EnsureConnected() {
base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
}
#if defined(OS_WIN)
void ChildThread::OnProcessBackgrounded(bool background) {
base::Process::Current().SetProcessBackgrounded(background);
}
#endif
} // namespace content
......@@ -194,6 +194,9 @@ class CONTENT_EXPORT ChildThread
void OnSetProfilerStatus(tracked_objects::ThreadData::Status status);
void OnGetChildProfilerData(int sequence_number);
void OnDumpHandles();
#if defined(OS_WIN)
void OnProcessBackgrounded(bool background);
#endif
#ifdef IPC_MESSAGE_LOG_ENABLED
void OnSetIPCLoggingEnabled(bool enable);
#endif
......
......@@ -111,6 +111,12 @@ IPC_MESSAGE_CONTROL1(ChildProcessMsg_GetChildHistogramData,
// Sent to child processes to dump their handle table.
IPC_MESSAGE_CONTROL0(ChildProcessMsg_DumpHandles)
#if defined(OS_WIN)
// Sent to child processes to tell them to enter or leave background mode.
IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetProcessBackgrounded,
bool /* background */)
#endif
#if defined(USE_TCMALLOC)
// Sent to child process to request tcmalloc stats.
IPC_MESSAGE_CONTROL0(ChildProcessMsg_GetTcmallocStats)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment