Fix segfault when PeerConnection is destroyed during stats collection.

RTCStatsCollector relies on PeerConnection and its WebRtcSession. If the
PeerConnection is destroyed, reference counting keeps the
RTCStatsCollector alive until the request has completed. But the request
is using PeerConnection/WebRtcSession resources that are destroyed in
~PeerConnection().

To get around this problem, RTCStatsCollector::WaitForPendingRequest()
is added, which is invoked at ~PeerConnection().

Integration test added, it caused a segmentation fault before this
change / EXPECT failure.

BUG=chromium:627816

Review-Url: https://codereview.webrtc.org/2583613003
Cr-Commit-Position: refs/heads/master@{#15674}
diff --git a/webrtc/api/rtcstatscollector.h b/webrtc/api/rtcstatscollector.h
index 7b23d24..4268a21 100644
--- a/webrtc/api/rtcstatscollector.h
+++ b/webrtc/api/rtcstatscollector.h
@@ -71,8 +71,13 @@
   // calling |GetStatsReport| guarantees fresh stats.
   void ClearCachedStatsReport();
 
+  // If there is a |GetStatsReport| requests in-flight, waits until it has been
+  // completed. Must be called on the signaling thread.
+  void WaitForPendingRequest();
+
  protected:
   RTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime_us);
+  ~RTCStatsCollector();
 
   // Stats gathering on a particular thread. Calls |AddPartialResults| before
   // returning. Virtual for the sake of testing.