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