Adding more detail to MessageQueue::Dispatch logging.

Every message will now be traced with the location from which it was
posted, including function name, file and line number.

This CL also writes a normal LOG message when the dispatch took more
than a certain amount of time (currently 50ms).

This logging should help us identify messages that are taking
longer than expected to be dispatched.

R=pthatcher@webrtc.org, tommi@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#13104}
diff --git a/webrtc/api/datachannel.cc b/webrtc/api/datachannel.cc
index 452e4b3..5a18e6f 100644
--- a/webrtc/api/datachannel.cc
+++ b/webrtc/api/datachannel.cc
@@ -187,7 +187,7 @@
     // Chrome glue and WebKit) are not wired up properly until after this
     // function returns.
     if (provider_->ReadyToSendData()) {
-      rtc::Thread::Current()->Post(this, MSG_CHANNELREADY, NULL);
+      rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_CHANNELREADY, NULL);
     }
   }
 
diff --git a/webrtc/api/dtmfsender.cc b/webrtc/api/dtmfsender.cc
index 78a73c4..bd4340e 100644
--- a/webrtc/api/dtmfsender.cc
+++ b/webrtc/api/dtmfsender.cc
@@ -137,7 +137,7 @@
   // Clear the previous queue.
   signaling_thread_->Clear(this, MSG_DO_INSERT_DTMF);
   // Kick off a new DTMF task queue.
-  signaling_thread_->Post(this, MSG_DO_INSERT_DTMF);
+  signaling_thread_->Post(RTC_FROM_HERE, this, MSG_DO_INSERT_DTMF);
   return true;
 }
 
@@ -222,7 +222,8 @@
   tones_.erase(0, first_tone_pos + 1);
 
   // Continue with the next tone.
-  signaling_thread_->PostDelayed(tone_gap, this, MSG_DO_INSERT_DTMF);
+  signaling_thread_->PostDelayed(RTC_FROM_HERE, tone_gap, this,
+                                 MSG_DO_INSERT_DTMF);
 }
 
 void DtmfSender::OnProviderDestroyed() {
diff --git a/webrtc/api/java/jni/androidmediadecoder_jni.cc b/webrtc/api/java/jni/androidmediadecoder_jni.cc
index 831b68d..3793756 100644
--- a/webrtc/api/java/jni/androidmediadecoder_jni.cc
+++ b/webrtc/api/java/jni/androidmediadecoder_jni.cc
@@ -307,6 +307,7 @@
 
   // Call Java init.
   return codec_thread_->Invoke<int32_t>(
+      RTC_FROM_HERE,
       Bind(&MediaCodecVideoDecoder::InitDecodeOnCodecThread, this));
 }
 
@@ -399,7 +400,7 @@
     }
   }
 
-  codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+  codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
@@ -430,7 +431,7 @@
   }
   inited_ = true;
 
-  codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+  codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
@@ -438,7 +439,7 @@
 int32_t MediaCodecVideoDecoder::Release() {
   ALOGD << "DecoderRelease request";
   return codec_thread_->Invoke<int32_t>(
-        Bind(&MediaCodecVideoDecoder::ReleaseOnCodecThread, this));
+      RTC_FROM_HERE, Bind(&MediaCodecVideoDecoder::ReleaseOnCodecThread, this));
 }
 
 int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
@@ -539,8 +540,9 @@
     if (use_surface_ &&
         (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecH264)) {
       // Soft codec reset - only for surface decoding.
-      ret = codec_thread_->Invoke<int32_t>(Bind(
-          &MediaCodecVideoDecoder::ResetDecodeOnCodecThread, this));
+      ret = codec_thread_->Invoke<int32_t>(
+          RTC_FROM_HERE,
+          Bind(&MediaCodecVideoDecoder::ResetDecodeOnCodecThread, this));
     } else {
       // Hard codec reset.
       ret = InitDecode(&codec_, 1);
@@ -568,8 +570,9 @@
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
 
-  return codec_thread_->Invoke<int32_t>(Bind(
-      &MediaCodecVideoDecoder::DecodeOnCodecThread, this, inputImage));
+  return codec_thread_->Invoke<int32_t>(
+      RTC_FROM_HERE,
+      Bind(&MediaCodecVideoDecoder::DecodeOnCodecThread, this, inputImage));
 }
 
 int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
@@ -896,7 +899,7 @@
     ProcessHWErrorOnCodecThread();
     return;
   }
-  codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+  codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
 }
 
 MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
