Adding metrics for hostname candidate use.

These metrics by themselves won't be as useful, unless they can be correlated to the use of the
feature 'WebRtcHideLocalIpsWithMdns'. This can be done by running a finch experiment where we turn
the feature on for a % of users, we can then compare these metrics for users with and without
the feature turned on.

A complementary change is required in Chrome:
tools/metrics/histograms/enums.xml

Bug: webrtc:9605 webrtc:10091 chromium:914452
Change-Id: Ibc6d16dec95a8e3943ce40063c02903769fe1cb4
Reviewed-on: https://webrtc-review.googlesource.com/c/113321
Commit-Queue: Jeroen de Borst <jeroendb@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26003}
diff --git a/api/umametrics.h b/api/umametrics.h
index 88ab08c..239eff3 100644
--- a/api/umametrics.h
+++ b/api/umametrics.h
@@ -79,12 +79,17 @@
   kIceCandidatePairPrflxSrflx,
   kIceCandidatePairPrflxRelay,
 
-  // The following 4 types tell whether local and remote hosts have private or
-  // public IP addresses.
+  // The following 9 types tell whether local and remote hosts have hostname,
+  // private or public IP addresses.
   kIceCandidatePairHostPrivateHostPrivate,
   kIceCandidatePairHostPrivateHostPublic,
   kIceCandidatePairHostPublicHostPrivate,
   kIceCandidatePairHostPublicHostPublic,
+  kIceCandidatePairHostNameHostName,
+  kIceCandidatePairHostNameHostPrivate,
+  kIceCandidatePairHostNameHostPublic,
+  kIceCandidatePairHostPrivateHostName,
+  kIceCandidatePairHostPublicHostName,
   kIceCandidatePairMax
 };
 
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index c9f2302..6c92816 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -277,16 +277,32 @@
   const auto& relay = RELAY_PORT_TYPE;
   const auto& prflx = PRFLX_PORT_TYPE;
   if (l == host && r == host) {
+    bool local_hostname =
+        !local.address().hostname().empty() && local.address().IsUnresolvedIP();
+    bool remote_hostname = !remote.address().hostname().empty() &&
+                           remote.address().IsUnresolvedIP();
     bool local_private = IPIsPrivate(local.address().ipaddr());
     bool remote_private = IPIsPrivate(remote.address().ipaddr());
-    if (local_private) {
-      if (remote_private) {
+    if (local_hostname) {
+      if (remote_hostname) {
+        return kIceCandidatePairHostNameHostName;
+      } else if (remote_private) {
+        return kIceCandidatePairHostNameHostPrivate;
+      } else {
+        return kIceCandidatePairHostNameHostPublic;
+      }
+    } else if (local_private) {
+      if (remote_hostname) {
+        return kIceCandidatePairHostPrivateHostName;
+      } else if (remote_private) {
         return kIceCandidatePairHostPrivateHostPrivate;
       } else {
         return kIceCandidatePairHostPrivateHostPublic;
       }
     } else {
-      if (remote_private) {
+      if (remote_hostname) {
+        return kIceCandidatePairHostPublicHostName;
+      } else if (remote_private) {
         return kIceCandidatePairHostPublicHostPrivate;
       } else {
         return kIceCandidatePairHostPublicHostPublic;
diff --git a/pc/peerconnection_integrationtest.cc b/pc/peerconnection_integrationtest.cc
index fa1fb23..c296e4c 100644
--- a/pc/peerconnection_integrationtest.cc
+++ b/pc/peerconnection_integrationtest.cc
@@ -3674,6 +3674,10 @@
                  caller()->ice_connection_state(), kDefaultTimeout);
   EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
                  callee()->ice_connection_state(), kDefaultTimeout);
+
+  EXPECT_EQ(1, webrtc::metrics::NumEvents(
+                   "WebRTC.PeerConnection.CandidatePairType_UDP",
+                   webrtc::kIceCandidatePairHostNameHostName));
 }
 
 // Test that firewalling the ICE connection causes the clients to identify the