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

Side by Side Diff: mojo/android/system/base_run_loop.cc

Issue 2272253003: Remove calls to deprecated MessageLoop methods from mojo/. (Closed)
Patch Set: Created 4 years, 3 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
« 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/android/system/base_run_loop.h" 5 #include "mojo/android/system/base_run_loop.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/base_jni_registrar.h" 9 #include "base/android/base_jni_registrar.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/android/jni_registrar.h" 11 #include "base/android/jni_registrar.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h"
14 #include "jni/BaseRunLoop_jni.h" 17 #include "jni/BaseRunLoop_jni.h"
15 18
16 using base::android::JavaParamRef; 19 using base::android::JavaParamRef;
17 20
18 namespace mojo { 21 namespace mojo {
19 namespace android { 22 namespace android {
20 23
21 static jlong CreateBaseRunLoop(JNIEnv* env, 24 static jlong CreateBaseRunLoop(JNIEnv* env,
22 const JavaParamRef<jobject>& jcaller) { 25 const JavaParamRef<jobject>& jcaller) {
23 base::MessageLoop* message_loop = new base::MessageLoop; 26 base::MessageLoop* message_loop = new base::MessageLoop;
24 return reinterpret_cast<uintptr_t>(message_loop); 27 return reinterpret_cast<uintptr_t>(message_loop);
25 } 28 }
26 29
27 static void Run(JNIEnv* env, 30 static void Run(JNIEnv* env,
28 const JavaParamRef<jobject>& jcaller, 31 const JavaParamRef<jobject>& jcaller,
29 jlong runLoopID) { 32 jlong runLoopID) {
30 reinterpret_cast<base::MessageLoop*>(runLoopID)->Run(); 33 DCHECK(reinterpret_cast<base::MessageLoop*>(runLoopID)
34 ->task_runner()
35 ->BelongsToCurrentThread());
jam 2016/08/30 16:33:04 if try runs passed (which I can't tell, since you
36 base::RunLoop().Run();
31 } 37 }
32 38
33 static void RunUntilIdle(JNIEnv* env, 39 static void RunUntilIdle(JNIEnv* env,
34 const JavaParamRef<jobject>& jcaller, 40 const JavaParamRef<jobject>& jcaller,
35 jlong runLoopID) { 41 jlong runLoopID) {
36 reinterpret_cast<base::MessageLoop*>(runLoopID)->RunUntilIdle(); 42 DCHECK(reinterpret_cast<base::MessageLoop*>(runLoopID)
43 ->task_runner()
44 ->BelongsToCurrentThread());
45 base::RunLoop().RunUntilIdle();
37 } 46 }
38 47
39 static void Quit(JNIEnv* env, 48 static void Quit(JNIEnv* env,
40 const JavaParamRef<jobject>& jcaller, 49 const JavaParamRef<jobject>& jcaller,
41 jlong runLoopID) { 50 jlong runLoopID) {
42 reinterpret_cast<base::MessageLoop*>(runLoopID)->QuitWhenIdle(); 51 reinterpret_cast<base::MessageLoop*>(runLoopID)->QuitWhenIdle();
43 } 52 }
44 53
45 static void RunJavaRunnable( 54 static void RunJavaRunnable(
46 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) { 55 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
47 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(), 56 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(),
48 runnable_ref); 57 runnable_ref);
49 } 58 }
50 59
51 static void PostDelayedTask(JNIEnv* env, 60 static void PostDelayedTask(JNIEnv* env,
52 const JavaParamRef<jobject>& jcaller, 61 const JavaParamRef<jobject>& jcaller,
53 jlong runLoopID, 62 jlong runLoopID,
54 const JavaParamRef<jobject>& runnable, 63 const JavaParamRef<jobject>& runnable,
55 jlong delay) { 64 jlong delay) {
56 base::android::ScopedJavaGlobalRef<jobject> runnable_ref; 65 base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
57 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to 66 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to
58 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before 67 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
59 // running the Runnable. 68 // running the Runnable.
60 runnable_ref.Reset(env, runnable); 69 runnable_ref.Reset(env, runnable);
61 reinterpret_cast<base::MessageLoop*>(runLoopID)->PostDelayedTask( 70 reinterpret_cast<base::MessageLoop*>(runLoopID)
62 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref), 71 ->task_runner()
63 base::TimeDelta::FromMicroseconds(delay)); 72 ->PostDelayedTask(FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref),
73 base::TimeDelta::FromMicroseconds(delay));
64 } 74 }
65 75
66 static void DeleteMessageLoop(JNIEnv* env, 76 static void DeleteMessageLoop(JNIEnv* env,
67 const JavaParamRef<jobject>& jcaller, 77 const JavaParamRef<jobject>& jcaller,
68 jlong runLoopID) { 78 jlong runLoopID) {
69 base::MessageLoop* message_loop = 79 base::MessageLoop* message_loop =
70 reinterpret_cast<base::MessageLoop*>(runLoopID); 80 reinterpret_cast<base::MessageLoop*>(runLoopID);
71 delete message_loop; 81 delete message_loop;
72 } 82 }
73 83
74 bool RegisterBaseRunLoop(JNIEnv* env) { 84 bool RegisterBaseRunLoop(JNIEnv* env) {
75 return RegisterNativesImpl(env); 85 return RegisterNativesImpl(env);
76 } 86 }
77 87
78 } // namespace android 88 } // namespace android
79 } // namespace mojo 89 } // namespace mojo
80 90
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