Add ThreadChecker class to ThreadUtils

This class can be used for checking that method calls are made on the correct thread.

R=magjed@webrtc.org

Review URL: https://codereview.webrtc.org/1384303002 .

Cr-Commit-Position: refs/heads/master@{#10173}
diff --git a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
index e7dc331..5e6cc52 100644
--- a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
@@ -31,6 +31,26 @@
 
 final class ThreadUtils {
   /**
+   * Utility class to be used for checking that a method is called on the correct thread.
+   */
+  public static class ThreadChecker {
+    private Thread thread = Thread.currentThread();
+
+    public void checkIsOnValidThread() {
+      if (thread == null) {
+        thread = Thread.currentThread();
+      }
+      if (Thread.currentThread() != thread) {
+        throw new IllegalStateException("Wrong thread");
+      }
+    }
+
+    public void detachThread() {
+      thread = null;
+    }
+  }
+
+  /**
    * Utility interface to be used with executeUninterruptibly() to wait for blocking operations
    * to complete without getting interrupted..
    */