Spanify GifFileWriter::WriteBuffer()

Its sole caller already is making a span for us. Then use
helper functions for spans to avoid unsafe buffer usage.

Change-Id: I2a435f4be9b8d88ad82aec67732f2da4e8b4dea4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5800787
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345132}
diff --git a/chromeos/ash/services/recording/gif_file_writer.cc b/chromeos/ash/services/recording/gif_file_writer.cc
index 4c50c502..9c2563d 100644
--- a/chromeos/ash/services/recording/gif_file_writer.cc
+++ b/chromeos/ash/services/recording/gif_file_writer.cc
@@ -2,11 +2,6 @@
 // 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 "chromeos/ash/services/recording/gif_file_writer.h"
 
 #include <string_view>
@@ -28,17 +23,15 @@
 GifFileWriter::~GifFileWriter() = default;
 
 void GifFileWriter::WriteByte(uint8_t byte) {
-  WriteBytesAndCheck(base::make_span(&byte, sizeof(byte)));
+  WriteBytesAndCheck(base::byte_span_from_ref(byte));
 }
 
-void GifFileWriter::WriteBuffer(const uint8_t* const buffer,
-                                size_t buffer_size) {
-  WriteBytesAndCheck(base::make_span(buffer, buffer_size));
+void GifFileWriter::WriteBuffer(base::span<const uint8_t> buffer) {
+  WriteBytesAndCheck(buffer);
 }
 
 void GifFileWriter::WriteString(std::string_view string) {
-  WriteBytesAndCheck(base::make_span(
-      reinterpret_cast<const uint8_t*>(string.data()), string.size()));
+  WriteBytesAndCheck(base::as_byte_span(string));
 }
 
 void GifFileWriter::WriteShort(uint16_t value) {
diff --git a/chromeos/ash/services/recording/gif_file_writer.h b/chromeos/ash/services/recording/gif_file_writer.h
index 9fb44b2..f7651ab 100644
--- a/chromeos/ash/services/recording/gif_file_writer.h
+++ b/chromeos/ash/services/recording/gif_file_writer.h
@@ -8,6 +8,7 @@
 #include <cstdint>
 #include <string_view>
 
+#include "base/containers/span.h"
 #include "base/files/file.h"
 #include "chromeos/ash/services/recording/recording_file_io_helper.h"
 
@@ -30,9 +31,8 @@
   // Writes the given `bytes` to the `gif_file_`.
   void WriteByte(uint8_t byte);
 
-  // Writes the contents of the given `buffer` whose length is `buffer_size` to
-  // the `gif_file_`.
-  void WriteBuffer(const uint8_t* const buffer, size_t buffer_size);
+  // Writes the contents of the given `buffer` to the `gif_file_`.
+  void WriteBuffer(base::span<const uint8_t> buffer);
 
   // Writes the given `string` to the `gif_file_`.
   void WriteString(std::string_view string);
diff --git a/chromeos/ash/services/recording/lzw_pixel_color_indices_writer.cc b/chromeos/ash/services/recording/lzw_pixel_color_indices_writer.cc
index ccf7bfb..14e775b 100644
--- a/chromeos/ash/services/recording/lzw_pixel_color_indices_writer.cc
+++ b/chromeos/ash/services/recording/lzw_pixel_color_indices_writer.cc
@@ -202,8 +202,7 @@
   DCHECK(!byte_stream_buffer_.empty());
 
   gif_file_writer_->WriteByte(byte_stream_buffer_.size());
-  gif_file_writer_->WriteBuffer(byte_stream_buffer_.data(),
-                                byte_stream_buffer_.size());
+  gif_file_writer_->WriteBuffer(byte_stream_buffer_);
   byte_stream_buffer_.clear();
 }