chromium/net/disk_cache/blockfile/entry_impl.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/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "net/disk_cache/blockfile/entry_impl.h"

#include <limits>
#include <memory>

#include "base/files/file_util.h"
#include "base/hash/hash.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/blockfile/backend_impl.h"
#include "net/disk_cache/blockfile/bitmap.h"
#include "net/disk_cache/blockfile/disk_format.h"
#include "net/disk_cache/blockfile/sparse_control.h"
#include "net/disk_cache/cache_util.h"
#include "net/disk_cache/net_log_parameters.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source_type.h"

Time;
TimeTicks;

namespace {

// Index for the file used to store the key, if any (files_[kKeyFileIndex]).
const int kKeyFileIndex =;

// This class implements FileIOCallback to buffer the callback from a file IO
// operation from the actual net class.
class SyncCallback: public disk_cache::FileIOCallback {};

void SyncCallback::OnFileIOComplete(int bytes_copied) {}

void SyncCallback::Discard() {}

const int kMaxBufferSize =;  // 1 MB.

}  // namespace

namespace disk_cache {

// This class handles individual memory buffers that store data before it is
// sent to disk. The buffer can start at any offset, but if we try to write to
// anywhere in the first 16KB of the file (kMaxBlockSize), we set the offset to
// zero. The buffer grows up to a size determined by the backend, to keep the
// total memory used under control.
class EntryImpl::UserBuffer {};

bool EntryImpl::UserBuffer::PreWrite(int offset, int len) {}

void EntryImpl::UserBuffer::Truncate(int offset) {}

void EntryImpl::UserBuffer::Write(int offset, IOBuffer* buf, int len) {}

bool EntryImpl::UserBuffer::PreRead(int eof, int offset, int* len) {}

int EntryImpl::UserBuffer::Read(int offset, IOBuffer* buf, int len) {}

void EntryImpl::UserBuffer::Reset() {}

bool EntryImpl::UserBuffer::GrowBuffer(int required, int limit) {}

// ------------------------------------------------------------------------

EntryImpl::EntryImpl(BackendImpl* backend, Addr address, bool read_only)
    :{}

void EntryImpl::DoomImpl() {}

int EntryImpl::ReadDataImpl(int index,
                            int offset,
                            IOBuffer* buf,
                            int buf_len,
                            CompletionOnceCallback callback) {}

int EntryImpl::WriteDataImpl(int index,
                             int offset,
                             IOBuffer* buf,
                             int buf_len,
                             CompletionOnceCallback callback,
                             bool truncate) {}

int EntryImpl::ReadSparseDataImpl(int64_t offset,
                                  IOBuffer* buf,
                                  int buf_len,
                                  CompletionOnceCallback callback) {}

int EntryImpl::WriteSparseDataImpl(int64_t offset,
                                   IOBuffer* buf,
                                   int buf_len,
                                   CompletionOnceCallback callback) {}

RangeResult EntryImpl::GetAvailableRangeImpl(int64_t offset, int len) {}

void EntryImpl::CancelSparseIOImpl() {}

int EntryImpl::ReadyForSparseIOImpl(CompletionOnceCallback callback) {}

uint32_t EntryImpl::GetHash() {}

bool EntryImpl::CreateEntry(Addr node_address,
                            const std::string& key,
                            uint32_t hash) {}

bool EntryImpl::IsSameEntry(const std::string& key, uint32_t hash) {}

void EntryImpl::InternalDoom() {}

void EntryImpl::DeleteEntryData(bool everything) {}

CacheAddr EntryImpl::GetNextAddress() {}

void EntryImpl::SetNextAddress(Addr address) {}

bool EntryImpl::LoadNodeAddress() {}

bool EntryImpl::Update() {}

void EntryImpl::SetDirtyFlag(int32_t current_id) {}

void EntryImpl::SetPointerForInvalidEntry(int32_t new_id) {}

bool EntryImpl::LeaveRankingsBehind() {}

// This only includes checks that relate to the first block of the entry (the
// first 256 bytes), and values that should be set from the entry creation.
// Basically, even if there is something wrong with this entry, we want to see
// if it is possible to load the rankings node and delete them together.
bool EntryImpl::SanityCheck() {}

bool EntryImpl::DataSanityCheck() {}

void EntryImpl::FixForDelete() {}

void EntryImpl::IncrementIoCount() {}

void EntryImpl::DecrementIoCount() {}

void EntryImpl::OnEntryCreated(BackendImpl* backend) {}

void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) {}

void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) {}

const net::NetLogWithSource& EntryImpl::net_log() const {}

// static
int EntryImpl::NumBlocksForEntry(int key_size) {}

// ------------------------------------------------------------------------

void EntryImpl::Doom() {}

void EntryImpl::Close() {}

std::string EntryImpl::GetKey() const {}

Time EntryImpl::GetLastUsed() const {}

Time EntryImpl::GetLastModified() const {}

int32_t EntryImpl::GetDataSize(int index) const {}

int EntryImpl::ReadData(int index,
                        int offset,
                        IOBuffer* buf,
                        int buf_len,
                        CompletionOnceCallback callback) {}

int EntryImpl::WriteData(int index,
                         int offset,
                         IOBuffer* buf,
                         int buf_len,
                         CompletionOnceCallback callback,
                         bool truncate) {}

int EntryImpl::ReadSparseData(int64_t offset,
                              IOBuffer* buf,
                              int buf_len,
                              CompletionOnceCallback callback) {}

int EntryImpl::WriteSparseData(int64_t offset,
                               IOBuffer* buf,
                               int buf_len,
                               CompletionOnceCallback callback) {}

RangeResult EntryImpl::GetAvailableRange(int64_t offset,
                                         int len,
                                         RangeResultCallback callback) {}

bool EntryImpl::CouldBeSparse() const {}

void EntryImpl::CancelSparseIO() {}

net::Error EntryImpl::ReadyForSparseIO(CompletionOnceCallback callback) {}

void EntryImpl::SetLastUsedTimeForTest(base::Time time) {}

// When an entry is deleted from the cache, we clean up all the data associated
// with it for two reasons: to simplify the reuse of the block (we know that any
// unused block is filled with zeros), and to simplify the handling of write /
// read partial information from an entry (don't have to worry about returning
// data related to a previous cache entry because the range was not fully
// written before).
EntryImpl::~EntryImpl() {}

// ------------------------------------------------------------------------

int EntryImpl::InternalReadData(int index,
                                int offset,
                                IOBuffer* buf,
                                int buf_len,
                                CompletionOnceCallback callback) {}

int EntryImpl::InternalWriteData(int index,
                                 int offset,
                                 IOBuffer* buf,
                                 int buf_len,
                                 CompletionOnceCallback callback,
                                 bool truncate) {}

// ------------------------------------------------------------------------

bool EntryImpl::CreateDataBlock(int index, int size) {}

bool EntryImpl::CreateBlock(int size, Addr* address) {}

// Note that this method may end up modifying a block file so upon return the
// involved block will be free, and could be reused for something else. If there
// is a crash after that point (and maybe before returning to the caller), the
// entry will be left dirty... and at some point it will be discarded; it is
// important that the entry doesn't keep a reference to this address, or we'll
// end up deleting the contents of |address| once again.
void EntryImpl::DeleteData(Addr address, int index) {}

void EntryImpl::UpdateRank(bool modified) {}

File* EntryImpl::GetBackingFile(Addr address, int index) {}

File* EntryImpl::GetExternalFile(Addr address, int index) {}

// We keep a memory buffer for everything that ends up stored on a block file
// (because we don't know yet the final data size), and for some of the data
// that end up on external files. This function will initialize that memory
// buffer and / or the files needed to store the data.
//
// In general, a buffer may overlap data already stored on disk, and in that
// case, the contents of the buffer are the most accurate. It may also extend
// the file, but we don't want to read from disk just to keep the buffer up to
// date. This means that as soon as there is a chance to get confused about what
// is the most recent version of some part of a file, we'll flush the buffer and
// reuse it for the new data. Keep in mind that the normal use pattern is quite
// simple (write sequentially from the beginning), so we optimize for handling
// that case.
bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
                              bool truncate) {}

// We get to this function with some data already stored. If there is a
// truncation that results on data stored internally, we'll explicitly
// handle the case here.
bool EntryImpl::HandleTruncation(int index, int offset, int buf_len) {}

bool EntryImpl::CopyToLocalBuffer(int index) {}

bool EntryImpl::MoveToLocalBuffer(int index) {}

bool EntryImpl::ImportSeparateFile(int index, int new_size) {}

bool EntryImpl::PrepareBuffer(int index, int offset, int buf_len) {}

bool EntryImpl::Flush(int index, int min_len) {}

void EntryImpl::UpdateSize(int index, int old_size, int new_size) {}

int EntryImpl::InitSparseData() {}

void EntryImpl::SetEntryFlags(uint32_t flags) {}

uint32_t EntryImpl::GetEntryFlags() {}

void EntryImpl::GetData(int index,
                        std::unique_ptr<char[]>* buffer,
                        Addr* address) {}

}  // namespace disk_cache