Reland of "Move RtcEventLog object from inside VoiceEngine to Call.", "Fix to make the start/stop functions for the Rtc Eventlog non-virtual." and "Fix for RtcEventLog ObjC interface"

The breaking tests in Chromium have been temporarily disabled, they will be fixed and reenabled soon.

Original CLs: https://codereview.webrtc.org/1748403002/, https://codereview.webrtc.org/2107253002/ and https://codereview.webrtc.org/2106103003/.

TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org,tkchin@webrtc.org
BUG=webrtc:4741, webrtc:5603, chromium:609749

Review-Url: https://codereview.webrtc.org/2110113003
Cr-Commit-Position: refs/heads/master@{#13379}
diff --git a/webrtc/api/android/java/src/org/webrtc/PeerConnection.java b/webrtc/api/android/java/src/org/webrtc/PeerConnection.java
index 70813a6..965cea4 100644
--- a/webrtc/api/android/java/src/org/webrtc/PeerConnection.java
+++ b/webrtc/api/android/java/src/org/webrtc/PeerConnection.java
@@ -257,6 +257,23 @@
     return nativeGetStats(observer, (track == null) ? 0 : track.nativeTrack);
   }
 
+  // Starts recording an RTC event log. Ownership of the file is transfered to
+  // the native code. If an RTC event log is already being recorded, it will be
+  // stopped and a new one will start using the provided file. Logging will
+  // continue until the stopRtcEventLog function is called. The max_size_bytes
+  // argument is ignored, it is added for future use.
+  public boolean startRtcEventLog(
+      int file_descriptor, long max_size_bytes) {
+    return nativeStartRtcEventLog(
+        nativePeerConnection, file_descriptor, max_size_bytes);
+  }
+
+  // Stops recording an RTC event log. If no RTC event log is currently being
+  // recorded, this call will have no effect.
+  public void stopRtcEventLog() {
+    nativeStopRtcEventLog(nativePeerConnection);
+  }
+
   // TODO(fischman): add support for DTMF-related methods once that API
   // stabilizes.
   public native SignalingState signalingState();
@@ -307,4 +324,10 @@
   private native List<RtpSender> nativeGetSenders();
 
   private native List<RtpReceiver> nativeGetReceivers();
+
+  private static native boolean nativeStartRtcEventLog(
+      long nativePeerConnection, int file_descriptor, long max_size_bytes);
+
+  private static native void nativeStopRtcEventLog(long nativePeerConnection);
+
 }
diff --git a/webrtc/api/android/java/src/org/webrtc/PeerConnectionFactory.java b/webrtc/api/android/java/src/org/webrtc/PeerConnectionFactory.java
index 0c1ef3c..2edd56e 100644
--- a/webrtc/api/android/java/src/org/webrtc/PeerConnectionFactory.java
+++ b/webrtc/api/android/java/src/org/webrtc/PeerConnectionFactory.java
@@ -148,28 +148,6 @@
     nativeStopAecDump(nativeFactory);
   }
 
-  // Starts recording an RTC event log. Ownership of the file is transfered to
-  // the native code. If an RTC event log is already being recorded, it will be
-  // stopped and a new one will start using the provided file.
-  public boolean startRtcEventLog(int file_descriptor) {
-    return startRtcEventLog(file_descriptor, -1);
-  }
-
-  // Same as above, but allows setting an upper limit to the size of the
-  // generated logfile.
-  public boolean startRtcEventLog(int file_descriptor,
-                                  int filesize_limit_bytes) {
-    return nativeStartRtcEventLog(nativeFactory,
-                                  file_descriptor,
-                                  filesize_limit_bytes);
-  }
-
-  // Stops recording an RTC event log. If no RTC event log is currently being
-  // recorded, this call will have no effect.
-  public void stopRtcEventLog() {
-    nativeStopRtcEventLog(nativeFactory);
-  }
-
   @Deprecated
   public void setOptions(Options options) {
     nativeSetOptions(nativeFactory, options);
@@ -275,12 +253,6 @@
 
   private static native void nativeStopAecDump(long nativeFactory);
 
-  private static native boolean nativeStartRtcEventLog(long nativeFactory,
-                                                       int file_descriptor,
-                                                       int filesize_limit_bytes);
-
-  private static native void nativeStopRtcEventLog(long nativeFactory);
-
   @Deprecated
   public native void nativeSetOptions(long nativeFactory, Options options);
 
diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc
index cc33aa8..be61472 100644
--- a/webrtc/api/peerconnection.cc
+++ b/webrtc/api/peerconnection.cc
@@ -31,10 +31,12 @@
 #include "webrtc/api/videocapturertracksource.h"
 #include "webrtc/api/videotrack.h"
 #include "webrtc/base/arraysize.h"
+#include "webrtc/base/bind.h"
 #include "webrtc/base/logging.h"
 #include "webrtc/base/stringencode.h"
 #include "webrtc/base/stringutils.h"
 #include "webrtc/base/trace_event.h"
+#include "webrtc/call.h"
 #include "webrtc/media/sctp/sctpdataengine.h"
 #include "webrtc/pc/channelmanager.h"
 #include "webrtc/system_wrappers/include/field_trial.h"
@@ -1263,6 +1265,18 @@
   }
 }
 
