// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/memory/ref_counted_memory.h" #include #include "base/check_op.h" #include "base/memory/read_only_shared_memory_region.h" namespace base { bool RefCountedMemory::Equals( const scoped_refptr& other) const { return other && AsSpan() == other->AsSpan(); } RefCountedMemory::RefCountedMemory() = default; RefCountedMemory::~RefCountedMemory() = default; RefCountedStaticMemory::RefCountedStaticMemory() = default; RefCountedStaticMemory::~RefCountedStaticMemory() = default; RefCountedStaticMemory::RefCountedStaticMemory(base::span bytes) : bytes_(bytes) {} base::span RefCountedStaticMemory::AsSpan() const { return bytes_; } RefCountedBytes::RefCountedBytes() = default; RefCountedBytes::~RefCountedBytes() = default; RefCountedBytes::RefCountedBytes(std::vector initializer) : bytes_(std::move(initializer)) {} RefCountedBytes::RefCountedBytes(base::span initializer) : bytes_(initializer.begin(), initializer.end()) {} RefCountedBytes::RefCountedBytes(size_t size) : bytes_(size, 0u) {} base::span RefCountedBytes::AsSpan() const { return bytes_; } RefCountedString::RefCountedString() = default; RefCountedString::~RefCountedString() = default; RefCountedString::RefCountedString(std::string str) : string_(std::move(str)) {} base::span RefCountedString::AsSpan() const { return base::as_byte_span(string_); } RefCountedString16::RefCountedString16() = default; RefCountedString16::~RefCountedString16() = default; RefCountedString16::RefCountedString16(std::u16string str) : string_(std::move(str)) {} base::span RefCountedString16::AsSpan() const { return base::as_byte_span(string_); } RefCountedSharedMemoryMapping::RefCountedSharedMemoryMapping( ReadOnlySharedMemoryMapping mapping) : mapping_(std::move(mapping)) { DCHECK_GT(mapping_.size(), 0u); } RefCountedSharedMemoryMapping::~RefCountedSharedMemoryMapping() = default; base::span RefCountedSharedMemoryMapping::AsSpan() const { return mapping_.GetMemoryAsSpan(); } // static scoped_refptr RefCountedSharedMemoryMapping::CreateFromWholeRegion( const ReadOnlySharedMemoryRegion& region) { ReadOnlySharedMemoryMapping mapping = region.Map(); if (!mapping.IsValid()) return nullptr; return MakeRefCounted(std::move(mapping)); } } // namespace base