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 5package org.chromium.base; 6 7import android.os.Handler; 8import 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") 15class JavaHandlerThread { 16 final HandlerThread mThread; 17 18 private JavaHandlerThread(String name) { 19 mThread = new HandlerThread(name); 20 } 21 22 @CalledByNative 23 private static JavaHandlerThread create(String name) { 24 return new JavaHandlerThread(name); 25 } 26 27 @CalledByNative 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 38 private native void nativeInitializeThread(long nativeJavaHandlerThread, long nativeEvent); 39} 40