#include "components/sync_sessions/session_store.h"
#include <stdint.h>
#include <algorithm>
#include <set>
#include <utility>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/pickle.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "components/sync/base/time.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/mutable_data_batch.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync_device_info/local_device_info_util.h"
#include "components/sync_sessions/session_sync_prefs.h"
#include "components/sync_sessions/sync_sessions_client.h"
namespace sync_sessions {
namespace {
SessionSpecifics;
DataTypeStore;
MetadataChangeList;
std::string TabNodeIdToClientTag(const std::string& session_tag,
int tab_node_id) { … }
std::string EncodeStorageKey(const std::string& session_tag, int tab_node_id) { … }
bool DecodeStorageKey(const std::string& storage_key,
std::string* session_tag,
int* tab_node_id) { … }
std::unique_ptr<syncer::EntityData> MoveToEntityData(
const std::string& client_name,
SessionSpecifics* specifics) { … }
std::string GetSessionTagWithPrefs(const std::string& cache_guid,
SessionSyncPrefs* sync_prefs) { … }
void ForwardError(syncer::OnceModelErrorHandler error_handler,
const std::optional<syncer::ModelError>& error) { … }
std::optional<syncer::ModelError> ParseInitialDataOnBackendSequence(
std::map<std::string, sync_pb::SessionSpecifics>* initial_data,
std::string* session_name,
std::unique_ptr<DataTypeStore::RecordList> record_list) { … }
}
struct SessionStore::Builder { … };
void SessionStore::Open(const std::string& cache_guid,
SyncSessionsClient* sessions_client,
OpenCallback callback) { … }
SessionStore::WriteBatch::WriteBatch(
std::unique_ptr<DataTypeStore::WriteBatch> batch,
CommitCallback commit_cb,
syncer::OnceModelErrorHandler error_handler,
SyncedSessionTracker* session_tracker)
: … { … }
SessionStore::WriteBatch::~WriteBatch() { … }
std::string SessionStore::WriteBatch::PutAndUpdateTracker(
const sync_pb::SessionSpecifics& specifics,
base::Time modification_time) { … }
std::vector<std::string>
SessionStore::WriteBatch::DeleteForeignEntityAndUpdateTracker(
const std::string& storage_key) { … }
std::string SessionStore::WriteBatch::PutWithoutUpdatingTracker(
const sync_pb::SessionSpecifics& specifics) { … }
std::string SessionStore::WriteBatch::DeleteLocalTabWithoutUpdatingTracker(
int tab_node_id) { … }
MetadataChangeList* SessionStore::WriteBatch::GetMetadataChangeList() { … }
void SessionStore::WriteBatch::Commit(std::unique_ptr<WriteBatch> batch) { … }
bool SessionStore::AreValidSpecifics(const SessionSpecifics& specifics) { … }
std::string SessionStore::GetClientTag(const SessionSpecifics& specifics) { … }
std::string SessionStore::GetStorageKey(const SessionSpecifics& specifics) { … }
std::string SessionStore::GetHeaderStorageKey(const std::string& session_tag) { … }
std::string SessionStore::GetTabStorageKey(const std::string& session_tag,
int tab_node_id) { … }
bool SessionStore::StorageKeyMatchesLocalSession(
const std::string& storage_key) const { … }
std::string SessionStore::GetTabClientTagForTest(const std::string& session_tag,
int tab_node_id) { … }
void SessionStore::OnStoreCreated(
std::unique_ptr<Builder> builder,
const std::optional<syncer::ModelError>& error,
std::unique_ptr<DataTypeStore> underlying_store) { … }
void SessionStore::OnReadAllMetadata(
std::unique_ptr<Builder> builder,
const std::optional<syncer::ModelError>& error,
std::unique_ptr<syncer::MetadataBatch> metadata_batch) { … }
void SessionStore::OnReadAllData(
std::unique_ptr<Builder> builder,
const std::optional<syncer::ModelError>& error) { … }
SessionStore::SessionStore(
const SessionInfo& local_session_info,
std::unique_ptr<syncer::DataTypeStore> underlying_store,
std::map<std::string, sync_pb::SessionSpecifics> initial_data,
const syncer::EntityMetadataMap& initial_metadata,
SyncSessionsClient* sessions_client)
: … { … }
SessionStore::~SessionStore() = default;
std::unique_ptr<syncer::DataBatch> SessionStore::GetSessionDataForKeys(
const std::vector<std::string>& storage_keys) const { … }
std::unique_ptr<syncer::DataBatch> SessionStore::GetAllSessionData() const { … }
std::unique_ptr<SessionStore::WriteBatch> SessionStore::CreateWriteBatch(
syncer::OnceModelErrorHandler error_handler) { … }
void SessionStore::DeleteAllDataAndMetadata() { … }
}