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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/android/process_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/process_utils.h"
6
7 #include <vector>
8
9 #include "base/lazy_instance.h"
10 #include "base/logging.h"
11 #include "chrome/common/render_messages.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "jni/process_utils_jni.h"
14
15 namespace {
16
17 // Only accessed from the JNI thread by ToggleWebKitSharedTimers() which is
18 // implemented below.
19 base::LazyInstance<std::vector<int /* process id */> > g_suspended_processes =
20 LAZY_INSTANCE_INITIALIZER;
21
22 // Suspends timers in all current render processes.
23 void SuspendWebKitSharedTimers(std::vector<int>* suspended_processes) {
24 for (content::RenderProcessHost::iterator i(
25 content::RenderProcessHost::AllHostsIterator());
26 !i.IsAtEnd(); i.Advance()) {
27 content::RenderProcessHost* host = i.GetCurrentValue();
28 suspended_processes->push_back(host->GetID());
29 host->Send(new ChromeViewMsg_ToggleWebKitSharedTimer(true));
30 }
31 }
32
33 void ResumeWebkitSharedTimers(const std::vector<int>& suspended_processes) {
34 for (std::vector<int>::const_iterator it = suspended_processes.begin();
35 it != suspended_processes.end(); ++it) {
36 content::RenderProcessHost* host = content::RenderProcessHost::FromID(*it);
37 if (host)
38 host->Send(new ChromeViewMsg_ToggleWebKitSharedTimer(false));
39 }
40 }
41
42 } // namespace
43
44 static void ToggleWebKitSharedTimers(JNIEnv* env,
45 jclass obj,
46 jboolean suspend) {
47 std::vector<int>* suspended_processes = &g_suspended_processes.Get();
48 if (suspend) {
49 DCHECK(suspended_processes->empty());
50 SuspendWebKitSharedTimers(suspended_processes);
51 } else {
52 ResumeWebkitSharedTimers(*suspended_processes);
53 suspended_processes->clear();
54 }
55 }
56
57 // TODO(pliard): http://crbug.com/137674
58 bool RegisterProcessUtils(JNIEnv* env) {
59 return RegisterNativesImpl(env);
60 }
OLDNEW
« 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