#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.h"
#include <unordered_set>
#include "base/containers/contains.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h"
#include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h"
#include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
#include "chrome/browser/sync_file_system/logger.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"
namespace sync_file_system {
namespace drive_backend {
namespace {
std::string GenerateAppRootIDByAppIDKey(const std::string& app_id) { … }
std::string GenerateActiveTrackerIDByFileIDKey(const std::string& file_id) { … }
std::string GenerateTrackerIDByFileIDKeyPrefix(const std::string& file_id) { … }
std::string GenerateMultiTrackerKey(const std::string& file_id) { … }
std::string GenerateActiveTrackerIDByParentAndTitleKey(
int64_t parent_id,
const std::string& title) { … }
std::string GenerateTrackerIDByParentAndTitleKeyPrefix(
int64_t parent_id,
const std::string& title) { … }
std::string GenerateTrackerIDsByParentIDKeyPrefix(int64_t parent_id) { … }
std::string GenerateMultiBackingParentAndTitleKey(int64_t parent_id,
const std::string& title) { … }
std::string GenerateDirtyIDKey(int64_t tracker_id) { … }
std::string GenerateDemotedDirtyIDKey(int64_t tracker_id) { … }
void RemoveUnreachableItemsFromDB(LevelDBWrapper* db,
int64_t sync_root_tracker_id) { … }
}
std::unique_ptr<MetadataDatabaseIndexOnDisk>
MetadataDatabaseIndexOnDisk::Create(LevelDBWrapper* db) { … }
MetadataDatabaseIndexOnDisk::~MetadataDatabaseIndexOnDisk() { … }
void MetadataDatabaseIndexOnDisk::RemoveUnreachableItems() { … }
bool MetadataDatabaseIndexOnDisk::GetFileMetadata(
const std::string& file_id, FileMetadata* metadata) const { … }
bool MetadataDatabaseIndexOnDisk::GetFileTracker(int64_t tracker_id,
FileTracker* tracker) const { … }
void MetadataDatabaseIndexOnDisk::StoreFileMetadata(
std::unique_ptr<FileMetadata> metadata) { … }
void MetadataDatabaseIndexOnDisk::StoreFileTracker(
std::unique_ptr<FileTracker> tracker) { … }
void MetadataDatabaseIndexOnDisk::RemoveFileMetadata(
const std::string& file_id) { … }
void MetadataDatabaseIndexOnDisk::RemoveFileTracker(int64_t tracker_id) { … }
TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByFileID(
const std::string& file_id) const { … }
int64_t MetadataDatabaseIndexOnDisk::GetAppRootTracker(
const std::string& app_id) const { … }
TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParentAndTitle(
int64_t parent_tracker_id,
const std::string& title) const { … }
std::vector<int64_t> MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParent(
int64_t parent_id) const { … }
std::string MetadataDatabaseIndexOnDisk::PickMultiTrackerFileID() const { … }
ParentIDAndTitle MetadataDatabaseIndexOnDisk::PickMultiBackingFilePath() const { … }
int64_t MetadataDatabaseIndexOnDisk::PickDirtyTracker() const { … }
void MetadataDatabaseIndexOnDisk::DemoteDirtyTracker(int64_t tracker_id) { … }
bool MetadataDatabaseIndexOnDisk::HasDemotedDirtyTracker() const { … }
bool MetadataDatabaseIndexOnDisk::IsDemotedDirtyTracker(
int64_t tracker_id) const { … }
void MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTracker(
int64_t tracker_id) { … }
bool MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTrackers() { … }
size_t MetadataDatabaseIndexOnDisk::CountDirtyTracker() const { … }
size_t MetadataDatabaseIndexOnDisk::CountFileMetadata() const { … }
size_t MetadataDatabaseIndexOnDisk::CountFileTracker() const { … }
void MetadataDatabaseIndexOnDisk::SetSyncRootRevalidated() const { … }
void MetadataDatabaseIndexOnDisk::SetSyncRootTrackerID(
int64_t sync_root_id) const { … }
void MetadataDatabaseIndexOnDisk::SetLargestChangeID(
int64_t largest_change_id) const { … }
void MetadataDatabaseIndexOnDisk::SetNextTrackerID(
int64_t next_tracker_id) const { … }
bool MetadataDatabaseIndexOnDisk::IsSyncRootRevalidated() const { … }
int64_t MetadataDatabaseIndexOnDisk::GetSyncRootTrackerID() const { … }
int64_t MetadataDatabaseIndexOnDisk::GetLargestChangeID() const { … }
int64_t MetadataDatabaseIndexOnDisk::GetNextTrackerID() const { … }
std::vector<std::string>
MetadataDatabaseIndexOnDisk::GetRegisteredAppIDs() const { … }
std::vector<int64_t> MetadataDatabaseIndexOnDisk::GetAllTrackerIDs() const { … }
std::vector<std::string>
MetadataDatabaseIndexOnDisk::GetAllMetadataIDs() const { … }
int64_t MetadataDatabaseIndexOnDisk::BuildTrackerIndexes() { … }
int64_t MetadataDatabaseIndexOnDisk::DeleteTrackerIndexes() { … }
LevelDBWrapper* MetadataDatabaseIndexOnDisk::GetDBForTesting() { … }
MetadataDatabaseIndexOnDisk::MetadataDatabaseIndexOnDisk(LevelDBWrapper* db)
: … { … }
void MetadataDatabaseIndexOnDisk::AddToAppIDIndex(const FileTracker& tracker) { … }
void MetadataDatabaseIndexOnDisk::UpdateInAppIDIndex(
const FileTracker& old_tracker,
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::RemoveFromAppIDIndex(
const FileTracker& tracker) { … }
void MetadataDatabaseIndexOnDisk::AddToFileIDIndexes(
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::UpdateInFileIDIndexes(
const FileTracker& old_tracker,
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::RemoveFromFileIDIndexes(
const FileTracker& tracker) { … }
void MetadataDatabaseIndexOnDisk::AddToPathIndexes(
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::UpdateInPathIndexes(
const FileTracker& old_tracker,
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::RemoveFromPathIndexes(
const FileTracker& tracker) { … }
void MetadataDatabaseIndexOnDisk::AddToDirtyTrackerIndexes(
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::UpdateInDirtyTrackerIndexes(
const FileTracker& old_tracker,
const FileTracker& new_tracker) { … }
void MetadataDatabaseIndexOnDisk::RemoveFromDirtyTrackerIndexes(
const FileTracker& tracker) { … }
TrackerIDSet MetadataDatabaseIndexOnDisk::GetTrackerIDSetByPrefix(
const std::string& active_tracker_key,
const std::string& ids_prefix) const { … }
void MetadataDatabaseIndexOnDisk::AddToTrackerIDSetWithPrefix(
const std::string& active_tracker_key, const std::string& key_prefix,
const FileTracker& tracker) { … }
bool MetadataDatabaseIndexOnDisk::EraseInTrackerIDSetWithPrefix(
const std::string& active_tracker_key,
const std::string& key_prefix,
int64_t tracker_id) { … }
void MetadataDatabaseIndexOnDisk::ActivateInTrackerIDSetWithPrefix(
const std::string& active_tracker_key,
const std::string& key_prefix,
int64_t tracker_id) { … }
void MetadataDatabaseIndexOnDisk::DeactivateInTrackerIDSetWithPrefix(
const std::string& active_tracker_key,
const std::string& key_prefix,
int64_t tracker_id) { … }
bool MetadataDatabaseIndexOnDisk::DBHasKey(const std::string& key) const { … }
size_t MetadataDatabaseIndexOnDisk::CountDirtyTrackerInternal() const { … }
MetadataDatabaseIndexOnDisk::NumEntries
MetadataDatabaseIndexOnDisk::CountWithPrefix(const std::string& prefix,
int64_t ignored_id) { … }
void MetadataDatabaseIndexOnDisk::DeleteKeyStartsWith(
const std::string& prefix) { … }
}
}