diff --git a/components/media_router/common/providers/cast/channel/enum_table.cc b/components/media_router/common/providers/cast/channel/enum_table.cc
index ba5f6c9d04a51..b17f41603e00c 100644
--- a/components/media_router/common/providers/cast/channel/enum_table.cc
+++ b/components/media_router/common/providers/cast/channel/enum_table.cc
@@ -2,10 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
+#include "base/containers/span.h"
+
+
 
 #include "components/media_router/common/providers/cast/channel/enum_table.h"
 
@@ -24,13 +23,11 @@ static_assert(sizeof(GenericEnumTableEntry) == 16,
 
 // static
 const GenericEnumTableEntry* GenericEnumTableEntry::FindByString(
-    const GenericEnumTableEntry data[],
-    std::size_t size,
+    base::span<const GenericEnumTableEntry> data,
     std::string_view str) {
-  for (std::size_t i = 0; i < size; i++) {
-    if (data[i].length == str.length() &&
-        std::memcmp(data[i].chars, str.data(), str.length()) == 0) {
-      return &data[i];
+  for (const auto& entry : data) {
+    if (entry.has_str() && entry.str() == str) {
+      return &entry;
     }
   }
   return nullptr;
@@ -38,12 +35,11 @@ const GenericEnumTableEntry* GenericEnumTableEntry::FindByString(
 
 // static
 std::optional<std::string_view> GenericEnumTableEntry::FindByValue(
-    const GenericEnumTableEntry data[],
-    std::size_t size,
+    base::span<const GenericEnumTableEntry> data,
     int value) {
-  for (std::size_t i = 0; i < size; i++) {
-    if (data[i].value == value && data[i].has_str()) {
-      return data[i].str();
+  for (const auto& entry : data) {
+    if (entry.value == value && entry.has_str()) {
+      return entry.str();
     }
   }
   return std::nullopt;
diff --git a/components/media_router/common/providers/cast/channel/enum_table.h b/components/media_router/common/providers/cast/channel/enum_table.h
index fdf8941c32236..e8c0a44f96cf8 100644
--- a/components/media_router/common/providers/cast/channel/enum_table.h
+++ b/components/media_router/common/providers/cast/channel/enum_table.h
@@ -2,10 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
+#include "base/containers/span.h"
+
+
 
 #ifndef COMPONENTS_MEDIA_ROUTER_COMMON_PROVIDERS_CAST_CHANNEL_ENUM_TABLE_H_
 #define COMPONENTS_MEDIA_ROUTER_COMMON_PROVIDERS_CAST_CHANNEL_ENUM_TABLE_H_
@@ -18,6 +17,7 @@
 #include <string_view>
 
 #include "base/check_op.h"
+#include "base/compiler_specific.h"
 #include "base/notreached.h"
 #include "build/build_config.h"
 
@@ -198,11 +198,10 @@ class
 
  private:
   static const GenericEnumTableEntry* FindByString(
-      const GenericEnumTableEntry data[],
-      std::size_t size,
+      base::span<const GenericEnumTableEntry> data,
       std::string_view str);
   static std::optional<std::string_view>
-  FindByValue(const GenericEnumTableEntry data[], std::size_t size, int value);
+  FindByValue(base::span<const GenericEnumTableEntry> data, int value);
 
   constexpr std::string_view str() const {
     DCHECK(has_str());
@@ -318,7 +317,8 @@ class EnumTable {
     if (is_sorted_) {
       const std::size_t index = static_cast<std::size_t>(value);
       if (ANALYZER_ASSUME_TRUE(index < data_.size())) {
-        const auto& entry = data_.begin()[index];
+        base::span<const Entry> data_span(data_);
+        const auto& entry = data_span[index];
         if (ANALYZER_ASSUME_TRUE(entry.has_str())) {
           return entry.str();
         }
@@ -326,8 +326,10 @@ class EnumTable {
       return std::nullopt;
     }
     return GenericEnumTableEntry::FindByValue(
-        reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
-        data_.size(), static_cast<int32_t>(value));
+        UNSAFE_BUFFERS(base::span(
+            reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
+            data_.size())),
+        static_cast<int32_t>(value));
   }
 
   // This overload of GetString is designed for cases where the argument is a
@@ -355,8 +357,10 @@ class EnumTable {
   // enum value directly.
   std::optional<E> GetEnum(std::string_view str) const {
     auto* entry = GenericEnumTableEntry::FindByString(
-        reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
-        data_.size(), str);
+        UNSAFE_BUFFERS(base::span(
+            reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
+            data_.size())),
+        str);
     return entry ? static_cast<E>(entry->value) : std::optional<E>();
   }
 