diff --git a/webrtc/api/java/jni/androidmediaencoder_jni.cc b/webrtc/api/java/jni/androidmediaencoder_jni.cc
index 0e36aa1..a240b25 100644
--- a/webrtc/api/java/jni/androidmediaencoder_jni.cc
+++ b/webrtc/api/java/jni/androidmediaencoder_jni.cc
@@ -413,35 +413,33 @@
   }
 
   return codec_thread_->Invoke<int32_t>(
-      Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread,
-           this,
-           init_width,
-           init_height,
-           codec_settings->startBitrate,
-           codec_settings->maxFramerate,
-           false /* use_surface */));
+      RTC_FROM_HERE,
+      Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, this, init_width,
+           init_height, codec_settings->startBitrate,
+           codec_settings->maxFramerate, false /* use_surface */));
 }
 
 int32_t MediaCodecVideoEncoder::Encode(
     const webrtc::VideoFrame& frame,
     const webrtc::CodecSpecificInfo* /* codec_specific_info */,
     const std::vector<webrtc::FrameType>* frame_types) {
-  return codec_thread_->Invoke<int32_t>(Bind(
-      &MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, frame_types));
+  return codec_thread_->Invoke<int32_t>(
+      RTC_FROM_HERE, Bind(&MediaCodecVideoEncoder::EncodeOnCodecThread, this,
+                          frame, frame_types));
 }
 
 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback(
     webrtc::EncodedImageCallback* callback) {
   return codec_thread_->Invoke<int32_t>(
+      RTC_FROM_HERE,
       Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread,
-           this,
-           callback));
+           this, callback));
 }
 
 int32_t MediaCodecVideoEncoder::Release() {
   ALOGD << "EncoderRelease request";
   return codec_thread_->Invoke<int32_t>(
-      Bind(&MediaCodecVideoEncoder::ReleaseOnCodecThread, this));
+      RTC_FROM_HERE, Bind(&MediaCodecVideoEncoder::ReleaseOnCodecThread, this));
 }
 
 int32_t MediaCodecVideoEncoder::SetChannelParameters(uint32_t /* packet_loss */,
@@ -452,10 +450,8 @@
 int32_t MediaCodecVideoEncoder::SetRates(uint32_t new_bit_rate,
                                          uint32_t frame_rate) {
   return codec_thread_->Invoke<int32_t>(
-      Bind(&MediaCodecVideoEncoder::SetRatesOnCodecThread,
-           this,
-           new_bit_rate,
-           frame_rate));
+      RTC_FROM_HERE, Bind(&MediaCodecVideoEncoder::SetRatesOnCodecThread, this,
+                          new_bit_rate, frame_rate));
 }
 
 void MediaCodecVideoEncoder::OnMessage(rtc::Message* msg) {
@@ -478,7 +474,7 @@
 
   // If there aren't more frames to deliver, we can stop the loop
   if (!input_frame_infos_.empty()) {
-    codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+    codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
   } else {
     output_delivery_loop_running_ = false;
   }
@@ -742,7 +738,7 @@
 
   if (!output_delivery_loop_running_) {
     output_delivery_loop_running_ = true;
-    codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+    codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
   }
 
   if (!DeliverPendingOutputs(jni)) {
@@ -1178,6 +1174,7 @@
   // directly.
   RTC_DCHECK(!codec_thread_checker_.CalledOnValidThread());
   codec_thread_->Invoke<void>(
+      RTC_FROM_HERE,
       Bind(&MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread, this));
 }
 
diff --git a/webrtc/api/java/jni/androidnetworkmonitor_jni.cc b/webrtc/api/java/jni/androidnetworkmonitor_jni.cc
index b7857e2..a815e27 100644
--- a/webrtc/api/java/jni/androidnetworkmonitor_jni.cc
+++ b/webrtc/api/java/jni/androidnetworkmonitor_jni.cc
@@ -268,8 +268,9 @@
 
 void AndroidNetworkMonitor::OnNetworkConnected(
     const NetworkInformation& network_info) {
-  worker_thread()->Invoke<void>(rtc::Bind(
-      &AndroidNetworkMonitor::OnNetworkConnected_w, this, network_info));
+  worker_thread()->Invoke<void>(
+      RTC_FROM_HERE, rtc::Bind(&AndroidNetworkMonitor::OnNetworkConnected_w,
+                               this, network_info));
   // Fire SignalNetworksChanged to update the list of networks.
   OnNetworksChanged();
 }
@@ -288,6 +289,7 @@
 void AndroidNetworkMonitor::OnNetworkDisconnected(NetworkHandle handle) {
   LOG(LS_INFO) << "Network disconnected for handle " << handle;
   worker_thread()->Invoke<void>(
+      RTC_FROM_HERE,
       rtc::Bind(&AndroidNetworkMonitor::OnNetworkDisconnected_w, this, handle));
 }
 
diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc
index 58f4d74..82d8c8e 100644
--- a/webrtc/api/java/jni/androidvideocapturer_jni.cc
+++ b/webrtc/api/java/jni/androidvideocapturer_jni.cc
@@ -107,15 +107,17 @@
 
 template <typename... Args>
 void AndroidVideoCapturerJni::AsyncCapturerInvoke(
-    const char* method_name,
+    const rtc::Location& posted_from,
     void (webrtc::AndroidVideoCapturer::*method)(Args...),
     typename Identity<Args>::type... args) {
   rtc::CritScope cs(&capturer_lock_);
   if (!invoker_) {
-    LOG(LS_WARNING) << method_name << "() called for closed capturer.";
+    LOG(LS_WARNING) << posted_from.function_name()
+                    << "() called for closed capturer.";
     return;
   }
-  invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...));
+  invoker_->AsyncInvoke<void>(posted_from,
+                              rtc::Bind(method, capturer_, args...));
 }
 
 std::vector<cricket::VideoFormat>
