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

Unified Diff: chrome/browser/android/process_utils.cc

Issue 10690023: Upstream support for WebKit shared timer toggling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « chrome/browser/android/process_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/process_utils.cc
diff --git a/chrome/browser/android/process_utils.cc b/chrome/browser/android/process_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..79d967b1deb5398c8561c88db7ca9cdb10da9b49
--- /dev/null
+++ b/chrome/browser/android/process_utils.cc
@@ -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);
+}
« no previous file with comments | « chrome/browser/android/process_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698