blob: 79d7e82a86b3b90059da63c97f2405f547da006b [file] [log] [blame]
Chris Mumford66df99e2017-09-13 22:23:321// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file. See the AUTHORS file for names of contributors.
4
5#ifndef THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_
6#define THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_
7
Chris Mumford8d26d10a2018-04-20 17:07:588#include <memory>
9#include <string>
10
Chris Mumforda884aa1f2017-10-24 22:46:3211#include "base/files/file_path.h"
Chris Mumford66df99e2017-09-13 22:23:3212#include "leveldb/cache.h"
Chris Mumfordc38afb62017-10-09 17:55:0813#include "leveldb/env.h"
Chris Mumford2a0c74d42017-10-14 00:49:2014#include "leveldb/export.h"
Chris Mumfordda3afc3b2018-06-05 22:10:2315#include "leveldb/options.h"
Chris Mumford2a0c74d42017-10-14 00:49:2016#include "third_party/leveldatabase/src/db/filename.h"
Chris Mumford66df99e2017-09-13 22:23:3217
Chris Mumford8d26d10a2018-04-20 17:07:5818namespace base {
19namespace trace_event {
20class MemoryAllocatorDump;
21class ProcessMemoryDump;
22} // namespace trace_event
23} // namespace base
24
Chris Mumford66df99e2017-09-13 22:23:3225namespace leveldb_chrome {
26
27// Return the shared leveldb block cache for web APIs. The caller *does not*
28// own the returned instance.
Chris Mumford2a0c74d42017-10-14 00:49:2029LEVELDB_EXPORT leveldb::Cache* GetSharedWebBlockCache();
Chris Mumford66df99e2017-09-13 22:23:3230
31// Return the shared leveldb block cache for browser (non web) APIs. The caller
32// *does not* own the returned instance.
Chris Mumford2a0c74d42017-10-14 00:49:2033LEVELDB_EXPORT leveldb::Cache* GetSharedBrowserBlockCache();
Chris Mumford66df99e2017-09-13 22:23:3234
Chris Mumforda46073f2017-10-12 21:54:1235// Return the shared leveldb block cache for in-memory Envs. The caller *does
36// not* own the returned instance.
Chris Mumford2a0c74d42017-10-14 00:49:2037LEVELDB_EXPORT leveldb::Cache* GetSharedInMemoryBlockCache();
Chris Mumforda46073f2017-10-12 21:54:1238
Chris Mumford1dc497c02017-10-09 22:03:2239// Determine if a leveldb::Env stores the file data in RAM.
Chris Mumford2a0c74d42017-10-14 00:49:2040LEVELDB_EXPORT bool IsMemEnv(const leveldb::Env* env);
Chris Mumford1dc497c02017-10-09 22:03:2241
Chris Mumfordc38afb62017-10-09 17:55:0842// Creates an in-memory Env for which all files are stored in the heap.
Chris Mumford8d26d10a2018-04-20 17:07:5843// This wraps leveldb::NewMemEnv to add memory-infra logging.
44// if |base_env| is null then leveldb::Env::Default() will be used.
45LEVELDB_EXPORT std::unique_ptr<leveldb::Env> NewMemEnv(
46 const std::string& name,
47 leveldb::Env* base_env = nullptr);
Chris Mumford2a0c74d42017-10-14 00:49:2048
49// If filename is a leveldb file, store the type of the file in *type.
Chris Mumford8d26d10a2018-04-20 17:07:5850// The number encoded in the filename is stored in *number.
Chris Mumford2a0c74d42017-10-14 00:49:2051// Returns true if the filename was successfully parsed.
52LEVELDB_EXPORT bool ParseFileName(const std::string& filename,
53 uint64_t* number,
54 leveldb::FileType* type);
Chris Mumfordc38afb62017-10-09 17:55:0855
Chris Mumforda46073f2017-10-12 21:54:1256// Report leveldb UMA values.
Chris Mumford2a0c74d42017-10-14 00:49:2057LEVELDB_EXPORT void UpdateHistograms();
Chris Mumforda46073f2017-10-12 21:54:1258
Chris Mumforda884aa1f2017-10-24 22:46:3259// Corrupt a closed database for testing purposes. After calling this function
60// leveldb::OpenDB(...) will return a status where IsCorruption() returns true.
61// Returns true if the database was successfully corrupted, false if not.
62// Note: This function will fail if |db_path| does not exist.
63LEVELDB_EXPORT bool CorruptClosedDBForTesting(const base::FilePath& db_path);
64
Chris Mumfordda3afc3b2018-06-05 22:10:2365// Check that the database path in |db_path| "appears" to be a valid leveldb
66// database using the provided |env|. This function *does not* open or verify
67// that the database referred to by |db_path| is a valid database, only that it
68// appears to be one.
69LEVELDB_EXPORT bool PossiblyValidDB(const base::FilePath& db_path,
70 leveldb::Env* env);
71
72// Fully delete the leveldb database specified by |db_path|. leveldb::DestroyDB
73// will only delete files that it creates. Other files, if present, will be
74// ignored and left behind after leveldb::DestroyDB returns. This function will
75// delete the entire database directory.
76//
77// Note: Can be used with in-memory Env's.
78LEVELDB_EXPORT leveldb::Status DeleteDB(const base::FilePath& db_path,
79 const leveldb::Options& options);
80
Chris Mumford8d26d10a2018-04-20 17:07:5881// Returns the memory-infra dump for |tracked_memenv|.
82// Do not call this function, instead call
83// leveldb_env::DBTracker::GetOrCreateAllocatorDump().
84// TODO(crbug.com/762598) Can be made private as part of leveldb cleanup.
85base::trace_event::MemoryAllocatorDump* GetEnvAllocatorDump(
86 base::trace_event::ProcessMemoryDump* pmd,
87 leveldb::Env* tracked_memenv);
88
89// Dump all tracked in-memory env's to the |pmd|. Do not call - this is a
90// private function for leveldb_env::DBTracker.
91// TODO(crbug.com/762598) Can be made private as part of leveldb cleanup.
92void DumpAllTrackedEnvs(base::trace_event::ProcessMemoryDump* pmd);
93
Chris Mumford66df99e2017-09-13 22:23:3294} // namespace leveldb_chrome
95
96#endif // THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_