@@ -162,9 +164,8 @@
 
 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) {
   LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success;
-  AsyncCapturerInvoke("OnCapturerStarted",
-                      &webrtc::AndroidVideoCapturer::OnCapturerStarted,
-                      success);
+  AsyncCapturerInvoke(
+      RTC_FROM_HERE, &webrtc::AndroidVideoCapturer::OnCapturerStarted, success);
 }
 
 void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame,
@@ -308,7 +309,7 @@
 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width,
                                                     int height,
                                                     int fps) {
-  AsyncCapturerInvoke("OnOutputFormatRequest",
+  AsyncCapturerInvoke(RTC_FROM_HERE,
                       &webrtc::AndroidVideoCapturer::OnOutputFormatRequest,
                       width, height, fps);
 }
diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.h b/webrtc/api/java/jni/androidvideocapturer_jni.h
index 4a803d9..00c7d91 100644
--- a/webrtc/api/java/jni/androidvideocapturer_jni.h
+++ b/webrtc/api/java/jni/androidvideocapturer_jni.h
@@ -68,7 +68,7 @@
   // are not guaranteed to be delivered.
   template <typename... Args>
   void AsyncCapturerInvoke(
-      const char* method_name,
+      const rtc::Location& posted_from,
       void (webrtc::AndroidVideoCapturer::*method)(Args...),
       typename Identity<Args>::type... args);
 
diff --git a/webrtc/api/java/jni/peerconnection_jni.cc b/webrtc/api/java/jni/peerconnection_jni.cc
index 0dc9b5e..a5ba254 100644
--- a/webrtc/api/java/jni/peerconnection_jni.cc
+++ b/webrtc/api/java/jni/peerconnection_jni.cc
@@ -1119,9 +1119,12 @@
 
 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() {
   LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads.";
-  network_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
-  worker_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
-  signaling_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
+  network_thread_->Invoke<void>(RTC_FROM_HERE,
+                                [this] { JavaCallbackOnFactoryThreads(); });
+  worker_thread_->Invoke<void>(RTC_FROM_HERE,
+                               [this] { JavaCallbackOnFactoryThreads(); });
+  signaling_thread_->Invoke<void>(RTC_FROM_HERE,
+                                  [this] { JavaCallbackOnFactoryThreads(); });
 }
 
 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni,
diff --git a/webrtc/api/mediacontroller.cc b/webrtc/api/mediacontroller.cc
index 2e4501b..e688e39 100644
--- a/webrtc/api/mediacontroller.cc
+++ b/webrtc/api/mediacontroller.cc
@@ -35,9 +35,9 @@
         media_config_(media_config),
         channel_manager_(channel_manager) {
     RTC_DCHECK(worker_thread);
-    worker_thread_->Invoke<void>(
-        rtc::Bind(&MediaController::Construct_w, this,
-                  channel_manager_->media_engine()));
+    worker_thread_->Invoke<void>(RTC_FROM_HERE,
+                                 rtc::Bind(&MediaController::Construct_w, this,
+                                           channel_manager_->media_engine()));
   }
   ~MediaController() override {
     Close();
@@ -45,7 +45,8 @@
 
   // webrtc::MediaControllerInterface implementation.
   void Close() override {
-    worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Close_w, this));
+    worker_thread_->Invoke<void>(RTC_FROM_HERE,
+                                 rtc::Bind(&MediaController::Close_w, this));
   }
   webrtc::Call* call_w() override {
     RTC_DCHECK(worker_thread_->IsCurrent());
diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc
index 6b5cc69b..b9cb83e 100644
--- a/webrtc/api/peerconnection.cc
+++ b/webrtc/api/peerconnection.cc
@@ -563,7 +563,8 @@
   // which will trigger some final actions in PeerConnection...
   session_.reset(nullptr);
   // port_allocator_ lives on the network thread and should be destroyed there.
-  network_thread()->Invoke<void>([this] { port_allocator_.reset(nullptr); });
+  network_thread()->Invoke<void>(RTC_FROM_HERE,
+                                 [this] { port_allocator_.reset(nullptr); });
 }
 
 bool PeerConnection::Initialize(
@@ -582,8 +583,9 @@
 
   // The port allocator lives on the network thread and should be initialized
   // there.
-  if (!network_thread()->Invoke<bool>(rtc::Bind(
-          &PeerConnection::InitializePortAllocator_n, this, configuration))) {
+  if (!network_thread()->Invoke<bool>(
+          RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n,
+                                   this, configuration))) {
     return false;
   }
 
@@ -833,7 +835,7 @@
   }
 
   stats_->UpdateStats(level);
