Skip to content

Commit

Permalink
Create bridges together with password bridge
Browse files Browse the repository at this point in the history
Introduce sync bridges for password sending data types

This CL just introduces sync bridge skeletons without any logic and
without wiring them.

Bug: 1445868
Change-Id: I31f38a3fd889159e01cca91248798da65f847ea6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4555576
Reviewed-by: Mohamed Amir Yosef <mamir@chromium.org>
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Cr-Commit-Position: refs/heads/main@{#1147748}
  • Loading branch information
Rushan Suleymanov authored and Chromium LUCI CQ committed May 23, 2023
1 parent 692840e commit 9d25ec3
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 18 deletions.
4 changes: 4 additions & 0 deletions components/password_manager/core/browser/BUILD.gn
Expand Up @@ -239,6 +239,10 @@ static_library("browser") {
"store_metrics_reporter.h",
"sync/credential_model_type_controller.cc",
"sync/credential_model_type_controller.h",
"sync/incoming_password_sharing_invitation_sync_bridge.cc",
"sync/incoming_password_sharing_invitation_sync_bridge.h",
"sync/outgoing_password_sharing_invitation_sync_bridge.cc",
"sync/outgoing_password_sharing_invitation_sync_bridge.h",
"sync/password_proto_utils.cc",
"sync/password_proto_utils.h",
"sync/password_sync_bridge.cc",
Expand Down
Expand Up @@ -4,12 +4,17 @@

#include "components/password_manager/core/browser/login_database_async_helper.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/task/sequenced_task_runner.h"
#include "components/os_crypt/sync/os_crypt.h"
#include "components/password_manager/core/browser/login_database.h"
#include "components/password_manager/core/browser/sync/incoming_password_sharing_invitation_sync_bridge.h"
#include "components/password_manager/core/browser/sync/outgoing_password_sharing_invitation_sync_bridge.h"
#include "components/password_manager/core/browser/sync/password_proto_utils.h"
#include "components/password_manager/core/browser/sync/password_sync_bridge.h"
#include "components/sync/base/model_type.h"
#include "components/sync/model/client_tag_based_model_type_processor.h"
#include "components/sync/model/model_type_controller_delegate.h"

Expand Down Expand Up @@ -68,11 +73,19 @@ bool LoginDatabaseAsyncHelper::Initialize(
base::Seconds(30));
}

sync_bridge_ = std::make_unique<PasswordSyncBridge>(
password_sync_bridge_ = std::make_unique<PasswordSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::PASSWORDS, base::DoNothing()),
static_cast<PasswordStoreSync*>(this),
std::move(sync_enabled_or_disabled_cb));
incoming_sharing_invitation_sync_bridge_ =
std::make_unique<IncomingPasswordSharingInvitationSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::INCOMING_PASSWORD_SHARING_INVITATION, base::DoNothing()));
outgoing_sharing_invitation_sync_bridge_ =
std::make_unique<OutgoingPasswordSharingInvitationSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::OUTGOING_PASSWORD_SHARING_INVITATION, base::DoNothing()));

