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

Unified Diff: base/android/java/src/org/chromium/base/JavaThread.java

Issue 18584006: Making a way to create thread with a Java Looper for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoiding calling start multiple times, ordering includes and ading override Created 7 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
Index: base/android/java/src/org/chromium/base/JavaThread.java
diff --git a/base/android/java/src/org/chromium/base/JavaThread.java b/base/android/java/src/org/chromium/base/JavaThread.java
new file mode 100644
index 0000000000000000000000000000000000000000..884f5318efab1be14520dd10f8e60668dc3da515
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/JavaThread.java
@@ -0,0 +1,39 @@
+// Copyright (c) 2013 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.
+
+package org.chromium.base;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
+
+@JNINamespace("base::android")
+class JavaThread implements Handler.Callback {
joth 2013/07/10 20:33:48 comment? It's mainly an implementation detail of t
Kristian Monsen 2013/07/16 21:54:41 See below.
joth 2013/07/17 16:29:18 Cool. I was actually meaning add a class comment /
Kristian Monsen 2013/07/17 21:02:37 Done.
+
+ final HandlerThread mThread;
+
+ private JavaThread(String name) {
+ mThread = new HandlerThread(name);
+ }
+
+ @CalledByNative
+ private static JavaThread create(String name) {
+ return new JavaThread(name);
+ }
+
+ @CalledByNative
+ private void start(int nativeThread) {
+ mThread.start();
+ new Handler(mThread.getLooper(), this).sendEmptyMessage(nativeThread);
joth 2013/07/10 20:33:48 rather than have the outer class subclass Handler.
Kristian Monsen 2013/07/16 21:54:41 Done. Removed the other parts that are no longer n
+ }
+
+ @Override
+ public boolean handleMessage(Message msg) {
+ nativeInitializeThread(msg.what);
+ return true;
+ }
+
+ private native void nativeInitializeThread(int nativeJavaThread);
+}

Powered by Google App Engine
This is Rietveld 408576698