-  signaling_thread()->Post(this, MSG_GETSTATS,
+  signaling_thread()->Post(RTC_FROM_HERE, this, MSG_GETSTATS,
                            new GetStatsMsg(observer, track));
   return true;
 }
@@ -1062,7 +1064,8 @@
   }
 
   SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
-  signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
+  signaling_thread()->Post(RTC_FROM_HERE, this,
+                           MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
 
   // MaybeStartGathering needs to be called after posting
   // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates
@@ -1173,13 +1176,15 @@
   UpdateEndedRemoteMediaStreams();
 
   SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
-  signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
+  signaling_thread()->Post(RTC_FROM_HERE, this,
+                           MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
 }
 
 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) {
   TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration");
   if (port_allocator_) {
     if (!network_thread()->Invoke<bool>(
+            RTC_FROM_HERE,
             rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this,
                       configuration))) {
       return false;
@@ -1492,7 +1497,8 @@
     const std::string& error) {
   SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
   msg->error = error;
-  signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_FAILED, msg);
+  signaling_thread()->Post(RTC_FROM_HERE, this,
+                           MSG_SET_SESSIONDESCRIPTION_FAILED, msg);
 }
 
 void PeerConnection::PostCreateSessionDescriptionFailure(
@@ -1500,7 +1506,8 @@
     const std::string& error) {
   CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
   msg->error = error;
-  signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
+  signaling_thread()->Post(RTC_FROM_HERE, this,
+                           MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
 }
 
 bool PeerConnection::GetOptionsForOffer(
@@ -1999,7 +2006,8 @@
       // we can't free it directly here; we need to free it asynchronously.
       sctp_data_channels_to_free_.push_back(*it);
       sctp_data_channels_.erase(it);
-      signaling_thread()->Post(this, MSG_FREE_DATACHANNELS, nullptr);
+      signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FREE_DATACHANNELS,
+                               nullptr);
       return;
     }
   }
diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc
index 178c59b..8500422 100644
--- a/webrtc/api/peerconnectionfactory.cc
+++ b/webrtc/api/peerconnectionfactory.cc
@@ -66,7 +66,7 @@
   MethodCall0<PeerConnectionFactory, bool> call(
       pc_factory.get(),
       &PeerConnectionFactory::Initialize);
-  bool result =  call.Marshal(signaling_thread);
+  bool result = call.Marshal(RTC_FROM_HERE, signaling_thread);
 
   if (!result) {
     return nullptr;
@@ -146,8 +146,9 @@
   // TODO:  Need to make sure only one VoE is created inside
   // WebRtcMediaEngine.
   cricket::MediaEngineInterface* media_engine =
-      worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind(
-      &PeerConnectionFactory::CreateMediaEngine_w, this));
+      worker_thread_->Invoke<cricket::MediaEngineInterface*>(
+          RTC_FROM_HERE,
+          rtc::Bind(&PeerConnectionFactory::CreateMediaEngine_w, this));
 
   channel_manager_.reset(new cricket::ChannelManager(
       media_engine, worker_thread_, network_thread_));
