Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: content/browser/android/content_view_statics.cc

Issue 14297022: Resume WebKit shared timers only in previously suspended processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Jonathan's comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/android/content_view_statics.cc
diff --git a/content/browser/android/content_view_statics.cc b/content/browser/android/content_view_statics.cc
index 0fb08964dea3514f57c01e6fe384a81a52edd89d..66af8652d49bf14b038ce79820903053657bcfd2 100644
--- a/content/browser/android/content_view_statics.cc
+++ b/content/browser/android/content_view_statics.cc
@@ -3,25 +3,64 @@
// found in the LICENSE file.
#include <jni.h>
+#include <vector>
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/basictypes.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "content/browser/android/content_view_statics.h"
#include "content/common/android/address_parser.h"
#include "content/common/view_messages.h"
#include "content/public/browser/render_process_host.h"
-
#include "jni/ContentViewStatics_jni.h"
using base::android::ConvertJavaStringToUTF16;
using base::android::ConvertUTF16ToJavaString;
-using base::android::ScopedJavaLocalRef;
+namespace {
+
+// TODO(pliard): http://crbug.com/235909. Move WebKit shared timer toggling
+// functionality out of ContentViewStatistics and not be build on top of
+// WebKit::Platform::SuspendSharedTimer.
+// TODO(pliard): http://crbug.com/235912. Add unit tests for WebKit shared timer
+// toggling.
+
+// This tracks the renderer processes that received a suspend request. It's
+// important on resume to only resume the renderer processes that were actually
+// suspended as opposed to all the current renderer processes because the
+// suspend calls are refcounted within WebKitPlatformSupport and it expects a
+// perfectly matched number of resume calls.
+// Note that this vector is only accessed from the UI thread.
+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 ViewMsg_SetWebKitSharedTimersSuspended(true));
+ }
+}
+
+// Resumes timers in processes that were previously stopped.
+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) // The process might have been killed since it was suspended.
+ host->Send(new ViewMsg_SetWebKitSharedTimersSuspended(false));
+ }
+}
+
+} // namespace
-// Return the first substring consisting of the address of a physical location.
+// Returns the first substring consisting of the address of a physical location.
static jstring FindAddress(JNIEnv* env, jclass clazz, jstring addr) {
string16 content_16 = ConvertJavaStringToUTF16(env, addr);
string16 result_16;
@@ -33,12 +72,13 @@ static jstring FindAddress(JNIEnv* env, jclass clazz, jstring addr) {
static void SetWebKitSharedTimersSuspended(JNIEnv* env,
jclass obj,
jboolean suspend) {
- for (content::RenderProcessHost::iterator i =
- content::RenderProcessHost::AllHostsIterator();
- !i.IsAtEnd();
- i.Advance()) {
- content::RenderProcessHost* host = i.GetCurrentValue();
- host->Send(new ViewMsg_SetWebKitSharedTimersSuspended(suspend));
+ std::vector<int>* suspended_processes = g_suspended_processes.Pointer();
+ if (suspend) {
+ DCHECK(suspended_processes->empty());
+ SuspendWebKitSharedTimers(suspended_processes);
+ } else {
+ ResumeWebkitSharedTimers(*suspended_processes);
+ suspended_processes->clear();
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698