Commit f8510dd5 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Support Account Store in CompromisedCredentialsManager ...

... when joining stored and compromised credentials.

Follow up CLs will support Account Store during other operations in
CompromisedCredentialsManager.

Bug: 1108422
Change-Id: I023026589c4717e0db002901104d7353a6dbae08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2370635Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801336}
parent 4f046e4c
......@@ -224,8 +224,8 @@ PasswordCheckDelegate::PasswordCheckDelegate(Profile* profile)
profile,
ServiceAccessType::EXPLICIT_ACCESS)),
saved_passwords_presenter_(password_store_),
compromised_credentials_manager_(password_store_,
&saved_passwords_presenter_),
compromised_credentials_manager_(&saved_passwords_presenter_,
password_store_),
bulk_leak_check_service_adapter_(
&saved_passwords_presenter_,
BulkLeakCheckServiceFactory::GetForProfile(profile_),
......
......@@ -228,8 +228,8 @@ class PasswordCheckManager
// Used to obtain the list of compromised credentials.
password_manager::CompromisedCredentialsManager
compromised_credentials_manager_{password_store_,
&saved_passwords_presenter_};
compromised_credentials_manager_{&saved_passwords_presenter_,
password_store_};
// Adapter used to start, monitor and stop a bulk leak check.
password_manager::BulkLeakCheckServiceAdapter
......
......@@ -34,22 +34,24 @@ using CredentialPasswordsMap =
// Transparent comparator that can compare CompromisedCredentials and
// autofill::PasswordForm.
struct CredentialWithoutPasswordLess {
static std::tuple<const std::string&, const base::string16&>
CredentialOriginAndUsername(const autofill::PasswordForm& form) {
return std::tie(form.signon_realm, form.username_value);
}
static std::tuple<const std::string&, const base::string16&>
CredentialOriginAndUsername(const CompromisedCredentials& c) {
return std::tie(c.signon_realm, c.username);
}
template <typename T, typename U>
bool operator()(const T& lhs, const U& rhs) const {
return CredentialOriginAndUsername(lhs) < CredentialOriginAndUsername(rhs);
return CredentialOriginAndUsernameAndStore(lhs) <
CredentialOriginAndUsernameAndStore(rhs);
}
using is_transparent = void;
private:
static auto CredentialOriginAndUsernameAndStore(
const autofill::PasswordForm& form) {
return std::tie(form.signon_realm, form.username_value, form.in_store);
}
static auto CredentialOriginAndUsernameAndStore(
const CompromisedCredentials& c) {
return std::tie(c.signon_realm, c.username, c.in_store);
}
};
CompromiseTypeFlags ConvertCompromiseType(CompromiseType type) {
......@@ -184,11 +186,14 @@ CredentialWithPassword& CredentialWithPassword::operator=(
CredentialWithPassword&& other) = default;
CompromisedCredentialsManager::CompromisedCredentialsManager(
scoped_refptr<PasswordStore> store,
SavedPasswordsPresenter* presenter)
: store_(std::move(store)),
presenter_(presenter),
compromised_credentials_reader_(store_.get()) {
SavedPasswordsPresenter* presenter,
scoped_refptr<PasswordStore> profile_store,
scoped_refptr<PasswordStore> account_store)
: presenter_(presenter),
profile_store_(std::move(profile_store)),
account_store_(std::move(account_store)),
compromised_credentials_reader_(profile_store_.get(),
account_store_.get()) {
observed_compromised_credentials_reader_.Add(
&compromised_credentials_reader_);
observed_saved_password_presenter_.Add(presenter_);
......@@ -211,7 +216,7 @@ void CompromisedCredentialsManager::SaveCompromisedCredential(
if (saved_password.password_value == credential.password() &&
CanonicalizeUsername(saved_password.username_value) ==
canonicalized_username) {
store_->AddCompromisedCredentials({
profile_store_->AddCompromisedCredentials({
.signon_realm = saved_password.signon_realm,
.username = saved_password.username_value,
.create_time = base::Time::Now(),
......@@ -235,7 +240,7 @@ bool CompromisedCredentialsManager::UpdateCompromisedCredentials(
return false;
for (size_t i = 1; i < forms.size(); ++i)
store_->RemoveLogin(forms[i]);
profile_store_->RemoveLogin(forms[i]);
// Note: We Invoke EditPassword on the presenter rather than UpdateLogin() on
// the store, so that observers of the presenter get notified of this event.
......@@ -252,7 +257,7 @@ bool CompromisedCredentialsManager::RemoveCompromisedCredential(
// credentials were deleted.
const auto& saved_passwords = it->second.forms;
for (const autofill::PasswordForm& saved_password : saved_passwords)
store_->RemoveLogin(saved_password);
profile_store_->RemoveLogin(saved_password);
return !saved_passwords.empty();
}
......
......@@ -112,8 +112,10 @@ class CompromisedCredentialsManager
CredentialsView credentials) = 0;
};
explicit CompromisedCredentialsManager(scoped_refptr<PasswordStore> store,
SavedPasswordsPresenter* presenter);
CompromisedCredentialsManager(
SavedPasswordsPresenter* presenter,
scoped_refptr<PasswordStore> profile_store,
scoped_refptr<PasswordStore> account_store = nullptr);
~CompromisedCredentialsManager() override;
void Init();
......@@ -160,15 +162,16 @@ class CompromisedCredentialsManager
void UpdateCachedDataAndNotifyObservers(
SavedPasswordsPresenter::SavedPasswordsView saved_passwords);
// The password store containing the compromised credentials.
scoped_refptr<PasswordStore> store_;
// A weak handle to the presenter used to join the list of compromised
// credentials with saved passwords. Needs to outlive this instance.
SavedPasswordsPresenter* presenter_ = nullptr;
// The password stores containing the compromised credentials.
scoped_refptr<PasswordStore> profile_store_;
scoped_refptr<PasswordStore> account_store_;
// The reader used to read the compromised credentials from the password
// store.
// stores.
CompromisedCredentialsReader compromised_credentials_reader_;
// Cache of the most recently obtained compromised credentials.
......
......@@ -95,8 +95,8 @@ IOSChromePasswordCheckManager::IOSChromePasswordCheckManager(
browser_state,
ServiceAccessType::EXPLICIT_ACCESS)),
saved_passwords_presenter_(password_store_),
compromised_credentials_manager_(password_store_,
&saved_passwords_presenter_),
compromised_credentials_manager_(&saved_passwords_presenter_,
password_store_),
bulk_leak_check_service_adapter_(
&saved_passwords_presenter_,
IOSChromeBulkLeakCheckServiceFactory::GetForBrowserState(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment