Export the standardized IceConnectionState.

Since a lot of native users have taken dependencies on our old, non-standard behaviour
we'll have to have two ice connection states living side by side until we can get rid
of the old one.

Bug: webrtc:6145
Change-Id: I9b673bffeb1dfcf410f7c56d4def5912121e644c
Reviewed-on: https://webrtc-review.googlesource.com/c/113421
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25929}
diff --git a/api/peerconnectioninterface.cc b/api/peerconnectioninterface.cc
index 665760c9..a9b95a9 100644
--- a/api/peerconnectioninterface.cc
+++ b/api/peerconnectioninterface.cc
@@ -160,9 +160,14 @@
   return SetBitrate(bitrate);
 }
 
+PeerConnectionInterface::IceConnectionState
+PeerConnectionInterface::standardized_ice_connection_state() {
+  return PeerConnectionInterface::IceConnectionState::kIceConnectionFailed;
+}
+
 PeerConnectionInterface::PeerConnectionState
 PeerConnectionInterface::peer_connection_state() {
-  return PeerConnectionInterface::PeerConnectionState::kNew;
+  return PeerConnectionInterface::PeerConnectionState::kFailed;
 }
 
 bool PeerConnectionInterface::StartRtcEventLog(rtc::PlatformFile file,
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index 4a7b051..4be3d2f 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -1041,12 +1041,16 @@
   // Returns the current SignalingState.
   virtual SignalingState signaling_state() = 0;
 
-  // Returns the aggregate state of all ICE *and* DTLS transports.
-  // TODO(jonasolsson): Replace with standardized_ice_connection_state once it
-  // is ready, see crbug.com/webrtc/6145
+  // Returns an aggregate state of all ICE *and* DTLS transports.
+  // This is left in place to avoid breaking native clients who expect our old,
+  // nonstandard behavior.
+  // TODO(jonasolsson): deprecate and remove this.
   virtual IceConnectionState ice_connection_state() = 0;
 
-  // Returns the aggregated state of all ICE and DTLS transports.
+  // Returns an aggregated state of all ICE transports.
+  virtual IceConnectionState standardized_ice_connection_state();
+
+  // Returns an aggregated state of all ICE and DTLS transports.
   virtual PeerConnectionState peer_connection_state();
 
   virtual IceGatheringState ice_gathering_state() = 0;
@@ -1108,15 +1112,21 @@
   // has begun.
   virtual void OnRenegotiationNeeded() = 0;
 
-  // Called any time the IceConnectionState changes.
+  // Called any time the legacy IceConnectionState changes.
   //
   // Note that our ICE states lag behind the standard slightly. The most
   // notable differences include the fact that "failed" occurs after 15
   // seconds, not 30, and this actually represents a combination ICE + DTLS
   // state, so it may be "failed" if DTLS fails while ICE succeeds.
+  //
+  // TODO(jonasolsson): deprecate and remove this.
   virtual void OnIceConnectionChange(
       PeerConnectionInterface::IceConnectionState new_state) = 0;
 
+  // Called any time the standards-compliant IceConnectionState changes.
+  virtual void OnStandardizedIceConnectionChange(
+      PeerConnectionInterface::IceConnectionState new_state) {}
+
   // Called any time the PeerConnectionState changes.
   virtual void OnConnectionChange(
       PeerConnectionInterface::PeerConnectionState new_state) {}
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 4a5bd92..e166d1e 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -3644,8 +3644,7 @@
   if (IsClosed())
     return;
   standardized_ice_connection_state_ = new_state;
-  // TODO(jonasolsson): Pass this value on to OnIceConnectionChange instead of
-  // the old one once disconnects are handled properly.
+  Observer()->OnStandardizedIceConnectionChange(new_state);
 }
 
 void PeerConnection::SetConnectionState(
diff --git a/pc/peerconnection.h b/pc/peerconnection.h
index b17881c..3105b2f 100644
--- a/pc/peerconnection.h
+++ b/pc/peerconnection.h
@@ -147,7 +147,7 @@
   SignalingState signaling_state() override;
 
   IceConnectionState ice_connection_state() override;
-  IceConnectionState standardized_ice_connection_state();
+  IceConnectionState standardized_ice_connection_state() override;
   PeerConnectionState peer_connection_state() override;
   IceGatheringState ice_gathering_state() override;