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

Side by Side 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: Created 7 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <jni.h> 5 #include <jni.h>
6 #include <vector>
6 7
7 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/lazy_instance.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "content/browser/android/content_view_statics.h" 14 #include "content/browser/android/content_view_statics.h"
13 #include "content/common/android/address_parser.h" 15 #include "content/common/android/address_parser.h"
14 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
15 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
16
17 #include "jni/ContentViewStatics_jni.h" 18 #include "jni/ContentViewStatics_jni.h"
18 19
19 using base::android::ConvertJavaStringToUTF16; 20 using base::android::ConvertJavaStringToUTF16;
20 using base::android::ConvertUTF16ToJavaString; 21 using base::android::ConvertUTF16ToJavaString;
21 using base::android::ScopedJavaLocalRef;
22 22
23 namespace {
23 24
24 // Return the first substring consisting of the address of a physical location. 25 // TODO(pliard): Move WebKit shared timer toggling functionnality out of
26 // ContentViewStatistics.
joth 2013/04/26 17:57:10 and perhaps add "and not be build on top of WebKit
Philippe 2013/04/26 18:03:07 Very good point.
27 // TODO(pliard): Add unit tests for WebKit shared timer toggling.
28
29 // This tracks the renderer processes that received a suspend request. It's
30 // important on resume to only resume the renderer processes that were actually
31 // suspended as opposed to all the current renderer processes.
joth 2013/04/26 17:57:10 nit: append why it's important: "because the suspe
Philippe 2013/04/26 18:03:07 Done.
32 // Note that this vector is only accessed from the UI thread.
33 base::LazyInstance<std::vector<int /* process id */> > g_suspended_processes =
34 LAZY_INSTANCE_INITIALIZER;
35
36 // Suspends timers in all current render processes.
37 void SuspendWebKitSharedTimers(std::vector<int>* suspended_processes) {
38 for (content::RenderProcessHost::iterator i(
39 content::RenderProcessHost::AllHostsIterator());
40 !i.IsAtEnd(); i.Advance()) {
41 content::RenderProcessHost* host = i.GetCurrentValue();
42 suspended_processes->push_back(host->GetID());
43 host->Send(new ViewMsg_SetWebKitSharedTimersSuspended(true));
44 }
45 }
46
47 // Resumes timers in processes that were previously stopped.
48 void ResumeWebkitSharedTimers(const std::vector<int>& suspended_processes) {
49 for (std::vector<int>::const_iterator it = suspended_processes.begin();
50 it != suspended_processes.end(); ++it) {
51 content::RenderProcessHost* host = content::RenderProcessHost::FromID(*it);
52 if (host) // The process might have been killed since it was suspended.
53 host->Send(new ViewMsg_SetWebKitSharedTimersSuspended(false));
54 }
55 }
56
57 } // namespace
58
59 // Returns the first substring consisting of the address of a physical location.
25 static jstring FindAddress(JNIEnv* env, jclass clazz, jstring addr) { 60 static jstring FindAddress(JNIEnv* env, jclass clazz, jstring addr) {
26 string16 content_16 = ConvertJavaStringToUTF16(env, addr); 61 string16 content_16 = ConvertJavaStringToUTF16(env, addr);
27 string16 result_16; 62 string16 result_16;
28 if (content::address_parser::FindAddress(content_16, &result_16)) 63 if (content::address_parser::FindAddress(content_16, &result_16))
29 return ConvertUTF16ToJavaString(env, result_16).Release(); 64 return ConvertUTF16ToJavaString(env, result_16).Release();
30 return NULL; 65 return NULL;
31 } 66 }
32 67
33 static void SetWebKitSharedTimersSuspended(JNIEnv* env, 68 static void SetWebKitSharedTimersSuspended(JNIEnv* env,
34 jclass obj, 69 jclass obj,
35 jboolean suspend) { 70 jboolean suspend) {
36 for (content::RenderProcessHost::iterator i = 71 std::vector<int>* suspended_processes = &g_suspended_processes.Get();
joth 2013/04/26 17:57:10 foo = g_suspended_processes.Pointer()
Philippe 2013/04/26 18:03:07 Ah, I always wondered why LazyInstance::Get() was
37 content::RenderProcessHost::AllHostsIterator(); 72 if (suspend) {
38 !i.IsAtEnd(); 73 DCHECK(suspended_processes->empty());
39 i.Advance()) { 74 SuspendWebKitSharedTimers(suspended_processes);
40 content::RenderProcessHost* host = i.GetCurrentValue(); 75 } else {
41 host->Send(new ViewMsg_SetWebKitSharedTimersSuspended(suspend)); 76 ResumeWebkitSharedTimers(*suspended_processes);
77 suspended_processes->clear();
42 } 78 }
43 } 79 }
44 80
45 namespace content { 81 namespace content {
46 82
47 bool RegisterWebViewStatics(JNIEnv* env) { 83 bool RegisterWebViewStatics(JNIEnv* env) {
48 return RegisterNativesImpl(env) >= 0; 84 return RegisterNativesImpl(env) >= 0;
49 } 85 }
50 86
51 } // namespace content 87 } // namespace content
OLDNEW
« 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