@@ -256,8 +257,8 @@
         default_network_manager_.get(), default_socket_factory_.get()));
   }
   network_thread_->Invoke<void>(
-      rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask, allocator.get(),
-                options_.network_ignore_mask));
+      RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
+                               allocator.get(), options_.network_ignore_mask));
 
   rtc::scoped_refptr<PeerConnection> pc(
       new rtc::RefCountedObject<PeerConnection>(this));
diff --git a/webrtc/api/peerconnectionfactoryproxy.h b/webrtc/api/peerconnectionfactoryproxy.h
index f0dea42..aad97e8 100644
--- a/webrtc/api/peerconnectionfactoryproxy.h
+++ b/webrtc/api/peerconnectionfactoryproxy.h
@@ -33,6 +33,7 @@
       PeerConnectionObserver* a5) override {
     return signaling_thread_
         ->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
+            RTC_FROM_HERE,
             rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot,
                       this, a1, a2, a3.release(), a4.release(), a5));
   }
@@ -43,6 +44,7 @@
       PeerConnectionObserver* a5) override {
     return signaling_thread_
         ->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
+            RTC_FROM_HERE,
             rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot,
                       this, a1, a3.release(), a4.release(), a5));
   }
diff --git a/webrtc/api/proxy.h b/webrtc/api/proxy.h
index 20a5b49..746a758 100644
--- a/webrtc/api/proxy.h
+++ b/webrtc/api/proxy.h
@@ -107,12 +107,12 @@
       : e_(), proxy_(proxy) {}
   ~SynchronousMethodCall() {}
 
-  void Invoke(rtc::Thread* t) {
+  void Invoke(const rtc::Location& posted_from, rtc::Thread* t) {
     if (t->IsCurrent()) {
       proxy_->OnMessage(NULL);
     } else {
       e_.reset(new rtc::Event(false, false));
-      t->Post(this, 0);
+      t->Post(posted_from, this, 0);
       e_->Wait(rtc::Event::kForever);
     }
   }
@@ -132,8 +132,8 @@
   typedef R (C::*Method)();
   MethodCall0(C* c, Method m) : c_(c), m_(m) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -152,8 +152,8 @@
   typedef R (C::*Method)() const;
   ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -172,8 +172,8 @@
   typedef R (C::*Method)(T1 a1);
   MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -193,8 +193,8 @@
   typedef R (C::*Method)(T1 a1) const;
   ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -214,8 +214,8 @@
   typedef R (C::*Method)(T1 a1, T2 a2);
   MethodCall2(C* c, Method m, T1 a1, T2 a2) : c_(c), m_(m), a1_(a1), a2_(a2) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -237,8 +237,8 @@
   MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3)
       : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -262,8 +262,8 @@
   MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4)
       : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -288,8 +288,8 @@
   MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
       : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5) {}
 
-  R Marshal(rtc::Thread* t) {
-    internal::SynchronousMethodCall(this).Invoke(t);
+  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
+    internal::SynchronousMethodCall(this).Invoke(posted_from, t);
     return r_.value();
   }
 
@@ -319,7 +319,7 @@
     ~c##ProxyWithInternal() {                                                  \
       MethodCall0<c##ProxyWithInternal, void> call(                            \
           this, &c##ProxyWithInternal::Release_s);                             \
-      call.Marshal(signaling_thread_);                                         \
+      call.Marshal(RTC_FROM_HERE, signaling_thread_);                          \
     }                                                                          \
                                                                                \
    public:                                                                     \
@@ -349,7 +349,7 @@
     ~c##ProxyWithInternal() {                                   \
       MethodCall0<c##ProxyWithInternal, void> call(             \
           this, &c##ProxyWithInternal::Release_s);              \
-      call.Marshal(signaling_thread_);                          \
+      call.Marshal(RTC_FROM_HERE, signaling_thread_);           \
     }                                                           \
                                                                 \
    public:                                                      \
@@ -363,67 +363,67 @@
     const INTERNAL_CLASS* internal() const { return c_.get(); } \
     INTERNAL_CLASS* internal() { return c_.get(); }
 
