Remove IceCandidateType::kNumValues

Bug: none
Change-Id: I108a006d6ff00f436c87dc9ee5b7e3c27b7b6c83
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/336242
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41642}
diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc
index ba1e597..f1b12f0 100644
--- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc
+++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.cc
@@ -139,10 +139,6 @@
       return rtclog::IceCandidatePairConfig::PRFLX;
     case IceCandidateType::kRelay:
       return rtclog::IceCandidatePairConfig::RELAY;
-    default:
-      // TODO(tommi): Remove the default handler when kNumValues is gone.
-      RTC_DCHECK_NOTREACHED();
-      return rtclog::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE;
   }
 }
 
@@ -200,6 +196,7 @@
       return rtclog::IceCandidatePairConfig::CELLULAR;
     case IceCandidateNetworkType::kNumValues:
       RTC_DCHECK_NOTREACHED();
+      break;
   }
   RTC_DCHECK_NOTREACHED();
   return rtclog::IceCandidatePairConfig::UNKNOWN_NETWORK_TYPE;
diff --git a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc
index a07afbe..4c662fd 100644
--- a/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc
+++ b/logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.cc
@@ -206,8 +206,6 @@
       return rtclog2::IceCandidatePairConfig::PRFLX;
     case IceCandidateType::kRelay:
       return rtclog2::IceCandidatePairConfig::RELAY;
-    case IceCandidateType::kNumValues:
-      RTC_DCHECK_NOTREACHED();
   }
   RTC_DCHECK_NOTREACHED();
   return rtclog2::IceCandidatePairConfig::UNKNOWN_CANDIDATE_TYPE;
diff --git a/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h b/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h
index a44f530..e77253d 100644
--- a/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h
+++ b/logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h
@@ -32,14 +32,13 @@
   kNumValues,
 };
 
-// TODO(qingsi): Change the names of candidate types to "host", "srflx", "prflx"
-// and "relay" after the naming is spec-compliant in the signaling part
+// TODO(tommi): Change the names of candidate types to "host", "srflx" for
+// spec-compliance.
 enum class IceCandidateType {
   kLocal,
   kStun,
   kPrflx,
   kRelay,
-  kNumValues,
 };
 
 enum class IceCandidatePairProtocol {
diff --git a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc
index 1aff19f..df3586a 100644
--- a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc
+++ b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc
@@ -217,10 +217,27 @@
   return std::make_unique<RtcEventProbeResultSuccess>(id, bitrate_bps);
 }
 
+constexpr uint32_t CandidateTypeCount() {
+  // This switch statement only exists to catch changes to the IceCandidateType
+  // enumeration. If you get an error here, please update the switch statement
+  // and the return value.
+  IceCandidateType type = IceCandidateType::kLocal;
+  switch (type) {
+    case IceCandidateType::kLocal:
+    case IceCandidateType::kStun:
+    case IceCandidateType::kPrflx:
+    case IceCandidateType::kRelay:
+      break;
+  }
+  return 4u;
+}
+
 std::unique_ptr<RtcEventIceCandidatePairConfig>
 EventGenerator::NewIceCandidatePairConfig() {
-  IceCandidateType local_candidate_type = static_cast<IceCandidateType>(
-      prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1));
+  static_assert(static_cast<int>(IceCandidateType::kLocal) == 0,
+                "Expect kLocal to be the first enum value, equal to 0");
+  IceCandidateType local_candidate_type =
+      static_cast<IceCandidateType>(prng_.Rand(CandidateTypeCount() - 1));
   IceCandidateNetworkType local_network_type =
       static_cast<IceCandidateNetworkType>(prng_.Rand(
           static_cast<uint32_t>(IceCandidateNetworkType::kNumValues) - 1));
@@ -228,8 +245,8 @@
       static_cast<IceCandidatePairAddressFamily>(prng_.Rand(
           static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) -
           1));
-  IceCandidateType remote_candidate_type = static_cast<IceCandidateType>(
-      prng_.Rand(static_cast<uint32_t>(IceCandidateType::kNumValues) - 1));
+  IceCandidateType remote_candidate_type =
+      static_cast<IceCandidateType>(prng_.Rand(CandidateTypeCount() - 1));
   IceCandidatePairAddressFamily remote_address_family =
       static_cast<IceCandidatePairAddressFamily>(prng_.Rand(
           static_cast<uint32_t>(IceCandidatePairAddressFamily::kNumValues) -
diff --git a/rtc_tools/rtc_event_log_to_text/converter.cc b/rtc_tools/rtc_event_log_to_text/converter.cc
index 35a780f..79cf03e 100644
--- a/rtc_tools/rtc_event_log_to_text/converter.cc
+++ b/rtc_tools/rtc_event_log_to_text/converter.cc
@@ -234,8 +234,7 @@
             candidate_type_name{{IceCandidateType::kLocal, "LOCAL"},
                                 {IceCandidateType::kStun, "STUN"},
                                 {IceCandidateType::kPrflx, "PRFLX"},
-                                {IceCandidateType::kRelay, "RELAY"},
-                                {IceCandidateType::kNumValues, "NUM_VALUES"}};
+                                {IceCandidateType::kRelay, "RELAY"}};
 
         static const std::map<IceCandidatePairProtocol, std::string>
             protocol_name{{IceCandidatePairProtocol::kUnknown, "UNKNOWN"},