TurnCustomizer - an interface for modifying stun messages sent by TurnPort

This patch adds an interface that allows modification of stun messages
sent by TurnPort. A user can inject a TurnCustomizer on the RTCConfig
and the TurnCustomizer will be invoked by TurnPort before sending
message. This allows user to e.g add custom attributes as described
in rtf5389.

BUG=webrtc:8313

Change-Id: I6f4333e9f8ff7fd20f32677be19285f15e1180b6
Reviewed-on: https://webrtc-review.googlesource.com/7618
Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20233}
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index e8e428d..a201cc7 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -277,6 +277,7 @@
     bool redetermine_role_on_ice_restart;
     rtc::Optional<int> ice_check_min_interval;
     rtc::Optional<rtc::IntervalRange> ice_regather_interval_range;
+    webrtc::TurnCustomizer* turn_customizer;
   };
   static_assert(sizeof(stuff_being_tested_for_equality) == sizeof(*this),
                 "Did you add something to RTCConfiguration and forget to "
@@ -312,7 +313,8 @@
          enable_ice_renomination == o.enable_ice_renomination &&
          redetermine_role_on_ice_restart == o.redetermine_role_on_ice_restart &&
          ice_check_min_interval == o.ice_check_min_interval &&
-         ice_regather_interval_range == o.ice_regather_interval_range;
+         ice_regather_interval_range == o.ice_regather_interval_range &&
+         turn_customizer == o.turn_customizer;
 }
 
 bool PeerConnectionInterface::RTCConfiguration::operator!=(
@@ -454,6 +456,7 @@
                   << "This shouldn't happen if using PeerConnectionFactory.";
     return false;
   }
+
   if (!observer) {
     // TODO(deadbeef): Why do we do this?
     LOG(LS_ERROR) << "PeerConnection initialized without a "
@@ -1147,6 +1150,7 @@
       configuration.ice_candidate_pool_size;
   modified_config.prune_turn_ports = configuration.prune_turn_ports;
   modified_config.ice_check_min_interval = configuration.ice_check_min_interval;
+  modified_config.turn_customizer = configuration.turn_customizer;
   if (configuration != modified_config) {
     LOG(LS_ERROR) << "Modifying the configuration in an unsupported way.";
     return SafeSetError(RTCErrorType::INVALID_MODIFICATION, error);
@@ -1180,7 +1184,8 @@
           rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this,
                     stun_servers, turn_servers, modified_config.type,
                     modified_config.ice_candidate_pool_size,
-                    modified_config.prune_turn_ports))) {
+                    modified_config.prune_turn_ports,
+                    modified_config.turn_customizer))) {
     LOG(LS_ERROR) << "Failed to apply configuration to PortAllocator.";
     return SafeSetError(RTCErrorType::INTERNAL_ERROR, error);
   }
@@ -2520,7 +2525,8 @@
   // properties set above.
   port_allocator_->SetConfiguration(stun_servers, turn_servers,
                                     configuration.ice_candidate_pool_size,
-                                    configuration.prune_turn_ports);
+                                    configuration.prune_turn_ports,
+                                    configuration.turn_customizer);
   return true;
 }
 
@@ -2529,13 +2535,15 @@
     const std::vector<cricket::RelayServerConfig>& turn_servers,
     IceTransportsType type,
     int candidate_pool_size,
-    bool prune_turn_ports) {
+    bool prune_turn_ports,
+    webrtc::TurnCustomizer* turn_customizer) {
   port_allocator_->set_candidate_filter(
       ConvertIceTransportTypeToCandidateFilter(type));
   // Call this last since it may create pooled allocator sessions using the
   // candidate filter set above.
   return port_allocator_->SetConfiguration(
-      stun_servers, turn_servers, candidate_pool_size, prune_turn_ports);
+      stun_servers, turn_servers, candidate_pool_size, prune_turn_ports,
+      turn_customizer);
 }
 
 bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file,