-#define PROXY_METHOD0(r, method)                  \
-  r method() override {                           \
-    MethodCall0<C, r> call(c_.get(), &C::method); \
-    return call.Marshal(signaling_thread_);       \
+#define PROXY_METHOD0(r, method)                           \
+  r method() override {                                    \
+    MethodCall0<C, r> call(c_.get(), &C::method);          \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
   }
 
-#define PROXY_CONSTMETHOD0(r, method)                  \
-  r method() const override {                          \
-    ConstMethodCall0<C, r> call(c_.get(), &C::method); \
-    return call.Marshal(signaling_thread_);            \
+#define PROXY_CONSTMETHOD0(r, method)                      \
+  r method() const override {                              \
+    ConstMethodCall0<C, r> call(c_.get(), &C::method);     \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
   }
 
-#define PROXY_METHOD1(r, method, t1)                      \
-  r method(t1 a1) override {                              \
-    MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
-    return call.Marshal(signaling_thread_);               \
+#define PROXY_METHOD1(r, method, t1)                       \
+  r method(t1 a1) override {                               \
+    MethodCall1<C, r, t1> call(c_.get(), &C::method, a1);  \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
   }
 
 #define PROXY_CONSTMETHOD1(r, method, t1)                      \
   r method(t1 a1) const override {                             \
     ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
-    return call.Marshal(signaling_thread_);                    \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_);     \
   }
 
 #define PROXY_METHOD2(r, method, t1, t2)                          \
   r method(t1 a1, t2 a2) override {                               \
     MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \
-    return call.Marshal(signaling_thread_);                       \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_);        \
   }
 
 #define PROXY_METHOD3(r, method, t1, t2, t3)                              \
   r method(t1 a1, t2 a2, t3 a3) override {                                \
     MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3); \
-    return call.Marshal(signaling_thread_);                               \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_);                \
   }
 
 #define PROXY_METHOD4(r, method, t1, t2, t3, t4)                             \
   r method(t1 a1, t2 a2, t3 a3, t4 a4) override {                            \
     MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \
                                            a4);                              \
-    return call.Marshal(signaling_thread_);                                  \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_);                   \
   }
 
 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5)                         \
   r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override {                     \
     MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \
                                                a3, a4, a5);                  \
-    return call.Marshal(signaling_thread_);                                  \
+    return call.Marshal(RTC_FROM_HERE, signaling_thread_);                   \
   }
 
 // Define methods which should be invoked on the worker thread.
 #define PROXY_WORKER_METHOD1(r, method, t1)               \
   r method(t1 a1) override {                              \
     MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
-    return call.Marshal(worker_thread_);                  \
+    return call.Marshal(RTC_FROM_HERE, worker_thread_);   \
   }
 
 #define PROXY_WORKER_METHOD2(r, method, t1, t2)                   \
   r method(t1 a1, t2 a2) override {                               \
     MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \
-    return call.Marshal(worker_thread_);                          \
+    return call.Marshal(RTC_FROM_HERE, worker_thread_);           \
   }
 
 #define END_SIGNALING_PROXY()             \
diff --git a/webrtc/api/quicdatachannel.cc b/webrtc/api/quicdatachannel.cc
index 5420da1..f4f5732 100644
--- a/webrtc/api/quicdatachannel.cc
+++ b/webrtc/api/quicdatachannel.cc
@@ -92,7 +92,7 @@
     return false;
   }
   return worker_thread_->Invoke<bool>(
-      rtc::Bind(&QuicDataChannel::Send_w, this, buffer));
+      RTC_FROM_HERE, rtc::Bind(&QuicDataChannel::Send_w, this, buffer));
 }
 
 bool QuicDataChannel::Send_w(const DataBuffer& buffer) {
@@ -187,8 +187,9 @@
   RTC_DCHECK(worker_thread_->IsCurrent());
   buffered_amount_ = buffered_amount;
   invoker_.AsyncInvoke<void>(
-      signaling_thread_, rtc::Bind(&QuicDataChannel::OnBufferedAmountChange_s,
-                                   this, buffered_amount));
+      RTC_FROM_HERE, signaling_thread_,
+      rtc::Bind(&QuicDataChannel::OnBufferedAmountChange_s, this,
+                buffered_amount));
 }
 
 void QuicDataChannel::Close() {
@@ -198,7 +199,8 @@
   }
   LOG(LS_INFO) << "Closing QUIC data channel.";
   SetState_s(kClosing);
-  worker_thread_->Invoke<void>(rtc::Bind(&QuicDataChannel::Close_w, this));
+  worker_thread_->Invoke<void>(RTC_FROM_HERE,
+                               rtc::Bind(&QuicDataChannel::Close_w, this));
   SetState_s(kClosed);
 }
 
@@ -236,7 +238,7 @@
   quic_transport_channel_ = channel;
   LOG(LS_INFO) << "Setting QuicTransportChannel for QUIC data channel " << id_;
   DataState data_channel_state = worker_thread_->Invoke<DataState>(
-      rtc::Bind(&QuicDataChannel::SetTransportChannel_w, this));
+      RTC_FROM_HERE, rtc::Bind(&QuicDataChannel::SetTransportChannel_w, this));
   SetState_s(data_channel_state);
   return true;
 }
