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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/LauncherThread.java

Issue 2828793002: Refactoring ChildProcessConnection. (Closed)
Patch Set: Refactoring ChildProcessConnection. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.os.Handler; 7 import android.os.Handler;
8 import android.os.Looper; 8 import android.os.Looper;
9 9
10 import org.chromium.base.JavaHandlerThread; 10 import org.chromium.base.JavaHandlerThread;
11 import org.chromium.base.VisibleForTesting;
11 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
13 14
14 /** This is BrowserThread::PROCESS_LAUNCHER. It is available before native libra ry is loaded. */ 15 /** This is BrowserThread::PROCESS_LAUNCHER. It is available before native libra ry is loaded. */
15 @JNINamespace("content::android") 16 @JNINamespace("content::android")
16 public final class LauncherThread { 17 public final class LauncherThread {
17 private static final JavaHandlerThread sThread = 18 private static final JavaHandlerThread sThread =
18 new JavaHandlerThread("Chrome_ProcessLauncherThread"); 19 new JavaHandlerThread("Chrome_ProcessLauncherThread");
19 private static final Handler sHandler; 20 private static final Handler sThreadHandler;
21 // Can be overritten in tests.
22 private static Handler sHandler;
20 static { 23 static {
21 sThread.maybeStart(); 24 sThread.maybeStart();
22 sHandler = new Handler(sThread.getLooper()); 25 sThreadHandler = new Handler(sThread.getLooper());
26 sHandler = sThreadHandler;
23 } 27 }
24 28
25 public static void post(Runnable r) { 29 public static void post(Runnable r) {
26 sHandler.post(r); 30 sHandler.post(r);
27 } 31 }
28 32
29 public static void postDelayed(Runnable r, long delayMillis) { 33 public static void postDelayed(Runnable r, long delayMillis) {
30 sHandler.postDelayed(r, delayMillis); 34 sHandler.postDelayed(r, delayMillis);
31 } 35 }
32 36
33 public static boolean runningOnLauncherThread() { 37 public static boolean runningOnLauncherThread() {
34 return sHandler.getLooper() == Looper.myLooper(); 38 return sHandler.getLooper() == Looper.myLooper();
35 } 39 }
36 40
41 @VisibleForTesting
42 public static void setCurrentThreadAsLauncherThread() {
43 sHandler = new Handler();
44 }
45
46 @VisibleForTesting
47 public static void setLauncherThreadAsLauncherThread() {
48 sHandler = sThreadHandler;
49 }
50
37 @CalledByNative 51 @CalledByNative
38 private static JavaHandlerThread getHandlerThread() { 52 private static JavaHandlerThread getHandlerThread() {
39 return sThread; 53 return sThread;
40 } 54 }
41 55
42 private LauncherThread() {} 56 private LauncherThread() {}
43 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698