Making a way to create thread with a Java Looper for Android

We need to create a new message loop type for this as for
testing the Android UI message pump type is not the standard Java, but gets overridden to a different one that can handle nested message loops.

Using the new Java thread for the java bridge thread, so the thread used for AJI callbacks will have a prepared Looper.

BUG=b/8680913
TBR=jochen@chromium.org

Review URL: https://chromiumcodereview.appspot.com/18584006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216349 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 349ad5872a8ff25729e1b67ad24a09b64571c04c
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index d2eafbd..826c757 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -92,7 +92,7 @@
 // time for every task that is added to the MessageLoop incoming queue.
 bool AlwaysNotifyPump(MessageLoop::Type type) {
 #if defined(OS_ANDROID)
-  return type == MessageLoop::TYPE_UI;
+  return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA;
 #else
   return false;
 #endif
@@ -184,6 +184,10 @@
       pump_.reset(MESSAGE_PUMP_UI);
   } else if (type_ == TYPE_IO) {
     pump_.reset(MESSAGE_PUMP_IO);
+#if defined(OS_ANDROID)
+  } else if (type_ == TYPE_JAVA) {
+    pump_.reset(MESSAGE_PUMP_UI);
+#endif
   } else {
     DCHECK_EQ(TYPE_DEFAULT, type_);
     pump_.reset(new MessagePumpDefault());
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index 6f71a85..f22c904 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -109,10 +109,19 @@
   //   This type of ML also supports asynchronous IO.  See also
   //   MessageLoopForIO.
   //
+  // TYPE_JAVA
+  //   This type of ML is backed by a Java message handler which is responsible
+  //   for running the tasks added to the ML. This is only for use on Android.
+  //   TYPE_JAVA behaves in essence like TYPE_UI, except during construction
+  //   where it does not use the main thread specific pump factory.
+  //
   enum Type {
     TYPE_DEFAULT,
     TYPE_UI,
-    TYPE_IO
+    TYPE_IO,
+#if defined(OS_ANDROID)
+    TYPE_JAVA,
+#endif // defined(OS_ANDROID)
   };
 
   // Normally, it is not necessary to instantiate a MessageLoop.  Instead, it