@@ -269,7 +271,7 @@
                  << " has finished receiving data for QUIC data channel "
                  << id_;
     DataBuffer final_message(message.buffer, false);
-    invoker_.AsyncInvoke<void>(signaling_thread_,
+    invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
                                rtc::Bind(&QuicDataChannel::OnMessage_s, this,
                                          std::move(final_message)));
     message.stream->Close();
@@ -316,7 +318,7 @@
   received_data.AppendData(data, len);
   DataBuffer final_message(std::move(received_data), false);
   invoker_.AsyncInvoke<void>(
-      signaling_thread_,
+      RTC_FROM_HERE, signaling_thread_,
       rtc::Bind(&QuicDataChannel::OnMessage_s, this, std::move(final_message)));
   // Once the stream is closed, OnDataReceived will not fire for the stream.
   stream->Close();
@@ -327,7 +329,8 @@
   RTC_DCHECK(channel == quic_transport_channel_);
   LOG(LS_INFO) << "QuicTransportChannel is ready to send";
   invoker_.AsyncInvoke<void>(
-      signaling_thread_, rtc::Bind(&QuicDataChannel::SetState_s, this, kOpen));
+      RTC_FROM_HERE, signaling_thread_,
+      rtc::Bind(&QuicDataChannel::SetState_s, this, kOpen));
 }
 
 void QuicDataChannel::OnWriteBlockedStreamClosed(net::QuicStreamId stream_id,
@@ -346,7 +349,7 @@
 
 void QuicDataChannel::OnConnectionClosed() {
   RTC_DCHECK(worker_thread_->IsCurrent());
-  invoker_.AsyncInvoke<void>(signaling_thread_,
+  invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
                              rtc::Bind(&QuicDataChannel::Close, this));
 }
 
diff --git a/webrtc/api/remoteaudiosource.cc b/webrtc/api/remoteaudiosource.cc
index 2d0785a..14eb82b 100644
--- a/webrtc/api/remoteaudiosource.cc
+++ b/webrtc/api/remoteaudiosource.cc
@@ -148,7 +148,7 @@
 void RemoteAudioSource::OnAudioProviderGone() {
   // Called when the data provider is deleted.  It may be the worker thread
   // in libjingle or may be a different worker thread.
-  main_thread_->Post(new MessageHandler(this));
+  main_thread_->Post(RTC_FROM_HERE, new MessageHandler(this));
 }
 
 void RemoteAudioSource::OnMessage(rtc::Message* msg) {
diff --git a/webrtc/api/test/fakeaudiocapturemodule.cc b/webrtc/api/test/fakeaudiocapturemodule.cc
index a32ef64..43ff664 100644
--- a/webrtc/api/test/fakeaudiocapturemodule.cc
+++ b/webrtc/api/test/fakeaudiocapturemodule.cc
@@ -627,7 +627,7 @@
       process_thread_.reset(new rtc::Thread());
       process_thread_->Start();
     }
-    process_thread_->Post(this, MSG_START_PROCESS);
+    process_thread_->Post(RTC_FROM_HERE, this, MSG_START_PROCESS);
   } else {
     if (process_thread_) {
       process_thread_->Stop();
@@ -668,7 +668,7 @@
   const int64_t current_time = rtc::TimeMillis();
   const int64_t wait_time =
       (next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0;
-  process_thread_->PostDelayed(wait_time, this, MSG_RUN_PROCESS);
+  process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS);
 }
 
 void FakeAudioCaptureModule::ReceiveFrameP() {
diff --git a/webrtc/api/test/fakeperiodicvideocapturer.h b/webrtc/api/test/fakeperiodicvideocapturer.h
index ab98855..2c16195 100644
--- a/webrtc/api/test/fakeperiodicvideocapturer.h
+++ b/webrtc/api/test/fakeperiodicvideocapturer.h
@@ -42,7 +42,7 @@
   virtual cricket::CaptureState Start(const cricket::VideoFormat& format) {
     cricket::CaptureState state = FakeVideoCapturer::Start(format);
     if (state != cricket::CS_FAILED) {
-      rtc::Thread::Current()->Post(this, MSG_CREATEFRAME);
+      rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_CREATEFRAME);
     }
     return state;
   }
@@ -54,8 +54,9 @@
     if (msg->message_id == MSG_CREATEFRAME) {
       if (IsRunning()) {
         CaptureFrame();
-        rtc::Thread::Current()->PostDelayed(static_cast<int>(
-            GetCaptureFormat()->interval / rtc::kNumNanosecsPerMillisec),
+        rtc::Thread::Current()->PostDelayed(
+            RTC_FROM_HERE, static_cast<int>(GetCaptureFormat()->interval /
+                                            rtc::kNumNanosecsPerMillisec),
             this, MSG_CREATEFRAME);
         }
     }
diff --git a/webrtc/api/test/fakertccertificategenerator.h b/webrtc/api/test/fakertccertificategenerator.h
index eaef737..77ff9dc 100644
--- a/webrtc/api/test/fakertccertificategenerator.h
+++ b/webrtc/api/test/fakertccertificategenerator.h
@@ -157,7 +157,7 @@
                  key_params.ec_curve() == rtc::EC_NIST_P256);
       msg_id = MSG_SUCCESS_ECDSA;
     }
