Commit 9fd38cdd authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Use CompromisedCredentialsReader in ...

... CompromisedCredentialsManager

Bug: 1108422
Change-Id: I750c63612bb68b9156b89fe2f7b4961f324a3067
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367099Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800659}
parent 3166ebf7
......@@ -186,15 +186,18 @@ CredentialWithPassword& CredentialWithPassword::operator=(
CompromisedCredentialsManager::CompromisedCredentialsManager(
scoped_refptr<PasswordStore> store,
SavedPasswordsPresenter* presenter)
: store_(std::move(store)), presenter_(presenter) {
observed_password_store_.Add(store_.get());
: store_(std::move(store)),
presenter_(presenter),
compromised_credentials_reader_(store_.get()) {
observed_compromised_credentials_reader_.Add(
&compromised_credentials_reader_);
observed_saved_password_presenter_.Add(presenter_);
}
CompromisedCredentialsManager::~CompromisedCredentialsManager() = default;
void CompromisedCredentialsManager::Init() {
store_->GetAllCompromisedCredentials(this);
compromised_credentials_reader_.Init();
}
void CompromisedCredentialsManager::SaveCompromisedCredential(
......@@ -276,17 +279,11 @@ void CompromisedCredentialsManager::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void CompromisedCredentialsManager::OnCompromisedCredentialsChanged() {
// Cancel ongoing requests to the password store and issue a new request.
cancelable_task_tracker()->TryCancelAll();
store_->GetAllCompromisedCredentials(this);
}
// Re-computes the list of compromised credentials with passwords after
// obtaining a new list of compromised credentials.
void CompromisedCredentialsManager::OnGetCompromisedCredentials(
std::vector<CompromisedCredentials> compromised_credentials) {
compromised_credentials_ = std::move(compromised_credentials);
void CompromisedCredentialsManager::OnCompromisedCredentialsChanged(
const std::vector<CompromisedCredentials>& compromised_credentials) {
compromised_credentials_ = compromised_credentials;
UpdateCachedDataAndNotifyObservers(presenter_->GetSavedPasswords());
}
......
......@@ -18,6 +18,7 @@
#include "components/password_manager/core/browser/compromised_credentials_table.h"
#include "components/password_manager/core/browser/leak_detection/bulk_leak_check.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/ui/compromised_credentials_reader.h"
#include "components/password_manager/core/browser/ui/credential_utils.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"
#include "url/gurl.h"
......@@ -96,8 +97,7 @@ struct CredentialMetadata;
// autofill::PasswordForms. It supports an observer interface, and clients can
// register themselves to get notified about changes to the list.
class CompromisedCredentialsManager
: public PasswordStore::DatabaseCompromisedCredentialsObserver,
public CompromisedCredentialsConsumer,
: public CompromisedCredentialsReader::Observer,
public SavedPasswordsPresenter::Observer {
public:
using CredentialsView = base::span<const CredentialWithPassword>;
......@@ -147,12 +147,10 @@ class CompromisedCredentialsManager
using CredentialPasswordsMap =
std::map<CredentialView, CredentialMetadata, PasswordCredentialLess>;
// PasswordStore::DatabaseCompromisedCredentialsObserver:
void OnCompromisedCredentialsChanged() override;
// CompromisedCredentialsConsumer:
void OnGetCompromisedCredentials(
std::vector<CompromisedCredentials> compromised_credentials) override;
// CompromisedCredentialsReader::Observer:
void OnCompromisedCredentialsChanged(
const std::vector<CompromisedCredentials>& compromised_credentials)
override;
// SavedPasswordsPresenter::Observer:
void OnSavedPasswordsChanged(
......@@ -169,6 +167,10 @@ class CompromisedCredentialsManager
// credentials with saved passwords. Needs to outlive this instance.
SavedPasswordsPresenter* presenter_ = nullptr;
// The reader used to read the compromised credentials from the password
// store.
CompromisedCredentialsReader compromised_credentials_reader_;
// Cache of the most recently obtained compromised credentials.
std::vector<CompromisedCredentials> compromised_credentials_;
......@@ -176,13 +178,11 @@ class CompromisedCredentialsManager
// create_type and combined compromise type.
CredentialPasswordsMap credentials_to_forms_;
// A scoped observer for |store_| to listen changes related to
// CompromisedCredentials only.
ScopedObserver<PasswordStore,
PasswordStore::DatabaseCompromisedCredentialsObserver,
&PasswordStore::AddDatabaseCompromisedCredentialsObserver,
&PasswordStore::RemoveDatabaseCompromisedCredentialsObserver>
observed_password_store_{this};
// A scoped observer for |compromised_credentials_reader_| to listen changes
// related to CompromisedCredentials only.
ScopedObserver<CompromisedCredentialsReader,
CompromisedCredentialsReader::Observer>
observed_compromised_credentials_reader_{this};
// A scoped observer for |presenter_|.
ScopedObserver<SavedPasswordsPresenter, SavedPasswordsPresenter::Observer>
......
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