Use CallbackList for DtlsState in dtls_transport.

- This contains a CallbackList disconnect and handled it
  by taking the given subscription tag to subscribe and unsubscribe.
- Left the original sigslot variable until downstream is update after
  this change.

Bug: webrtc:11943
No-Try: True
Change-Id: Ie96d74b9594eae11beaa552f61e40f451242bfab
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203780
Commit-Queue: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33285}
diff --git a/p2p/base/dtls_transport.cc b/p2p/base/dtls_transport.cc
index 4dadcf2..c37cd0f 100644
--- a/p2p/base/dtls_transport.cc
+++ b/p2p/base/dtls_transport.cc
@@ -817,6 +817,7 @@
                       << " to " << state;
   dtls_state_ = state;
   SignalDtlsState(this, state);
+  SendDtlsState(this, state);
 }
 
 void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {
diff --git a/p2p/base/dtls_transport_internal.h b/p2p/base/dtls_transport_internal.h
index 34f7a1a..7771f1f 100644
--- a/p2p/base/dtls_transport_internal.h
+++ b/p2p/base/dtls_transport_internal.h
@@ -115,6 +115,25 @@
   virtual IceTransportInternal* ice_transport() = 0;
 
   sigslot::signal2<DtlsTransportInternal*, DtlsTransportState> SignalDtlsState;
+  // F: void(DtlsTransportInternal*, const DtlsTransportState)
+  template <typename F>
+  void SubscribeDtlsState(F&& callback) {
+    dtls_state_callback_list_.AddReceiver(std::forward<F>(callback));
+  }
+
+  template <typename F>
+  void SubscribeDtlsState(const void* id, F&& callback) {
+    dtls_state_callback_list_.AddReceiver(id, std::forward<F>(callback));
+  }
+  // Unsubscribe the subscription with given id.
+  void UnsubscribeDtlsState(const void* id) {
+    dtls_state_callback_list_.RemoveReceivers(id);
+  }
+
+  void SendDtlsState(DtlsTransportInternal* transport,
+                     DtlsTransportState state) {
+    dtls_state_callback_list_.Send(transport, state);
+  }
 
   // Emitted whenever the Dtls handshake failed on some transport channel.
   // F: void(rtc::SSLHandshakeError)
@@ -134,6 +153,8 @@
   RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal);
   webrtc::CallbackList<const rtc::SSLHandshakeError>
       dtls_handshake_error_callback_list_;
+  webrtc::CallbackList<DtlsTransportInternal*, const DtlsTransportState>
+      dtls_state_callback_list_;
 };
 
 }  // namespace cricket
diff --git a/p2p/base/fake_dtls_transport.h b/p2p/base/fake_dtls_transport.h
index 7061ea4..9ab8998 100644
--- a/p2p/base/fake_dtls_transport.h
+++ b/p2p/base/fake_dtls_transport.h
@@ -86,6 +86,7 @@
   void SetDtlsState(DtlsTransportState state) {
     dtls_state_ = state;
     SignalDtlsState(this, dtls_state_);
+    SendDtlsState(this, dtls_state_);
   }
 
   // Simulates the two DTLS transports connecting to each other.