-    rtc::Thread::Current()->Post(this, msg_id, msg);
+    rtc::Thread::Current()->Post(RTC_FROM_HERE, this, msg_id, msg);
   }
 
   static rtc::scoped_refptr<rtc::RTCCertificate> GenerateCertificate() {
diff --git a/webrtc/api/videocapturertracksource.cc b/webrtc/api/videocapturertracksource.cc
index b99a2d1..2321d83 100644
--- a/webrtc/api/videocapturertracksource.cc
+++ b/webrtc/api/videocapturertracksource.cc
@@ -352,8 +352,8 @@
   format_ = GetBestCaptureFormat(formats);
   // Start the camera with our best guess.
   if (!worker_thread_->Invoke<bool>(
-          rtc::Bind(&cricket::VideoCapturer::StartCapturing,
-                    video_capturer_.get(), format_))) {
+          RTC_FROM_HERE, rtc::Bind(&cricket::VideoCapturer::StartCapturing,
+                                   video_capturer_.get(), format_))) {
     SetState(kEnded);
     return;
   }
@@ -372,6 +372,7 @@
   }
   started_ = false;
   worker_thread_->Invoke<void>(
+      RTC_FROM_HERE,
       rtc::Bind(&cricket::VideoCapturer::Stop, video_capturer_.get()));
 }
 
@@ -380,8 +381,8 @@
     return;
   }
   if (!worker_thread_->Invoke<bool>(
-          rtc::Bind(&cricket::VideoCapturer::StartCapturing,
-                    video_capturer_.get(), format_))) {
+          RTC_FROM_HERE, rtc::Bind(&cricket::VideoCapturer::StartCapturing,
+                                   video_capturer_.get(), format_))) {
     SetState(kEnded);
     return;
   }
@@ -394,8 +395,9 @@
     cricket::CaptureState capture_state) {
   if (rtc::Thread::Current() != signaling_thread_) {
     invoker_.AsyncInvoke<void>(
-        signaling_thread_, rtc::Bind(&VideoCapturerTrackSource::OnStateChange,
-                                     this, capturer, capture_state));
+        RTC_FROM_HERE, signaling_thread_,
+        rtc::Bind(&VideoCapturerTrackSource::OnStateChange, this, capturer,
+                  capture_state));
     return;
   }
 
diff --git a/webrtc/api/webrtcsessiondescriptionfactory.cc b/webrtc/api/webrtcsessiondescriptionfactory.cc
index 08392e5..29da6f2 100644
--- a/webrtc/api/webrtcsessiondescriptionfactory.cc
+++ b/webrtc/api/webrtcsessiondescriptionfactory.cc
@@ -145,7 +145,7 @@
     // it in the constructor then the caller has not had a chance to connect to
     // |SignalCertificateReady|.
     signaling_thread_->Post(
-        this, MSG_USE_CONSTRUCTOR_CERTIFICATE,
+        RTC_FROM_HERE, this, MSG_USE_CONSTRUCTOR_CERTIFICATE,
         new rtc::ScopedRefMessageData<rtc::RTCCertificate>(certificate));
   } else {
     // Generate certificate.
@@ -450,7 +450,8 @@
     CreateSessionDescriptionObserver* observer, const std::string& error) {
   CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
   msg->error = error;
-  signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
+  signaling_thread_->Post(RTC_FROM_HERE, this,
+                          MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
   LOG(LS_ERROR) << "Create SDP failed: " << error;
 }
 
@@ -459,7 +460,8 @@
     SessionDescriptionInterface* description) {
   CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
   msg->description.reset(description);
-  signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
+  signaling_thread_->Post(RTC_FROM_HERE, this,
+                          MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
 }
 
 void WebRtcSessionDescriptionFactory::OnCertificateRequestFailed() {