0

Make BufferAutoMapper a contiguous range.

This allows it to qualify for the proper span range constructor, not
just the "legacy" version.

Bug: 364987728
Change-Id: I27803583373044e89b618961fa097a9664e9261d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5962463
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Derek Schuff <dschuff@chromium.org>
Commit-Queue: Derek Schuff <dschuff@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1373603}
This commit is contained in:
Peter Kasting
2024-10-24 21:53:13 +00:00
committed by Chromium LUCI CQ
parent 8c8e7d5fc4
commit e0da0e7849

@ -7,6 +7,8 @@
#include <stdint.h>
#include "base/compiler_specific.h"
#include "base/containers/checked_iterators.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory_mapping.h"
@ -61,6 +63,8 @@ class PPB_Buffer_Impl : public ppapi::Resource,
// mapped state in the destructor.
class BufferAutoMapper {
public:
using iterator = base::CheckedContiguousIterator<const uint8_t>;
explicit BufferAutoMapper(ppapi::thunk::PPB_Buffer_API* api);
BufferAutoMapper(const BufferAutoMapper&) = delete;
@ -72,6 +76,19 @@ class BufferAutoMapper {
const uint8_t* data() const { return data_; }
size_t size() const { return size_; }
// Iterate buffer as bytes up to the end of its logical size.
iterator begin() const {
// SAFETY: The implementer of `PPB_Buffer_API` is responsible for
// guaranteeing that when `Map()` returns a non-null pointer, it points to
// at least the number of bytes returned in `Describe()`'s outparam. This
// memory must also remain valid for the lifetime of this mapper.
return UNSAFE_BUFFERS(iterator(data(), data() + size()));
}
iterator end() const {
// SAFETY: As in `begin()` above.
return UNSAFE_BUFFERS(iterator(data(), data() + size(), data() + size()));
}
private:
raw_ptr<ppapi::thunk::PPB_Buffer_API> api_;