leveldb_chrome.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // 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. #ifndef THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_
  5. #define THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/files/file_path.h"
  9. #include "leveldb/cache.h"
  10. #include "leveldb/env.h"
  11. #include "leveldb/export.h"
  12. #include "leveldb/options.h"
  13. #include "third_party/leveldatabase/src/db/filename.h"
  14. namespace base {
  15. namespace trace_event {
  16. class MemoryAllocatorDump;
  17. class ProcessMemoryDump;
  18. } // namespace trace_event
  19. } // namespace base
  20. namespace leveldb_chrome {
  21. // Return the shared leveldb block cache for web APIs. The caller *does not*
  22. // own the returned instance.
  23. LEVELDB_EXPORT leveldb::Cache* GetSharedWebBlockCache();
  24. // Return the shared leveldb block cache for browser (non web) APIs. The caller
  25. // *does not* own the returned instance.
  26. LEVELDB_EXPORT leveldb::Cache* GetSharedBrowserBlockCache();
  27. // Return the shared leveldb block cache for in-memory Envs. The caller *does
  28. // not* own the returned instance.
  29. LEVELDB_EXPORT leveldb::Cache* GetSharedInMemoryBlockCache();
  30. // Determine if a leveldb::Env stores the file data in RAM.
  31. LEVELDB_EXPORT bool IsMemEnv(const leveldb::Env* env);
  32. // Creates an in-memory Env for which all files are stored in the heap.
  33. // This wraps leveldb::NewMemEnv to add memory-infra logging.
  34. // if |base_env| is null then leveldb::Env::Default() will be used.
  35. LEVELDB_EXPORT std::unique_ptr<leveldb::Env> NewMemEnv(
  36. const std::string& name,
  37. leveldb::Env* base_env = nullptr);
  38. // If filename is a leveldb file, store the type of the file in *type.
  39. // The number encoded in the filename is stored in *number.
  40. // Returns true if the filename was successfully parsed.
  41. LEVELDB_EXPORT bool ParseFileName(const std::string& filename,
  42. uint64_t* number,
  43. leveldb::FileType* type);
  44. // Corrupt a closed database for testing purposes. After calling this function
  45. // leveldb::OpenDB(...) will return a status where IsCorruption() returns true.
  46. // Returns true if the database was successfully corrupted, false if not.
  47. // Note: This function will fail if |db_path| does not exist.
  48. LEVELDB_EXPORT bool CorruptClosedDBForTesting(const base::FilePath& db_path);
  49. // Check that the database path in |db_path| "appears" to be a valid leveldb
  50. // database using the provided |env|. This function *does not* open or verify
  51. // that the database referred to by |db_path| is a valid database, only that it
  52. // appears to be one.
  53. LEVELDB_EXPORT bool PossiblyValidDB(const base::FilePath& db_path,
  54. leveldb::Env* env);
  55. // Fully delete the leveldb database specified by |db_path|. leveldb::DestroyDB
  56. // will only delete files that it creates. Other files, if present, will be
  57. // ignored and left behind after leveldb::DestroyDB returns. This function will
  58. // delete the entire database directory.
  59. //
  60. // Note: Can be used with in-memory Env's.
  61. LEVELDB_EXPORT leveldb::Status DeleteDB(const base::FilePath& db_path,
  62. const leveldb::Options& options);
  63. // Returns the memory-infra dump for |tracked_memenv|.
  64. // Do not call this function, instead call
  65. // leveldb_env::DBTracker::GetOrCreateAllocatorDump().
  66. // TODO(crbug.com/762598) Can be made private as part of leveldb cleanup.
  67. base::trace_event::MemoryAllocatorDump* GetEnvAllocatorDump(
  68. base::trace_event::ProcessMemoryDump* pmd,
  69. leveldb::Env* tracked_memenv);
  70. // Dump all tracked in-memory env's to the |pmd|. Do not call - this is a
  71. // private function for leveldb_env::DBTracker.
  72. // TODO(crbug.com/762598) Can be made private as part of leveldb cleanup.
  73. void DumpAllTrackedEnvs(base::trace_event::ProcessMemoryDump* pmd);
  74. } // namespace leveldb_chrome
  75. #endif // THIRD_PARTY_LEVELDATABASE_LEVELDB_CHROME_H_