Chromium Code Reviews

Unified Diff: shell/android/apk/src/org/chromium/mojo/shell/NativeHandlerThread.java

Issue 1456913002: Use thread with looper and native message loop for vsync service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: shell/android/apk/src/org/chromium/mojo/shell/NativeHandlerThread.java
diff --git a/shell/android/apk/src/org/chromium/mojo/shell/NativeHandlerThread.java b/shell/android/apk/src/org/chromium/mojo/shell/NativeHandlerThread.java
new file mode 100644
index 0000000000000000000000000000000000000000..334372ebd9995acea71635798269d6fc81c3aef8
--- /dev/null
+++ b/shell/android/apk/src/org/chromium/mojo/shell/NativeHandlerThread.java
@@ -0,0 +1,54 @@
+// Copyright 2015 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.mojo.shell;
+
+import android.os.HandlerThread;
+
+import org.chromium.base.JNINamespace;
+
+/**
+ * Handler thread associated with a native message loop.
+ */
+@JNINamespace("shell")
+public class NativeHandlerThread extends HandlerThread {
+ // The native message loop.
+ private long mNativeMessageLoop = 0;
+
+ /**
+ * Constructor.
+ */
+ public NativeHandlerThread(String name) {
+ super(name);
+ }
+
+ /**
+ * @see HandlerThread#run()
+ */
+ @Override
+ public void run() {
+ try {
+ super.run();
+ } finally {
+ if (mNativeMessageLoop != 0) {
+ nativeDeleteMessageLoop(mNativeMessageLoop);
+ }
+ }
+ }
+
+ /**
+ * @see HandlerThread#onLooperPrepared()
+ */
+ @Override
+ protected void onLooperPrepared() {
+ if (mNativeMessageLoop == 0) {
+ mNativeMessageLoop = nativeCreateMessageLoop();
+ }
+ super.onLooperPrepared();
+ }
+
+ native long nativeCreateMessageLoop();
+
+ native void nativeDeleteMessageLoop(long messageLoop);
+}

Powered by Google App Engine