// On Windows encryption capability is expected to be available by default.
// On MacOS encrpytion is also expected to be available unless the user didn't
Expand Down Expand Up @@ -142,8 +155,9 @@ PasswordChangesOrError LoginDatabaseAsyncHelper::AddLogin(
BeginTransaction();
AddCredentialError error = AddCredentialError::kNone;
PasswordStoreChangeList changes = AddLoginImpl(form, &error);
if (sync_bridge_ && !changes.empty())
sync_bridge_->ActOnPasswordStoreChanges(changes);
if (password_sync_bridge_ && !changes.empty()) {
password_sync_bridge_->ActOnPasswordStoreChanges(changes);
}
// Sync metadata get updated in ActOnPasswordStoreChanges(). Therefore,
// CommitTransaction() must be called after ActOnPasswordStoreChanges(),
// because sync codebase needs to update metadata atomically together with
Expand All @@ -162,8 +176,9 @@ PasswordChangesOrError LoginDatabaseAsyncHelper::UpdateLogin(
BeginTransaction();
UpdateCredentialError error = UpdateCredentialError::kNone;
PasswordStoreChangeList changes = UpdateLoginImpl(form, &error);
if (sync_bridge_ && !changes.empty())
sync_bridge_->ActOnPasswordStoreChanges(changes);
if (password_sync_bridge_ && !changes.empty()) {
password_sync_bridge_->ActOnPasswordStoreChanges(changes);
}
// Sync metadata get updated in ActOnPasswordStoreChanges(). Therefore,
// CommitTransaction() must be called after ActOnPasswordStoreChanges(),
// because sync codebase needs to update metadata atomically together with
Expand All @@ -182,8 +197,9 @@ PasswordChangesOrError LoginDatabaseAsyncHelper::RemoveLogin(
BeginTransaction();
PasswordStoreChangeList changes;
if (login_db_ && login_db_->RemoveLogin(form, &changes)) {
if (sync_bridge_ && !changes.empty())
sync_bridge_->ActOnPasswordStoreChanges(changes);
if (password_sync_bridge_ && !changes.empty()) {
password_sync_bridge_->ActOnPasswordStoreChanges(changes);
}
}
// Sync metadata get updated in ActOnPasswordStoreChanges(). Therefore,
// CommitTransaction() must be called after ActOnPasswordStoreChanges(),
Expand All @@ -201,8 +217,9 @@ PasswordChangesOrError LoginDatabaseAsyncHelper::RemoveLoginsCreatedBetween(
PasswordStoreChangeList changes;
bool success = login_db_ && login_db_->RemoveLoginsCreatedBetween(
delete_begin, delete_end, &changes);
if (success && sync_bridge_ && !changes.empty())
sync_bridge_->ActOnPasswordStoreChanges(changes);
if (success && password_sync_bridge_ && !changes.empty()) {
password_sync_bridge_->ActOnPasswordStoreChanges(changes);
}
// Sync metadata get updated in ActOnPasswordStoreChanges(). Therefore,
// CommitTransaction() must be called after ActOnPasswordStoreChanges(),
// because sync codebase needs to update metadata atomically together with
Expand Down Expand Up @@ -235,8 +252,9 @@ PasswordChangesOrError LoginDatabaseAsyncHelper::RemoveLoginsByURLAndTime(
}
}
}
if (sync_bridge_ && !changes.empty())
sync_bridge_->ActOnPasswordStoreChanges(changes);
if (password_sync_bridge_ && !changes.empty()) {
password_sync_bridge_->ActOnPasswordStoreChanges(changes);
}
// Sync metadata get updated in ActOnPasswordStoreChanges(). Therefore,
// CommitTransaction() must be called after ActOnPasswordStoreChanges(),
// because sync codebase needs to update metadata atomically together with
Expand Down Expand Up @@ -347,7 +365,7 @@ void LoginDatabaseAsyncHelper::RemoveFieldInfoByTime(base::Time remove_begin,
base::WeakPtr<syncer::ModelTypeControllerDelegate>
LoginDatabaseAsyncHelper::GetSyncControllerDelegate() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return sync_bridge_->change_processor()->GetControllerDelegate();
return password_sync_bridge_->change_processor()->GetControllerDelegate();
}

PasswordStoreChangeList LoginDatabaseAsyncHelper::AddCredentialSync(
Expand Down
Expand Up @@ -19,6 +19,8 @@ class ModelTypeControllerDelegate;
namespace password_manager {

class LoginDatabase;
class IncomingPasswordSharingInvitationSyncBridge;
class OutgoingPasswordSharingInvitationSyncBridge;
class PasswordSyncBridge;
class UnsyncedCredentialsDeletionNotifier;

Expand All @@ -36,7 +38,7 @@ class LoginDatabaseAsyncHelper : private PasswordStoreSync {

~LoginDatabaseAsyncHelper() override;

// Opens |login_db_| and creates |sync_bridge_|.
// Opens |login_db_| and creates sync bridges.
bool Initialize(
PasswordStoreBackend::RemoteChangesReceived remote_form_changes_received,
base::RepeatingClosure sync_enabled_or_disabled_cb);
Expand Down Expand Up @@ -125,12 +127,16 @@ class LoginDatabaseAsyncHelper : private PasswordStoreSync {
std::unique_ptr<LoginDatabase> login_db_
GUARDED_BY_CONTEXT(sequence_checker_);

std::unique_ptr<PasswordSyncBridge> sync_bridge_
std::unique_ptr<PasswordSyncBridge> password_sync_bridge_
GUARDED_BY_CONTEXT(sequence_checker_);

// Whenever 'sync_bridge_'receive remote changes this callback is used to
// notify PasswordStore observers about them. Called on a main sequence from
// the 'NotifyLoginsChanged'.
std::unique_ptr<IncomingPasswordSharingInvitationSyncBridge>
incoming_sharing_invitation_sync_bridge_;
std::unique_ptr<OutgoingPasswordSharingInvitationSyncBridge>
outgoing_sharing_invitation_sync_bridge_;

// Whenever 'password_sync_bridge_' receive remote changes this callback is
// used to notify PasswordStore observers about them. Called on a main
// sequence from the 'NotifyLoginsChanged'.
PasswordStoreBackend::RemoteChangesReceived
remote_forms_changes_received_callback_
GUARDED_BY_CONTEXT(sequence_checker_);
Expand Down
@@ -0,0 +1,110 @@
// Copyright 2023 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/password_manager/core/browser/sync/incoming_password_sharing_invitation_sync_bridge.h"

#include "components/sync/model/in_memory_metadata_change_list.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/model/model_type_change_processor.h"
#include "components/sync/model/mutable_data_batch.h"

namespace password_manager {

IncomingPasswordSharingInvitationSyncBridge::
IncomingPasswordSharingInvitationSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor)
: syncer::ModelTypeSyncBridge(std::move(change_processor)) {
// TODO(crbug.com/1445868): read metadata from the store.
std::unique_ptr<syncer::MetadataBatch> batch =
std::make_unique<syncer::MetadataBatch>();
this->change_processor()->ModelReadyToSync(std::move(batch));
}

IncomingPasswordSharingInvitationSyncBridge::
~IncomingPasswordSharingInvitationSyncBridge() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

std::unique_ptr<syncer::MetadataChangeList>
IncomingPasswordSharingInvitationSyncBridge::CreateMetadataChangeList() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return std::make_unique<syncer::InMemoryMetadataChangeList>();
}

absl::optional<syncer::ModelError>
IncomingPasswordSharingInvitationSyncBridge::MergeFullSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
return absl::nullopt;
}

absl::optional<syncer::ModelError>
IncomingPasswordSharingInvitationSyncBridge::ApplyIncrementalSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_changes) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
return absl::nullopt;
}

void IncomingPasswordSharingInvitationSyncBridge::GetData(
StorageKeyList storage_keys,
DataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
auto batch = std::make_unique<syncer::MutableDataBatch>();
std::move(callback).Run(std::move(batch));
}

void IncomingPasswordSharingInvitationSyncBridge::GetAllDataForDebugging(
DataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
auto batch = std::make_unique<syncer::MutableDataBatch>();
std::move(callback).Run(std::move(batch));
}

std::string IncomingPasswordSharingInvitationSyncBridge::GetClientTag(
const syncer::EntityData& entity_data) {
NOTREACHED();
return std::string();
}

std::string IncomingPasswordSharingInvitationSyncBridge::GetStorageKey(
const syncer::EntityData& entity_data) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
return std::string();
}

bool IncomingPasswordSharingInvitationSyncBridge::SupportsGetClientTag() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return false;
}

