#include "components/sync/engine/loopback_server/loopback_server.h"
#include <algorithm>
#include <limits>
#include <map>
#include <set>
#include <string_view>
#include <utility>
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/numerics/clamped_math.h"
#include "base/rand_util.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "components/sync/base/data_type.h"
#include "components/sync/engine/loopback_server/persistent_bookmark_entity.h"
#include "components/sync/engine/loopback_server/persistent_permanent_entity.h"
#include "components/sync/engine/loopback_server/persistent_tombstone_entity.h"
#include "components/sync/engine/loopback_server/persistent_unique_client_entity.h"
#include "components/sync/protocol/data_type_progress_marker.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/loopback_server.pb.h"
#include "components/sync/protocol/nigori_specifics.pb.h"
#include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync/protocol/sync_entity.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
string;
vector;
DataType;
DataTypeSet;
GetDataTypeFromSpecifics;
namespace syncer {
class LoopbackServerEntity;
namespace {
static const char kHistogramSuffix[] = …;
static const int kCurrentLoopbackServerProtoVersion = …;
static const int kKeystoreKeyLength = …;
static const char kBookmarkBarFolderServerTag[] = …;
static const char kBookmarkBarFolderName[] = …;
static const char kOtherBookmarksFolderServerTag[] = …;
static const char kOtherBookmarksFolderName[] = …;
static const char kSyncedBookmarksFolderServerTag[] = …;
static const char kSyncedBookmarksFolderName[] = …;
int GetServerMigrationVersion(
const std::map<DataType, int>& server_migration_versions,
DataType type) { … }
class ProgressMarkerToken { … };
class UpdateSieve { … };
bool SortByVersion(const LoopbackServerEntity* lhs,
const LoopbackServerEntity* rhs) { … }
}
LoopbackServer::LoopbackServer(const base::FilePath& persistent_file)
: … { … }
LoopbackServer::~LoopbackServer() { … }
void LoopbackServer::Init() { … }
std::vector<uint8_t> LoopbackServer::GenerateNewKeystoreKey() const { … }
bool LoopbackServer::CreatePermanentBookmarkFolder(
const std::string& server_tag,
const std::string& name) { … }
bool LoopbackServer::CreateDefaultPermanentItems() { … }
void LoopbackServer::UpdateEntityVersion(LoopbackServerEntity* entity) { … }
void LoopbackServer::SaveEntity(std::unique_ptr<LoopbackServerEntity> entity) { … }
net::HttpStatusCode LoopbackServer::HandleCommand(
const sync_pb::ClientToServerMessage& message,
sync_pb::ClientToServerResponse* response) { … }
void LoopbackServer::EnableStrongConsistencyWithConflictDetectionModel() { … }
void LoopbackServer::AddNewKeystoreKeyForTesting() { … }
void LoopbackServer::FlushToDisk() { … }
bool LoopbackServer::HandleGetUpdatesRequest(
const sync_pb::GetUpdatesMessage& get_updates,
const std::string& store_birthday,
const std::string& invalidator_client_id,
sync_pb::GetUpdatesResponse* response,
std::vector<DataType>* datatypes_to_migrate) { … }
string LoopbackServer::CommitEntity(
const sync_pb::SyncEntity& client_entity,
sync_pb::CommitResponse_EntryResponse* entry_response,
const string& client_guid,
const string& parent_id) { … }
void LoopbackServer::OverrideResponseType(
ResponseTypeProvider response_type_override) { … }
void LoopbackServer::BuildEntryResponseForSuccessfulCommit(
const std::string& entity_id,
sync_pb::CommitResponse_EntryResponse* entry_response) { … }
bool LoopbackServer::IsChild(const string& id,
const string& potential_parent_id) { … }
void LoopbackServer::DeleteChildren(const string& parent_id) { … }
bool LoopbackServer::HandleCommitRequest(
const sync_pb::CommitMessage& commit,
const std::string& invalidator_client_id,
sync_pb::CommitResponse* response,
DataTypeSet* throttled_datatypes_in_request) { … }
void LoopbackServer::ClearServerData() { … }
void LoopbackServer::DeleteAllEntitiesForDataType(DataType data_type) { … }
std::string LoopbackServer::GetStoreBirthday() const { … }
std::vector<sync_pb::SyncEntity> LoopbackServer::GetSyncEntitiesByDataType(
DataType data_type) { … }
std::vector<sync_pb::SyncEntity>
LoopbackServer::GetPermanentSyncEntitiesByDataType(DataType data_type) { … }
base::Value::Dict LoopbackServer::GetEntitiesAsDictForTesting() { … }
bool LoopbackServer::ModifyEntitySpecifics(
const std::string& id,
const sync_pb::EntitySpecifics& updated_specifics) { … }
bool LoopbackServer::ModifyBookmarkEntity(
const std::string& id,
const std::string& parent_id,
const sync_pb::EntitySpecifics& updated_specifics) { … }
void LoopbackServer::SerializeState(sync_pb::LoopbackServerProto* proto) const { … }
bool LoopbackServer::DeSerializeState(
const sync_pb::LoopbackServerProto& proto) { … }
std::optional<std::string> LoopbackServer::SerializeData() { … }
bool LoopbackServer::ScheduleSaveStateToFile() { … }
bool LoopbackServer::LoadStateFromFile() { … }
}