Reland "Spanify base::RefCountedMemory"

This is a reland of commit 431722686bd15761e77c290b04957f01d5640a99

Fixed the null deref of scoped_refptr in the usb descriptor code,
by not constructing the span from the RefCountedMemory before we
know the RefCountedMemory is really there.

Original change's description:
> Spanify base::RefCountedMemory
>
> - The base class gets data() and size() as well as begin() and end()
> - The virtual interface gets a span from the subclass.
> - All subclasses hold a bounded type.
> - Remove front_as<T>() from the base class. Use a span or data()
>   instead.
> - Remove most use of front() from the base class, but leave the
>   method there just to reduce the scope/size of this CL a bit. Use
>   a span or data() instead.
> - Rename data() in subclasses to be more specific: as_vector() or
>   as_string().
> - Remove the shadowing data(), and front_as(), from the vector-based
>   subclass that provided mutable access. Have mutable access go
>   through as_vector().
> - Remove the shadowing data() from the string-based subclasses that
>   provided mutable access. Have mutable access go through
>   as_string().
>
> The base class provides const access to the underlying data, as not
> all implementations point to mutable data. The subclasses provided
> methods to access the underlying data mutably, sometimes in ways that
> shadowed the base class methods (such as with front_as). When mutable
> access is required, we now go through the underlying storage accessor
> such as as_vector() or as_string().
>
> In the X11 code there's a bunch of RefCountedMemory that are
> actually unsized, since they come from void* in C APIs. So split
> those off to a separate x11::UnsizedRefCountedMemory, and use that
> for all reply type data fields.
>
> Add conversion types to move between sized and unsized, which are needed
> very rarely.
>
> Use RefCountedMemory as a span since it converts now:
> - Convert all front_as<char>() to use base::as_string_view(*mem).
> - Convert make_span(mem->front(), mem->size()) to span(*mem).
> - Except when mutable access is required, in which case we go through
>   the underlying storage type.
>
> Bug: 40284755
> Change-Id: Ib1c5fd61973092e3e02562646a7b3416e1070cd1
> Low-Coverage-Reason: refactoring, not new code
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5447596
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Owners-Override: Kyle Charbonneau <kylechar@chromium.org>
> Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
> Commit-Queue: danakj <danakj@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1288921}

Bug: 40284755
Change-Id: Ide0a71227c4930bd638bb07faffda44f5285bd4f
Low-Coverage-Reason: refactoring, not new code
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5462330
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Owners-Override: Kyle Charbonneau <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1289537}
NOKEYCHECK=True
GitOrigin-RevId: 529a3eba25e6a166606533fc4bd5d4363ed6760a
2 files changed