#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/base/resource/data_pack.h"
#include <errno.h>
#include <algorithm>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_span.h"
#include "base/memory/ref_counted_memory.h"
#include "base/synchronization/lock.h"
#include "net/filter/gzip_header.h"
#include "third_party/zlib/google/compression_utils.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/base/resource/scoped_file_writer.h"
namespace {
static const uint32_t kFileFormatV4 = …;
static const uint32_t kFileFormatV5 = …;
static const size_t kHeaderLengthV4 = …;
static const size_t kHeaderLengthV5 = …;
void MaybePrintResourceId(uint16_t resource_id) { … }
bool MmapHasGzipHeader(const base::MemoryMappedFile* mmap) { … }
}
namespace ui {
int DataPack::Entry::CompareById(const void* void_key, const void* void_entry) { … }
int DataPack::Alias::CompareById(const void* void_key, const void* void_entry) { … }
void DataPack::Iterator::UpdateResourceData() { … }
DataPack::Iterator DataPack::begin() const { … }
DataPack::Iterator DataPack::end() const { … }
class DataPack::MemoryMappedDataSource : public DataPack::DataSource { … };
class DataPack::StringDataSource : public DataPack::DataSource { … };
class DataPack::BufferDataSource : public DataPack::DataSource { … };
DataPack::DataPack(ResourceScaleFactor resource_scale_factor)
: … { … }
DataPack::~DataPack() { … }
std::unique_ptr<DataPack::DataSource> DataPack::LoadFromPathInternal(
const base::FilePath& path) { … }
bool DataPack::LoadFromPath(const base::FilePath& path) { … }
bool DataPack::LoadFromFile(base::File file) { … }
bool DataPack::LoadFromFileRegion(
base::File file,
const base::MemoryMappedFile::Region& region) { … }
bool DataPack::LoadFromBuffer(base::span<const uint8_t> buffer) { … }
bool DataPack::SanityCheckFileAndRegisterResources(size_t margin_to_skip,
const uint8_t* data,
size_t data_length) { … }
bool DataPack::LoadImpl(std::unique_ptr<DataPack::DataSource> data_source) { … }
const DataPack::Entry* DataPack::LookupEntryById(uint16_t resource_id) const { … }
bool DataPack::HasResource(uint16_t resource_id) const { … }
std::string_view DataPack::GetStringPieceFromOffset(
uint32_t target_offset,
uint32_t next_offset,
const uint8_t* data_source) { … }
std::optional<std::string_view> DataPack::GetStringPiece(
uint16_t resource_id) const { … }
base::RefCountedStaticMemory* DataPack::GetStaticMemory(
uint16_t resource_id) const { … }
ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { … }
ResourceScaleFactor DataPack::GetResourceScaleFactor() const { … }
#if DCHECK_IS_ON()
void DataPack::CheckForDuplicateResources(
const std::vector<std::unique_ptr<ResourceHandle>>& packs) { … }
#endif
bool DataPack::WritePack(const base::FilePath& path,
const std::map<uint16_t, std::string_view>& resources,
TextEncodingType text_encoding_type) { … }
}