chromium/components/sync/engine/data_type_worker.cc

// Copyright 2014 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/sync/engine/data_type_worker.h"

#include <stdint.h>

#include <map>
#include <set>
#include <utility>

#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/uuid.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/data_type_histogram.h"
#include "components/sync/base/features.h"
#include "components/sync/base/hash_util.h"
#include "components/sync/base/sync_invalidation_adapter.h"
#include "components/sync/base/time.h"
#include "components/sync/engine/bookmark_update_preprocessing.h"
#include "components/sync/engine/cancelation_signal.h"
#include "components/sync/engine/commit_contribution.h"
#include "components/sync/engine/commit_contribution_impl.h"
#include "components/sync/engine/cycle/entity_change_metric_recording.h"
#include "components/sync/engine/data_type_processor.h"
#include "components/sync/protocol/data_type_progress_marker.pb.h"
#include "components/sync/protocol/data_type_state_helper.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/password_specifics.pb.h"
#include "components/sync/protocol/proto_memory_estimations.h"
#include "components/sync/protocol/sync_entity.pb.h"

namespace syncer {

namespace {

const char kUndecryptablePendingUpdatesDroppedHistogramName[] =;
const char kBlockedByUndecryptableUpdateHistogramName[] =;
const char kPasswordNotesStateHistogramName[] =;
constexpr char kEntityEncryptionResultHistogramName[] =;

// Sync ignores updates encrypted with keys that have been missing for too long
// from this client and will proceed normally as if those updates didn't exist.
// The notion of "too long" is measured in number of GetUpdates and is
// determined by this constant. The counter is in-memory only.
constexpr int kMinGuResponsesToIgnoreKey =;

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

void LogPasswordNotesState(PasswordNotesStateForUMA state) {}

void LogEncryptionResult(DataType type, bool success) {}

void LogCrossUserSharingDecryptionResult(
    CrossUserSharingDecryptionResult result) {}

// A proxy which can be called from any sequence and delegates the work to the
// commit queue injected on construction.
class CommitQueueProxy : public CommitQueue {};

void AdaptClientTagForFullUpdateData(DataType data_type,
                                     syncer::EntityData* data) {}

void AdaptWebAuthnClientTagHash(syncer::EntityData* data) {}

// Returns empty string if |entity| is not encrypted.
// TODO(crbug.com/40141634): Consider moving this to a util file and converting
// UpdateResponseData::encryption_key_name into a method that calls it. Consider
// returning a struct containing also the encrypted blob, which would make the
// code of PopulateUpdateResponseData() simpler.
std::string GetEncryptionKeyName(const sync_pb::SyncEntity& entity) {}

// Attempts to decrypt the given specifics and return them in the |out|
// parameter. The cryptographer must know the decryption key, i.e.
// cryptographer.CanDecrypt(specifics.encrypted()) must return true.
//
// Returns false if the decryption failed. There are no guarantees about the
// contents of |out| when that happens.
//
// In theory, this should never fail. Only corrupt or invalid entries could
// cause this to fail, and no clients are known to create such entries. The
// failure case is an attempt to be defensive against bad input.
bool DecryptSpecifics(const Cryptographer& cryptographer,
                      const sync_pb::EntitySpecifics& in,
                      sync_pb::EntitySpecifics* out) {}

// Attempts to decrypt the given password specifics and return them in the
// |out| parameter. The cryptographer must know the decryption key, i.e.
// cryptographer.CanDecrypt(in.encrypted()) must return true.
//
// Returns false if the decryption failed. There are no guarantees about the
// contents of |out| when that happens.
//
// In theory, this should never fail. Only corrupt or invalid entries could
// cause this to fail, and no clients are known to create such entries. The
// failure case is an attempt to be defensive against bad input.
bool DecryptPasswordSpecifics(const Cryptographer& cryptographer,
                              const sync_pb::PasswordSpecifics& in,
                              sync_pb::PasswordSpecificsData* out) {}

bool DecryptIncomingPasswordSharingInvitationSpecifics(
    const Cryptographer& cryptographer,
    const sync_pb::IncomingPasswordSharingInvitationSpecifics& invitation,
    sync_pb::PasswordSharingInvitationData* unencrypted_invitation_data) {}

}  // namespace

DataTypeWorker::DataTypeWorker(DataType type,
                               const sync_pb::DataTypeState& initial_state,
                               Cryptographer* cryptographer,
                               bool encryption_enabled,
                               PassphraseType passphrase_type,
                               NudgeHandler* nudge_handler,
                               CancelationSignal* cancelation_signal)
    :{}

DataTypeWorker::PendingInvalidation::PendingInvalidation() = default;
DataTypeWorker::PendingInvalidation::PendingInvalidation(
    PendingInvalidation&&) = default;
DataTypeWorker::PendingInvalidation&
DataTypeWorker::PendingInvalidation::operator=(PendingInvalidation&&) =
    default;
DataTypeWorker::PendingInvalidation::PendingInvalidation(
    std::unique_ptr<SyncInvalidation> invalidation,
    bool is_processed)
    :{}
DataTypeWorker::PendingInvalidation::~PendingInvalidation() = default;

DataTypeWorker::~DataTypeWorker() {}

void DataTypeWorker::LogPendingInvalidationStatus(
    PendingInvalidationStatus status) {}

void DataTypeWorker::ConnectSync(
    std::unique_ptr<DataTypeProcessor> data_type_processor) {}

DataType DataTypeWorker::GetDataType() const {}

void DataTypeWorker::EnableEncryption() {}

void DataTypeWorker::OnCryptographerChange() {}

void DataTypeWorker::UpdatePassphraseType(PassphraseType type) {}

bool DataTypeWorker::IsInitialSyncEnded() const {}

const sync_pb::DataTypeProgressMarker& DataTypeWorker::GetDownloadProgress()
    const {}

const sync_pb::DataTypeContext& DataTypeWorker::GetDataTypeContext() const {}

void DataTypeWorker::ProcessGetUpdatesResponse(
    const sync_pb::DataTypeProgressMarker& progress_marker,
    const sync_pb::DataTypeContext& mutated_context,
    const SyncEntityList& applicable_updates,
    StatusController* status) {}

// static
// |response_data| must be not null.
DataTypeWorker::DecryptionStatus DataTypeWorker::PopulateUpdateResponseData(
    const Cryptographer& cryptographer,
    DataType data_type,
    const sync_pb::SyncEntity& update_entity,
    UpdateResponseData* response_data) {}

void DataTypeWorker::ApplyUpdates(StatusController* status, bool cycle_done) {}

void DataTypeWorker::SendPendingUpdatesToProcessorIfReady() {}

void DataTypeWorker::NudgeForCommit() {}

void DataTypeWorker::NudgeIfReadyToCommit() {}

std::unique_ptr<CommitContribution> DataTypeWorker::GetContribution(
    size_t max_entries) {}

bool DataTypeWorker::HasLocalChanges() const {}

void DataTypeWorker::OnCommitResponse(
    const CommitResponseDataList& committed_response_list,
    const FailedCommitResponseDataList& error_response_list) {}

void DataTypeWorker::OnFullCommitFailure(SyncCommitError commit_error) {}

size_t DataTypeWorker::EstimateMemoryUsage() const {}

bool DataTypeWorker::CanCommitItems() const {}

bool DataTypeWorker::BlockForEncryption() const {}

bool DataTypeWorker::UpdateTypeEncryptionKeyName() {}

void DataTypeWorker::DecryptStoredEntities() {}

void DataTypeWorker::DeduplicatePendingUpdatesBasedOnServerId() {}

void DataTypeWorker::DeduplicatePendingUpdatesBasedOnClientTagHash() {}

void DataTypeWorker::DeduplicatePendingUpdatesBasedOnOriginatorClientItemId() {}

bool DataTypeWorker::ShouldIgnoreUpdatesEncryptedWith(
    const std::string& key_name) {}

void DataTypeWorker::MaybeDropPendingUpdatesEncryptedWith(
    const std::string& key_name) {}

void DataTypeWorker::RemoveKeysNoLongerUnknown() {}

bool DataTypeWorker::HasNonDeletionUpdates() const {}

void DataTypeWorker::ExtractGcDirective() {}

void DataTypeWorker::RecordRemoteInvalidation(
    std::unique_ptr<SyncInvalidation> incoming) {}

void DataTypeWorker::CollectPendingInvalidations(
    sync_pb::GetUpdateTriggers* msg) {}

bool DataTypeWorker::HasPendingInvalidations() const {}

void DataTypeWorker::SendPendingInvalidationsToProcessor() {}

void DataTypeWorker::UpdateDataTypeStateInvalidations() {}

void DataTypeWorker::EncryptPasswordSpecificsData(
    CommitRequestDataList* request_data_list) {}

void DataTypeWorker::EncryptOutgoingPasswordSharingInvitations(
    CommitRequestDataList* request_data_list) {}

void DataTypeWorker::EncryptSpecifics(
    CommitRequestDataList* request_data_list) {}

GetLocalChangesRequest::GetLocalChangesRequest()
    :{}

GetLocalChangesRequest::~GetLocalChangesRequest() = default;

void GetLocalChangesRequest::OnCancelationSignalReceived() {}

void GetLocalChangesRequest::WaitForResponseOrCancelation(
    CancelationSignal* cancelation_signal) {}

void GetLocalChangesRequest::SetResponse(
    CommitRequestDataList&& local_changes) {}

CommitRequestDataList&& GetLocalChangesRequest::ExtractResponse() {}

}  // namespace syncer