forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream support for WebKit shared timer toggling.
This is part of Chrome for Android upstreaming. These changes are used on the Java app side to suspend webkit timers in all renderers when activity is paused and resume timers when activity is resumed. This reduces javascript execution when the app is in the background, causing lesser CPU and network usage. It doesn't stop javascript altogether because if the page JS is constantly running without relying on timers/events then it continues to run (but that is quite rare). Review URL: https://chromiumcodereview.appspot.com/10690023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147438 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
pliard@chromium.org
committed
Jul 19, 2012
1 parent
8220e5d
commit a1a7ff3
Showing
14 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ include_rules = [ | |
"+ash", | ||
"+crypto", | ||
"+gpu", | ||
"+jni", | ||
"+native_client", | ||
"+net", | ||
"+printing", | ||
|
25 changes: 25 additions & 0 deletions
25
chrome/android/java/src/org/chromium/chrome/browser/ProcessUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser; | ||
|
||
/** | ||
* A set of utility methods related to the various Chrome processes. | ||
*/ | ||
public class ProcessUtils { | ||
// To prevent this class from being instantiated. | ||
private ProcessUtils() { | ||
} | ||
|
||
/** | ||
* Suspends Webkit timers in all renderers. | ||
* | ||
* @param suspend true if timers should be suspended. | ||
*/ | ||
public static void toggleWebKitSharedTimers(boolean suspend) { | ||
nativeToggleWebKitSharedTimers(suspend); | ||
} | ||
|
||
private static native void nativeToggleWebKitSharedTimers(boolean suspend); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/android/process_utils.h" | ||
|
||
#include <vector> | ||
|
||
#include "base/lazy_instance.h" | ||
#include "base/logging.h" | ||
#include "chrome/common/render_messages.h" | ||
#include "content/public/browser/render_process_host.h" | ||
#include "jni/process_utils_jni.h" | ||
|
||
namespace { | ||
|
||
// Only accessed from the JNI thread by ToggleWebKitSharedTimers() which is | ||
// implemented below. | ||
base::LazyInstance<std::vector<int /* process id */> > g_suspended_processes = | ||
LAZY_INSTANCE_INITIALIZER; | ||
|
||
// Suspends timers in all current render processes. | ||
void SuspendWebKitSharedTimers(std::vector<int>* suspended_processes) { | ||
for (content::RenderProcessHost::iterator i( | ||
content::RenderProcessHost::AllHostsIterator()); | ||
!i.IsAtEnd(); i.Advance()) { | ||
content::RenderProcessHost* host = i.GetCurrentValue(); | ||
suspended_processes->push_back(host->GetID()); | ||
host->Send(new ChromeViewMsg_ToggleWebKitSharedTimer(true)); | ||
} | ||
} | ||
|
||
void ResumeWebkitSharedTimers(const std::vector<int>& suspended_processes) { | ||
for (std::vector<int>::const_iterator it = suspended_processes.begin(); | ||
it != suspended_processes.end(); ++it) { | ||
content::RenderProcessHost* host = content::RenderProcessHost::FromID(*it); | ||
if (host) | ||
host->Send(new ChromeViewMsg_ToggleWebKitSharedTimer(false)); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
static void ToggleWebKitSharedTimers(JNIEnv* env, | ||
jclass obj, | ||
jboolean suspend) { | ||
std::vector<int>* suspended_processes = &g_suspended_processes.Get(); | ||
if (suspend) { | ||
DCHECK(suspended_processes->empty()); | ||
SuspendWebKitSharedTimers(suspended_processes); | ||
} else { | ||
ResumeWebkitSharedTimers(*suspended_processes); | ||
suspended_processes->clear(); | ||
} | ||
} | ||
|
||
// TODO(pliard): http://crbug.com/137674 | ||
bool RegisterProcessUtils(JNIEnv* env) { | ||
return RegisterNativesImpl(env); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_ANDROID_PROCESS_UTILS_H_ | ||
#define CHROME_BROWSER_ANDROID_PROCESS_UTILS_H_ | ||
|
||
#include <jni.h> | ||
|
||
bool RegisterProcessUtils(JNIEnv* env); | ||
|
||
#endif // CHROME_BROWSER_ANDROID_PROCESS_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters