#include "third_party/leveldatabase/env_chromium.h"
#include <atomic>
#include <iterator>
#include <limits>
#include <string>
#include <string_view>
#include <utility>
#include "base/check_op.h"
#include "base/files/file_error_or.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/process/process_metrics.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "base/types/expected_macros.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/services/storage/public/cpp/filesystem/filesystem_proxy.h"
#include "third_party/leveldatabase/chromium_logger.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "third_party/re2/src/re2/re2.h"
FilePath;
MemoryAllocatorDump;
MemoryDumpArgs;
ProcessMemoryDump;
FileLock;
Slice;
Status;
namespace leveldb_env {
namespace {
FileErrorOr;
const constexpr size_t kFileLimitToDisableEviction = …;
constexpr auto kMaxRetryDuration = …;
const FilePath::CharType table_extension[] = …);
static const FilePath::CharType kLevelDBTestDirectoryPrefix[] = …);
static const char kDatabaseNameSuffixForRebuildDB[] = …;
DBFactoryMethod& GetDBFactoryOverride() { … }
class ChromiumFileLock : public FileLock { … };
class Retrier { … };
class ChromiumSequentialFile : public leveldb::SequentialFile { … };
void RemoveFile(const Slice& key, void* value) { … }
Status ReadFromFileToScratch(uint64_t offset,
size_t n,
Slice* result,
char* scratch,
base::File* file,
const base::FilePath& file_path) { … }
class ChromiumEvictableRandomAccessFile : public leveldb::RandomAccessFile { … };
class ChromiumRandomAccessFile : public leveldb::RandomAccessFile { … };
class ChromiumWritableFile : public leveldb::WritableFile { … };
ChromiumWritableFile::ChromiumWritableFile(const std::string& fname,
base::File f,
storage::FilesystemProxy* filesystem)
: … { … }
Status ChromiumWritableFile::SyncParent() { … }
Status ChromiumWritableFile::Append(const Slice& data) { … }
Status ChromiumWritableFile::Close() { … }
Status ChromiumWritableFile::Flush() { … }
Status ChromiumWritableFile::Sync() { … }
size_t GetLevelDBFileLimit(size_t max_file_descriptors) { … }
std::string GetDumpNameForDB(const leveldb::DB* db) { … }
std::string GetDumpNameForCache(DBTracker::SharedReadCacheUse cache) { … }
MemoryAllocatorDump* CreateDumpMalloced(ProcessMemoryDump* pmd,
const std::string& name,
size_t size) { … }
void RecordCacheUsageInTracing(ProcessMemoryDump* pmd,
DBTracker::SharedReadCacheUse cache) { … }
}
Options::Options() { … }
const char* MethodIDToString(MethodID method) { … }
Status MakeIOError(Slice filename,
const std::string& message,
MethodID method,
base::File::Error error) { … }
ErrorParsingResult ParseMethodAndError(const leveldb::Status& status,
MethodID* method_param,
base::File::Error* error) { … }
const char* patterns[] = …;
int GetCorruptionCode(const leveldb::Status& status) { … }
int GetNumCorruptionCodes() { … }
std::string GetCorruptionMessage(const leveldb::Status& status) { … }
bool IndicatesDiskFull(const leveldb::Status& status) { … }
std::string DatabaseNameForRewriteDB(const std::string& original_name) { … }
size_t WriteBufferSize(int64_t disk_size) { … }
ChromiumEnv::ChromiumEnv()
: … { … }
ChromiumEnv::ChromiumEnv(bool log_lock_errors) : … { … }
ChromiumEnv::ChromiumEnv(std::unique_ptr<storage::FilesystemProxy> filesystem)
: … { … }
ChromiumEnv::~ChromiumEnv() { … }
bool ChromiumEnv::FileExists(const std::string& fname) { … }
const char* ChromiumEnv::FileErrorString(base::File::Error error) { … }
void ChromiumEnv::RemoveBackupFiles(const FilePath& dir) { … }
void ChromiumEnv::SetReadOnlyFileLimitForTesting(int max_open_files) { … }
Status ChromiumEnv::GetChildren(const std::string& dir,
std::vector<std::string>* result) { … }
Status ChromiumEnv::RemoveFile(const std::string& fname) { … }
Status ChromiumEnv::CreateDir(const std::string& name) { … }
Status ChromiumEnv::RemoveDir(const std::string& name) { … }
Status ChromiumEnv::GetFileSize(const std::string& fname, uint64_t* size) { … }
Status ChromiumEnv::RenameFile(const std::string& src, const std::string& dst) { … }
Status ChromiumEnv::LockFile(const std::string& fname, FileLock** lock) { … }
Status ChromiumEnv::UnlockFile(FileLock* lock) { … }
Status ChromiumEnv::GetTestDirectory(std::string* path) { … }
Status ChromiumEnv::NewLogger(const std::string& fname,
leveldb::Logger** result) { … }
Status ChromiumEnv::NewSequentialFile(const std::string& fname,
leveldb::SequentialFile** result) { … }
Status ChromiumEnv::NewRandomAccessFile(const std::string& fname,
leveldb::RandomAccessFile** result) { … }
Status ChromiumEnv::NewWritableFile(const std::string& fname,
leveldb::WritableFile** result) { … }
Status ChromiumEnv::NewAppendableFile(const std::string& fname,
leveldb::WritableFile** result) { … }
uint64_t ChromiumEnv::NowMicros() { … }
void ChromiumEnv::SleepForMicroseconds(int micros) { … }
class Thread : public base::PlatformThread::Delegate { … };
void ChromiumEnv::Schedule(ScheduleFunc* function, void* arg) { … }
void ChromiumEnv::StartThread(void (*function)(void* arg), void* arg) { … }
LevelDBStatusValue GetLevelDBStatusUMAValue(const leveldb::Status& s) { … }
class DBTracker::TrackedDBImpl : public base::LinkNode<TrackedDBImpl>,
public TrackedDB { … };
class DBTracker::MemoryDumpProvider
: public base::trace_event::MemoryDumpProvider { … };
void DBTracker::MemoryDumpProvider::DumpAllDatabases(ProcessMemoryDump* pmd) { … }
void DBTracker::MemoryDumpProvider::DumpVisitor(ProcessMemoryDump* pmd,
TrackedDB* db) { … }
DBTracker::DBTracker() : … { … }
DBTracker::~DBTracker() { … }
DBTracker* DBTracker::GetInstance() { … }
MemoryAllocatorDump* DBTracker::GetOrCreateAllocatorDump(
ProcessMemoryDump* pmd,
leveldb::DB* tracked_db) { … }
MemoryAllocatorDump* DBTracker::GetOrCreateAllocatorDump(
ProcessMemoryDump* pmd,
leveldb::Env* tracked_memenv) { … }
bool DBTracker::IsTrackedDB(const leveldb::DB* db) const { … }
leveldb::Status DBTracker::OpenDatabase(const leveldb_env::Options& options,
const std::string& name,
TrackedDB** dbptr) { … }
void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { … }
void DBTracker::DatabaseOpened(TrackedDBImpl* database) { … }
void DBTracker::DatabaseDestroyed(TrackedDBImpl* database) { … }
leveldb::Status OpenDB(const leveldb_env::Options& options,
const std::string& name,
std::unique_ptr<leveldb::DB>* dbptr) { … }
void SetDBFactoryForTesting(DBFactoryMethod factory) { … }
leveldb::Status RewriteDB(const leveldb_env::Options& options,
const std::string& name,
std::unique_ptr<leveldb::DB>* dbptr) { … }
std::string_view MakeStringView(const leveldb::Slice& s) { … }
leveldb::Slice MakeSlice(std::string_view s) { … }
leveldb::Slice MakeSlice(base::span<const uint8_t> s) { … }
}
namespace leveldb {
Env* Env::Default() { … }
}