#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/drive/resource_metadata_storage.h"
#include <stddef.h>
#include <map>
#include <set>
#include <unordered_map>
#include <utility>
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/drive/drive.pb.h"
#include "components/drive/drive_api_util.h"
#include "components/drive/file_system_core_util.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
namespace drive {
namespace internal {
namespace {
enum DBInitStatus { … };
const base::FilePath::CharType kResourceMapDBName[] = …);
const base::FilePath::CharType kPreservedResourceMapDBName[] = …);
const base::FilePath::CharType kTrashedResourceMapDBName[] = …);
const char kDBKeyDelimeter = …;
const char kCacheEntryKeySuffix[] = …;
const char kIdEntryKeyPrefix[] = …;
std::string GetHeaderDBKey() { … }
bool IsChildEntryKey(const leveldb::Slice& key) { … }
bool IsCacheEntryKey(const leveldb::Slice& key) { … }
std::string GetIdFromCacheEntryKey(const leveldb::Slice& key) { … }
std::string GetIdEntryKey(const std::string& resource_id) { … }
bool IsIdEntryKey(const leveldb::Slice& key) { … }
std::string GetResourceIdFromIdEntryKey(const leveldb::Slice& key) { … }
DBInitStatus LevelDBStatusToDBInitStatus(const leveldb::Status& status) { … }
FileError LevelDBStatusToFileError(const leveldb::Status& status) { … }
ResourceMetadataHeader GetDefaultHeaderEntry() { … }
bool MoveIfPossible(const base::FilePath& from, const base::FilePath& to) { … }
bool UpgradeOldDBVersions6To10(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersion11(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersion12(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersion13(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersion14(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersion15(leveldb::DB* resource_map) { … }
bool UpgradeOldDBVersions16To18(leveldb::DB* resource_map) { … }
}
ResourceMetadataStorage::Iterator::Iterator(
std::unique_ptr<leveldb::Iterator> it)
: … { … }
ResourceMetadataStorage::Iterator::~Iterator() { … }
bool ResourceMetadataStorage::Iterator::IsAtEnd() const { … }
std::string ResourceMetadataStorage::Iterator::GetID() const { … }
const ResourceEntry& ResourceMetadataStorage::Iterator::GetValue() const { … }
void ResourceMetadataStorage::Iterator::Advance() { … }
bool ResourceMetadataStorage::Iterator::HasError() const { … }
bool ResourceMetadataStorage::UpgradeOldDB(
const base::FilePath& directory_path) { … }
ResourceMetadataStorage::ResourceMetadataStorage(
const base::FilePath& directory_path,
base::SequencedTaskRunner* blocking_task_runner)
: … { … }
bool ResourceMetadataStorage::Initialize() { … }
void ResourceMetadataStorage::Destroy() { … }
void ResourceMetadataStorage::RecoverCacheInfoFromTrashedResourceMap(
RecoveredCacheInfoMap* out_info) { … }
FileError ResourceMetadataStorage::SetLargestChangestamp(
int64_t largest_changestamp) { … }
FileError ResourceMetadataStorage::GetLargestChangestamp(
int64_t* largest_changestamp) { … }
FileError ResourceMetadataStorage::GetStartPageToken(
std::string* start_page_token) { … }
FileError ResourceMetadataStorage::SetStartPageToken(
const std::string& start_page_token) { … }
FileError ResourceMetadataStorage::PutEntry(const ResourceEntry& entry) { … }
FileError ResourceMetadataStorage::GetEntry(const std::string& id,
ResourceEntry* out_entry) { … }
FileError ResourceMetadataStorage::RemoveEntry(const std::string& id) { … }
std::unique_ptr<ResourceMetadataStorage::Iterator>
ResourceMetadataStorage::GetIterator() { … }
FileError ResourceMetadataStorage::GetChild(const std::string& parent_id,
const std::string& child_name,
std::string* child_id) const { … }
FileError ResourceMetadataStorage::GetChildren(
const std::string& parent_id,
std::vector<std::string>* children) const { … }
FileError ResourceMetadataStorage::GetIdByResourceId(
const std::string& resource_id,
std::string* out_id) const { … }
ResourceMetadataStorage::RecoveredCacheInfo::RecoveredCacheInfo()
: … { … }
ResourceMetadataStorage::RecoveredCacheInfo::~RecoveredCacheInfo() = default;
ResourceMetadataStorage::~ResourceMetadataStorage() { … }
void ResourceMetadataStorage::DestroyOnBlockingPool() { … }
std::string ResourceMetadataStorage::GetChildEntryKey(
const std::string& parent_id,
const std::string& child_name) { … }
FileError ResourceMetadataStorage::PutHeader(
const ResourceMetadataHeader& header) { … }
FileError ResourceMetadataStorage::GetHeader(
ResourceMetadataHeader* header) const { … }
bool ResourceMetadataStorage::CheckValidity() { … }
}
}