Add a proper API to create memslices from the QUIC code.

Current API provides an (allocator, size) constructor.  However, this just creates a buffer with random data in it and no way to change it, since memslices are read-only.  Current code uses const_cast; this CL creates a proper API and updates all existing call sites to use it.

gfe-relnote: n/a (no functional change)
PiperOrigin-RevId: 287072774
Change-Id: Ie4dd2eae6db2ec91b087f5d41887ea3948ee411a
diff --git a/quic/platform/api/quic_mem_slice.h b/quic/platform/api/quic_mem_slice.h
index a40d638..2d44085 100644
--- a/quic/platform/api/quic_mem_slice.h
+++ b/quic/platform/api/quic_mem_slice.h
@@ -26,14 +26,12 @@
   // Constructs a empty QuicMemSlice with no underlying data and 0 reference
   // count.
   QuicMemSlice() = default;
-  // Let |allocator| allocate a data buffer of |length|, then construct
-  // QuicMemSlice with reference count 1 from the allocated data buffer.
-  // Once all of the references to the allocated data buffer are released,
-  // |allocator| is responsible to free the memory. |allocator| must
-  // not be null, and |length| must not be 0. To construct an empty
-  // QuicMemSlice, use the zero-argument constructor instead.
-  QuicMemSlice(QuicBufferAllocator* allocator, size_t length)
-      : impl_(allocator, length) {}
+
+  // Constructs a QuicMemSlice that takes ownership of |buffer|.  |length| must
+  // not be zero.  To construct an empty QuicMemSlice, use the zero-argument
+  // constructor instead.
+  QuicMemSlice(QuicUniqueBufferPtr buffer, size_t length)
+      : impl_(std::move(buffer), length) {}
 
   // Constructs QuicMemSlice from |impl|. It takes the reference away from
   // |impl|.
diff --git a/quic/platform/api/quic_mem_slice_test.cc b/quic/platform/api/quic_mem_slice_test.cc
index 185f536..d441afa 100644
--- a/quic/platform/api/quic_mem_slice_test.cc
+++ b/quic/platform/api/quic_mem_slice_test.cc
@@ -15,7 +15,7 @@
  public:
   QuicMemSliceTest() {
     size_t length = 1024;
-    slice_ = QuicMemSlice(&allocator_, length);
+    slice_ = QuicMemSlice(MakeUniqueBuffer(&allocator_, length), length);
     orig_data_ = slice_.data();
     orig_length_ = slice_.length();
   }