+bool PeerConnection::StartRtcEventLog(rtc::PlatformFile file,
+                                      int64_t max_size_bytes) {
+  return factory_->worker_thread()->Invoke<bool>(
+      RTC_FROM_HERE, rtc::Bind(&PeerConnection::StartRtcEventLog_w, this, file,
+                               max_size_bytes));
+}
+
+void PeerConnection::StopRtcEventLog() {
+  factory_->worker_thread()->Invoke<void>(
+      RTC_FROM_HERE, rtc::Bind(&PeerConnection::StopRtcEventLog_w, this));
+}
+
 const SessionDescriptionInterface* PeerConnection::local_description() const {
   return session_->local_description();
 }
@@ -2234,4 +2248,12 @@
   return true;
 }
 
+bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file,
+                                        int64_t max_size_bytes) {
+  return media_controller_->call_w()->StartEventLog(file, max_size_bytes);
+}
+
+void PeerConnection::StopRtcEventLog_w() {
+  media_controller_->call_w()->StopEventLog();
+}
 }  // namespace webrtc
diff --git a/webrtc/api/peerconnection.h b/webrtc/api/peerconnection.h
index fc754b9..c4a9a60 100644
--- a/webrtc/api/peerconnection.h
+++ b/webrtc/api/peerconnection.h
@@ -136,6 +136,10 @@
 
   void RegisterUMAObserver(UMAObserver* observer) override;
 
+  bool StartRtcEventLog(rtc::PlatformFile file,
+                        int64_t max_size_bytes) override;
+  void StopRtcEventLog() override;
+
   void Close() override;
 
   // Virtual for unit tests.
@@ -360,6 +364,13 @@
   // is applied.
   bool ReconfigurePortAllocator_n(const RTCConfiguration& configuration);
 
+  // Starts recording an Rtc EventLog using the supplied platform file.
+  // This function should only be called from the worker thread.
+  bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes);
+  // Starts recording an Rtc EventLog using the supplied platform file.
+  // This function should only be called from the worker thread.
+  void StopRtcEventLog_w();
+
   // Storing the factory as a scoped reference pointer ensures that the memory
   // in the PeerConnectionFactoryImpl remains available as long as the
   // PeerConnection is running. It is passed to PeerConnection as a raw pointer.
diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc
index 745de3f..b79e7a2 100644
--- a/webrtc/api/peerconnectionfactory.cc
+++ b/webrtc/api/peerconnectionfactory.cc
@@ -220,17 +220,6 @@
   channel_manager_->StopAecDump();
 }
 
-bool PeerConnectionFactory::StartRtcEventLog(rtc::PlatformFile file,
-                                             int64_t max_size_bytes) {
-  RTC_DCHECK(signaling_thread_->IsCurrent());
-  return channel_manager_->StartRtcEventLog(file, max_size_bytes);
-}
-
-void PeerConnectionFactory::StopRtcEventLog() {
-  RTC_DCHECK(signaling_thread_->IsCurrent());
-  channel_manager_->StopRtcEventLog();
-}
-
 rtc::scoped_refptr<PeerConnectionInterface>
 PeerConnectionFactory::CreatePeerConnection(
     const PeerConnectionInterface::RTCConfiguration& configuration_in,
diff --git a/webrtc/api/peerconnectionfactory.h b/webrtc/api/peerconnectionfactory.h
index d4bc0da..39a6402 100644
--- a/webrtc/api/peerconnectionfactory.h
+++ b/webrtc/api/peerconnectionfactory.h
@@ -80,12 +80,15 @@
 
   bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
   void StopAecDump() override;
-  bool StartRtcEventLog(rtc::PlatformFile file) override {
-    return StartRtcEventLog(file, -1);
-  }
+  // TODO(ivoc) Remove after Chrome is updated.
+  bool StartRtcEventLog(rtc::PlatformFile file) override { return false; }
+  // TODO(ivoc) Remove after Chrome is updated.
   bool StartRtcEventLog(rtc::PlatformFile file,
-                        int64_t max_size_bytes) override;
-  void StopRtcEventLog() override;
+                        int64_t max_size_bytes) override {
+    return false;
+  }
+  // TODO(ivoc) Remove after Chrome is updated.
+  void StopRtcEventLog() override {}
 
   virtual webrtc::MediaControllerInterface* CreateMediaController(
       const cricket::MediaConfig& config) const;
