chromium/ui/base/resource/data_pack.cc

// 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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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"

// For details of the file layout, see
// http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalizedstrings

namespace {

static const uint32_t kFileFormatV4 =;
static const uint32_t kFileFormatV5 =;
// uint32(version), uint32(resource_count), uint8(encoding)
static const size_t kHeaderLengthV4 =;
// uint32(version), uint8(encoding), 3 bytes padding,
// uint16(resource_count), uint16(alias_count)
static const size_t kHeaderLengthV5 =;

// Prints the given resource id the first time it's loaded if Chrome has been
// started with --print-resource-ids. This output is then used to generate a
// more optimal resource renumbering to improve startup speed. See
// tools/gritsettings/README.md for more info.
void MaybePrintResourceId(uint16_t resource_id) {}

bool MmapHasGzipHeader(const base::MemoryMappedFile* mmap) {}

}  // namespace

namespace ui {

// static
int DataPack::Entry::CompareById(const void* void_key, const void* void_entry) {}

// static
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 {};

// Takes ownership of a string of uncompressed pack data.
class DataPack::StringDataSource : public DataPack::DataSource {};

class DataPack::BufferDataSource : public DataPack::DataSource {};

DataPack::DataPack(ResourceScaleFactor resource_scale_factor)
    :{}

DataPack::~DataPack() {}

// static
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 {}

// static
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  // DCHECK_IS_ON()

// static
bool DataPack::WritePack(const base::FilePath& path,
                         const std::map<uint16_t, std::string_view>& resources,
                         TextEncodingType text_encoding_type) {}

}  // namespace ui