1 // Copyright 2013 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 package org.chromium.base; 6 7 import android.os.Handler; 8 import android.os.HandlerThread; 9 10 /** 11 * This class is an internal detail of the native counterpart. 12 * It is instantiated and owned by the native object. 13 */ 14 @JNINamespace("base::android") 15 class JavaHandlerThread { 16 final HandlerThread mThread; 17 JavaHandlerThread(String name)18 private JavaHandlerThread(String name) { 19 mThread = new HandlerThread(name); 20 } 21 22 @CalledByNative create(String name)23 private static JavaHandlerThread create(String name) { 24 return new JavaHandlerThread(name); 25 } 26 27 @CalledByNative start(final long nativeThread, final long nativeEvent)28 private void start(final long nativeThread, final long nativeEvent) { 29 mThread.start(); 30 new Handler(mThread.getLooper()).post(new Runnable() { 31 @Override 32 public void run() { 33 nativeInitializeThread(nativeThread, nativeEvent); 34 } 35 }); 36 } 37 nativeInitializeThread(long nativeJavaHandlerThread, long nativeEvent)38 private native void nativeInitializeThread(long nativeJavaHandlerThread, long nativeEvent); 39 } 40