diff --git a/webrtc/api/peerconnectionfactoryproxy.h b/webrtc/api/peerconnectionfactoryproxy.h
index aad97e8..227a685 100644
--- a/webrtc/api/peerconnectionfactoryproxy.h
+++ b/webrtc/api/peerconnectionfactoryproxy.h
@@ -70,6 +70,8 @@
                 CreateAudioTrack, const std::string&,  AudioSourceInterface*)
   PROXY_METHOD2(bool, StartAecDump, rtc::PlatformFile, int64_t)
   PROXY_METHOD0(void, StopAecDump)
+  // TODO(ivoc): Remove the StartRtcEventLog and StopRtcEventLog functions as
+  // soon as they are removed from PeerConnectionFactoryInterface.
   PROXY_METHOD1(bool, StartRtcEventLog, rtc::PlatformFile)
   PROXY_METHOD2(bool, StartRtcEventLog, rtc::PlatformFile, int64_t)
   PROXY_METHOD0(void, StopRtcEventLog)
diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h
index e28a27e..39c4856 100644
--- a/webrtc/api/peerconnectioninterface.h
+++ b/webrtc/api/peerconnectioninterface.h
@@ -493,6 +493,21 @@
   virtual IceConnectionState ice_connection_state() = 0;
   virtual IceGatheringState ice_gathering_state() = 0;
 
+  // Starts RtcEventLog using existing file. Takes ownership of |file| and
+  // passes it on to Call, which will take the ownership. If the
+  // operation fails the file will be closed. The logging will stop
+  // automatically after 10 minutes have passed, or when the StopRtcEventLog
+  // function is called.
+  // TODO(ivoc): Make this pure virtual when Chrome is updated.
+  virtual bool StartRtcEventLog(rtc::PlatformFile file,
+                                int64_t max_size_bytes) {
+    return false;
+  }
+
+  // Stops logging the RtcEventLog.
+  // TODO(ivoc): Make this pure virtual when Chrome is updated.
+  virtual void StopRtcEventLog() {}
+
   // Terminates all media and closes the transport.
   virtual void Close() = 0;
 
@@ -659,25 +674,19 @@
   // Stops logging the AEC dump.
   virtual void StopAecDump() = 0;
 
-  // Starts RtcEventLog using existing file. Takes ownership of |file| and
-  // passes it on to VoiceEngine, which will take the ownership. If the
-  // operation fails the file will be closed. The logging will stop
-  // automatically after 10 minutes have passed, or when the StopRtcEventLog
-  // function is called. A maximum filesize in bytes can be set, the logging
-  // will be stopped before exceeding this limit. If max_size_bytes is set to a
-  // value <= 0, no limit will be used.
-  // This function as well as the StopRtcEventLog don't really belong on this
-  // interface, this is a temporary solution until we move the logging object
-  // from inside voice engine to webrtc::Call, which will happen when the VoE
-  // restructuring effort is further along.
-  // TODO(ivoc): Move this into being:
-  //             PeerConnection => MediaController => webrtc::Call.
+  // This function is deprecated and will be removed when Chrome is updated to
+  // use the equivalent function on PeerConnectionInterface.
+  // TODO(ivoc) Remove after Chrome is updated.
   virtual bool StartRtcEventLog(rtc::PlatformFile file,
                                 int64_t max_size_bytes) = 0;
-  // Deprecated, use the version above.
+  // This function is deprecated and will be removed when Chrome is updated to
+  // use the equivalent function on PeerConnectionInterface.
+  // TODO(ivoc) Remove after Chrome is updated.
   virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
 
-  // Stops logging the RtcEventLog.
+  // This function is deprecated and will be removed when Chrome is updated to
+  // use the equivalent function on PeerConnectionInterface.
+  // TODO(ivoc) Remove after Chrome is updated.
   virtual void StopRtcEventLog() = 0;
 
  protected:
diff --git a/webrtc/api/peerconnectionproxy.h b/webrtc/api/peerconnectionproxy.h
index d35d5ba..37f2e89 100644
--- a/webrtc/api/peerconnectionproxy.h
+++ b/webrtc/api/peerconnectionproxy.h
@@ -74,6 +74,8 @@
   PROXY_METHOD0(IceState, ice_state)
   PROXY_METHOD0(IceConnectionState, ice_connection_state)
   PROXY_METHOD0(IceGatheringState, ice_gathering_state)
+  PROXY_METHOD2(bool, StartRtcEventLog, rtc::PlatformFile, int64_t)
+  PROXY_METHOD0(void, StopRtcEventLog)
   PROXY_METHOD0(void, Close)
 END_SIGNALING_PROXY()