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

Unified Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java

Issue 2708513002: bluetooth: Post a task when sending GATT events to simulate another thread. (Closed)
Patch Set: Remove unnecessary if statement Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
index 282faa877e3c0b4d7c62f3ee86d9f6520d49840b..4b3b3a828f57c95dd921b78db40d4687caf2363c 100644
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
@@ -24,6 +24,7 @@ import android.os.Build;
import android.os.ParcelUuid;
import org.chromium.base.Log;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -48,6 +49,52 @@ class Wrappers {
public static final int DEVICE_CLASS_UNSPECIFIED = 0x1F00;
/**
+ * Wraps base.ThreadUtils.
+ * base.ThreadUtils has a set of static method to interact with the
+ * UI Thread. To be able to provide a set of test methods, ThreadUtilsWrapper
+ * uses the factory pattern.
+ */
+ static class ThreadUtilsWrapper {
+ private static Factory sFactory;
+
+ private static ThreadUtilsWrapper sInstance;
+
+ protected ThreadUtilsWrapper() {}
+
+ /**
+ * Returns the singleton instance of ThreadUtilsWrapper, creating it if needed.
+ */
+ public static ThreadUtilsWrapper getInstance() {
+ if (sInstance == null) {
+ if (sFactory == null) {
+ sInstance = new ThreadUtilsWrapper();
+ } else {
+ sInstance = sFactory.create();
+ }
+ }
+ return sInstance;
+ }
+
+ public void runOnUiThread(Runnable r) {
+ ThreadUtils.runOnUiThread(r);
+ }
+
+ /**
+ * Instantiate this to explain how to create a ThreadUtilsWrapper instance in
+ * ThreadUtilsWrapper.getInstance().
+ */
+ public interface Factory { public ThreadUtilsWrapper create(); }
+
+ /**
+ * Call this to use a different subclass of ThreadUtilsWrapper throughout the program.
+ */
+ public static void setFactory(Factory factory) {
+ sFactory = factory;
+ sInstance = null;
+ }
+ }
+
+ /**
* Wraps android.bluetooth.BluetoothAdapter.
*/
static class BluetoothAdapterWrapper {

Powered by Google App Engine
This is Rietveld 408576698