chromium/components/history/core/browser/sync/history_sync_bridge.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/history/core/browser/sync/history_sync_bridge.h"

#include <optional>
#include <vector>

#include "base/auto_reset.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/sync/history_sync_metadata_database.h"
#include "components/history/core/browser/sync/visit_id_remapper.h"
#include "components/history/core/browser/url_row.h"
#include "components/history/core/browser/visit_annotations_database.h"
#include "components/sync/base/page_transition_conversion.h"
#include "components/sync/model/conflict_resolution.h"
#include "components/sync/model/data_type_local_change_processor.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/model/mutable_data_batch.h"
#include "components/sync/model/sync_metadata_store_change_list.h"
#include "components/sync/protocol/history_specifics.pb.h"
#include "ui/base/page_transition_types.h"

namespace history {

namespace {

constexpr base::TimeDelta kMaxWriteToTheFuture =;

// Redirect chains have theoretically unbounded size, and in excessive cases
// they can become so large that the whole entity may fail to sync due to its
// size. Avoid even trying to commit such entities.
constexpr int kMaxRedirectsPerEntity =;

// Some pages embed the favicon image itself in the URL, using the data: scheme.
// These cases, or more generally any favicon URL that is unreasonably large,
// should simply be ignored, because it otherwise runs into the risk that the
// whole entity may fail to sync due to max size limits imposed by the sync
// server. And after all, the favicon is somewhat optional.
constexpr int kMaxFaviconUrlSizeToSync =;

bool ShouldSync(const GURL& url) {}

std::string GetStorageKeyFromVisitRow(const VisitRow& row) {}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// LINT.IfChange(SyncHistoryDatabaseError)
enum class SyncHistoryDatabaseError {};
// LINT.ThenChange(/tools/metrics/histograms/metadata/sync/enums.xml:SyncHistoryDatabaseError)

void RecordDatabaseError(SyncHistoryDatabaseError error) {}

base::Time GetVisitTime(const sync_pb::HistorySpecifics& specifics) {}

sync_pb::SyncEnums::BrowserType BrowserTypeToProto(
    VisitContextAnnotations::BrowserType type) {}

VisitContextAnnotations::BrowserType BrowserTypeFromProto(
    sync_pb::SyncEnums::BrowserType type) {}

VisitContentAnnotations::PasswordState PasswordStateFromProto(
    sync_pb::SyncEnums::PasswordState password_state) {}

sync_pb::SyncEnums::PasswordState PasswordStateToProto(
    VisitContentAnnotations::PasswordState password_state) {}

// Creates a VisitRow out of a single redirect entry within the `specifics`.
// The `visit_id` and `url_id` will be unset; the HistoryBackend assigns those.
VisitRow MakeVisitRow(const sync_pb::HistorySpecifics& specifics,
                      int redirect_index) {}

std::optional<VisitContextAnnotations> MakeContextAnnotations(
    const sync_pb::HistorySpecifics& specifics,
    int redirect_index) {}

std::optional<VisitContentAnnotations> MakeContentAnnotations(
    const sync_pb::HistorySpecifics& specifics,
    int redirect_index) {}

// `included_visit_ids` may be nullptr.
std::unique_ptr<syncer::EntityData> MakeEntityData(
    const std::string& local_cache_guid,
    const std::vector<AnnotatedVisit>& redirect_visits,
    bool redirect_chain_middle_trimmed,
    const GURL& referrer_url,
    const std::vector<GURL>& favicon_urls,
    int64_t local_cluster_id,
    std::vector<VisitID>* included_visit_ids,
    std::optional<std::string> app_id) {}

// Returns whether all of the URLs in `specifics` are actually considered
// syncable, and eligible for being added to the history DB.
bool SpecificsContainsOnlyValidURLs(
    const sync_pb::HistorySpecifics& specifics,
    const HistoryBackendForSync* history_backend) {}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// LINT.IfChange(SyncHistorySpecificsError)
enum class SpecificsError {};
// LINT.ThenChange(/tools/metrics/histograms/metadata/sync/enums.xml:SyncHistorySpecificsError)

// Checks the given `specifics` for validity, i.e. whether it passes some basic
// validation checks, and returns the appropriate error if it doesn't.
std::optional<SpecificsError> GetSpecificsError(
    const sync_pb::HistorySpecifics& specifics,
    const HistoryBackendForSync* history_backend) {}

void RecordSpecificsError(SpecificsError error) {}

}  // namespace

HistorySyncBridge::HistorySyncBridge(
    HistoryBackendForSync* history_backend,
    HistorySyncMetadataDatabase* sync_metadata_database,
    std::unique_ptr<syncer::DataTypeLocalChangeProcessor> change_processor)
    :{}

HistorySyncBridge::~HistorySyncBridge() = default;

std::unique_ptr<syncer::MetadataChangeList>
HistorySyncBridge::CreateMetadataChangeList() {}

std::optional<syncer::ModelError> HistorySyncBridge::MergeFullSyncData(
    std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
    syncer::EntityChangeList entity_data) {}

std::optional<syncer::ModelError>
HistorySyncBridge::ApplyIncrementalSyncChanges(
    std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
    syncer::EntityChangeList entity_changes) {}

void HistorySyncBridge::ApplyDisableSyncChanges(
    std::unique_ptr<syncer::MetadataChangeList> delete_metadata_change_list) {}

std::unique_ptr<syncer::DataBatch> HistorySyncBridge::GetDataForCommit(
    StorageKeyList storage_keys) {}

std::unique_ptr<syncer::DataBatch> HistorySyncBridge::GetDataImpl(
    StorageKeyList storage_keys) {}

std::unique_ptr<syncer::DataBatch> HistorySyncBridge::GetAllDataForDebugging() {}

std::string HistorySyncBridge::GetClientTag(
    const syncer::EntityData& entity_data) {}

std::string HistorySyncBridge::GetStorageKey(
    const syncer::EntityData& entity_data) {}

syncer::ConflictResolution HistorySyncBridge::ResolveConflict(
    const std::string& storage_key,
    const syncer::EntityData& remote_data) const {}

void HistorySyncBridge::OnURLVisited(HistoryBackend* history_backend,
                                     const URLRow& url_row,
                                     const VisitRow& visit_row) {}

void HistorySyncBridge::OnURLsModified(HistoryBackend* history_backend,
                                       const URLRows& changed_urls,
                                       bool is_from_expiration) {}

void HistorySyncBridge::OnHistoryDeletions(HistoryBackend* history_backend,
                                           bool all_history,
                                           bool expired,
                                           const URLRows& deleted_rows,
                                           const std::set<GURL>& favicon_urls) {}

void HistorySyncBridge::OnVisitUpdated(const VisitRow& visit_row,
                                       VisitUpdateReason reason) {}

void HistorySyncBridge::OnVisitDeleted(const VisitRow& visit_row) {}

void HistorySyncBridge::SetSyncTransportState(
    syncer::SyncService::TransportState state) {}

void HistorySyncBridge::OnDatabaseError() {}

void HistorySyncBridge::LoadMetadata() {}

bool HistorySyncBridge::ShouldCommitRightNow() const {}

void HistorySyncBridge::MaybeCommit(const VisitRow& visit_row) {}

std::vector<std::unique_ptr<syncer::EntityData>>
HistorySyncBridge::QueryRedirectChainAndMakeEntityData(
    const VisitRow& final_visit,
    std::vector<VisitID>* included_visit_ids) {}

GURL HistorySyncBridge::GetURLForVisit(VisitID visit_id) {}

bool HistorySyncBridge::AddEntityInBackend(
    VisitIDRemapper* id_remapper,
    const sync_pb::HistorySpecifics& specifics) {}

bool HistorySyncBridge::UpdateEntityInBackend(
    VisitIDRemapper* id_remapper,
    const sync_pb::HistorySpecifics& specifics) {}

void HistorySyncBridge::UntrackAndClearMetadataForAllEntities() {}

void HistorySyncBridge::UntrackAndClearMetadataForSyncedEntities() {}

std::string HistorySyncBridge::GetLocalCacheGuid() const {}

}  // namespace history