bool IncomingPasswordSharingInvitationSyncBridge::SupportsGetStorageKey()
const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return true;
}

void IncomingPasswordSharingInvitationSyncBridge::ApplyDisableSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> delete_metadata_change_list) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
}

sync_pb::EntitySpecifics IncomingPasswordSharingInvitationSyncBridge::
TrimAllSupportedFieldsFromRemoteSpecifics(
const sync_pb::EntitySpecifics& entity_specifics) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
return ModelTypeSyncBridge::TrimAllSupportedFieldsFromRemoteSpecifics(
entity_specifics);
}

} // namespace password_manager
@@ -0,0 +1,58 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SYNC_INCOMING_PASSWORD_SHARING_INVITATION_SYNC_BRIDGE_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SYNC_INCOMING_PASSWORD_SHARING_INVITATION_SYNC_BRIDGE_H_

#include <memory>
#include "base/sequence_checker.h"
#include "components/sync/model/model_type_sync_bridge.h"

namespace syncer {
class MetadataChangeList;
class ModelTypeChangeProcessor;
} // namespace syncer

namespace password_manager {

// Sync bridge implementation for INCOMING_PASSWORD_SHARING_INVITATION model
// type.
class IncomingPasswordSharingInvitationSyncBridge
: public syncer::ModelTypeSyncBridge {
public:
explicit IncomingPasswordSharingInvitationSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor);
IncomingPasswordSharingInvitationSyncBridge(
const IncomingPasswordSharingInvitationSyncBridge&) = delete;
IncomingPasswordSharingInvitationSyncBridge& operator=(
const IncomingPasswordSharingInvitationSyncBridge&) = delete;
~IncomingPasswordSharingInvitationSyncBridge() override;

// ModelTypeSyncBridge implementation.
std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
override;
absl::optional<syncer::ModelError> MergeFullSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) override;
absl::optional<syncer::ModelError> ApplyIncrementalSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_changes) override;
void GetData(StorageKeyList storage_keys, DataCallback callback) override;
void GetAllDataForDebugging(DataCallback callback) override;
std::string GetClientTag(const syncer::EntityData& entity_data) override;
std::string GetStorageKey(const syncer::EntityData& entity_data) override;
bool SupportsGetClientTag() const override;
bool SupportsGetStorageKey() const override;
void ApplyDisableSyncChanges(std::unique_ptr<syncer::MetadataChangeList>
delete_metadata_change_list) override;
sync_pb::EntitySpecifics TrimAllSupportedFieldsFromRemoteSpecifics(
const sync_pb::EntitySpecifics& entity_specifics) const override;

private:
SEQUENCE_CHECKER(sequence_checker_);
};

} // namespace password_manager

#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SYNC_INCOMING_PASSWORD_SHARING_INVITATION_SYNC_BRIDGE_H_

0 comments on commit 9d25ec3

Please sign in to comment.