PeerConnection(Java): auto-WrapCurrentThread() when creating PeerConnectionFactory.

Various pieces of talk/ assume that the current Thread is ThreadManager'd
without checking this, so unconditionally wrap the caller's thread in case it
was created by Java code unbeknownst to ThreadManager.

BUG=2947
R=wu@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/9419004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6154 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc
index 9739c89..364d196 100644
--- a/talk/app/webrtc/java/jni/peerconnection_jni.cc
+++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc
@@ -1928,6 +1928,12 @@
 
 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
     JNIEnv* jni, jclass) {
+  // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
+  // ThreadManager only WrapCurrentThread()s the thread where it is first
+  // created.  Since the semantics around when auto-wrapping happens in
+  // talk/base/ are convoluted, we simply wrap here to avoid having to think
+  // about ramifications of auto-wrapping there.
+  talk_base::ThreadManager::Instance()->WrapCurrentThread();
   webrtc::Trace::CreateTrace();
   Thread* worker_thread = new Thread();
   worker_thread->SetName("worker_thread", NULL);