Add counter for constraint EnableRtpDataChannels

This is the first step in removing the feature:
1) Count
2) Deprecate
3) Remove

Bug: webrtc:6625
Change-Id: Icd9ad6afa7cb427340d075680134fc5d85050353
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270062
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782935}
diff --git a/third_party/blink/public/mojom/web_feature/web_feature.mojom b/third_party/blink/public/mojom/web_feature/web_feature.mojom
index 814cbd3..befde94 100644
--- a/third_party/blink/public/mojom/web_feature/web_feature.mojom
+++ b/third_party/blink/public/mojom/web_feature/web_feature.mojom
@@ -2677,6 +2677,8 @@
   kV8Window_ShowSaveFilePicker_Method = 3341,
   kV8Window_ShowDirectoryPicker_Method = 3342,
   kV8Window_GetOriginPrivateDirectory_Method = 3343,
+  kRTCConstraintEnableRtpDataChannelsTrue = 3344,
+  kRTCConstraintEnableRtpDataChannelsFalse = 3345,
 
   // Add new features immediately above this line. Don't change assigned
   // numbers of any item, and don't reuse removed slots.
diff --git a/third_party/blink/renderer/modules/mediastream/media_constraints_impl.cc b/third_party/blink/renderer/modules/mediastream/media_constraints_impl.cc
index 431d2bc..5dc9b2e 100644
--- a/third_party/blink/renderer/modules/mediastream/media_constraints_impl.cc
+++ b/third_party/blink/renderer/modules/mediastream/media_constraints_impl.cc
@@ -367,6 +367,14 @@
       }
       result.enable_dtls_srtp.SetExact(ToBoolean(constraint.value_));
     } else if (constraint.name_.Equals(kEnableRtpDataChannels)) {
+      bool value = ToBoolean(constraint.value_);
+      if (value) {
+        UseCounter::Count(context,
+                          WebFeature::kRTCConstraintEnableRtpDataChannelsTrue);
+      } else {
+        UseCounter::Count(context,
+                          WebFeature::kRTCConstraintEnableRtpDataChannelsFalse);
+      }
       result.enable_rtp_data_channels.SetExact(ToBoolean(constraint.value_));
     } else if (constraint.name_.Equals(kEnableDscp)) {
       result.enable_dscp.SetExact(ToBoolean(constraint.value_));
diff --git a/third_party/blink/web_tests/fast/peerconnection/RTCPeerConnection-dataChannelTypeCollision.html b/third_party/blink/web_tests/fast/peerconnection/RTCPeerConnection-dataChannelTypeCollision.html
index 9585715..532d41b 100644
--- a/third_party/blink/web_tests/fast/peerconnection/RTCPeerConnection-dataChannelTypeCollision.html
+++ b/third_party/blink/web_tests/fast/peerconnection/RTCPeerConnection-dataChannelTypeCollision.html
@@ -23,6 +23,26 @@
   return promise_rejects_dom(t, "InvalidAccessError", pc.setRemoteDescription(sd));
 }, 'Local RTP channel, remote offer of SCTP channel');
 
+promise_test(async t => {
+  var pc = new RTCPeerConnection();
+  t.add_cleanup(() => pc.close());
+  pc.createDataChannel('');
+  offer = await pc.createOffer();
+  assert_regexp_match(offer.sdp, /m=application .* webrtc-datachannel/);
+  assert_equals(offer.sdp.match(/a=rtpmap:\d+ google-data/), null);
+}, 'Asking for default Data Channels generates appropriate offer');
+
+promise_test(async t => {
+  const rtpConstraints = { optional: [{ RtpDataChannels: true}]};
+
+  var pc = new RTCPeerConnection({}, rtpConstraints);
+  t.add_cleanup(() => pc.close());
+  pc.createDataChannel('');
+  offer = await pc.createOffer();
+  assert_equals(offer.sdp.match(/m=application .* webrtc-datachannel/), null);
+  assert_regexp_match(offer.sdp, /a=rtpmap:\d+ google-data/);
+}, 'Asking for RTP Data Channels generates appropriate offer');
+
 </script>
 </body>
 </html>
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index 52ec9ed..265308b 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -28141,6 +28141,8 @@
   <int value="3341" label="V8Window_ShowSaveFilePicker_Method"/>
   <int value="3342" label="V8Window_ShowDirectoryPicker_Method"/>
   <int value="3343" label="V8Window_GetOriginPrivateDirectory_Method"/>
+  <int value="3344" label="RTCConstraintEnableRtpDataChannelsTrue"/>
+  <int value="3345" label="RTCConstraintEnableRtpDataChannelsFalse"/>
 </enum>
 
 <enum name="FeaturePolicyAllowlistType">