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=( ...@@ -186,15 +186,18 @@ CredentialWithPassword& CredentialWithPassword::operator=(
CompromisedCredentialsManager::CompromisedCredentialsManager( CompromisedCredentialsManager::CompromisedCredentialsManager(
scoped_refptr<PasswordStore> store, scoped_refptr<PasswordStore> store,
SavedPasswordsPresenter* presenter) SavedPasswordsPresenter* presenter)
: store_(std::move(store)), presenter_(presenter) { : store_(std::move(store)),
observed_password_store_.Add(store_.get()); presenter_(presenter),
compromised_credentials_reader_(store_.get()) {
observed_compromised_credentials_reader_.Add(
&compromised_credentials_reader_);
observed_saved_password_presenter_.Add(presenter_); observed_saved_password_presenter_.Add(presenter_);
} }
CompromisedCredentialsManager::~CompromisedCredentialsManager() = default; CompromisedCredentialsManager::~CompromisedCredentialsManager() = default;
void CompromisedCredentialsManager::Init() { void CompromisedCredentialsManager::Init() {
store_->GetAllCompromisedCredentials(this); compromised_credentials_reader_.Init();
} }
void CompromisedCredentialsManager::SaveCompromisedCredential( void CompromisedCredentialsManager::SaveCompromisedCredential(
...@@ -276,17 +279,11 @@ void CompromisedCredentialsManager::RemoveObserver(Observer* observer) { ...@@ -276,17 +279,11 @@ void CompromisedCredentialsManager::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(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 // Re-computes the list of compromised credentials with passwords after
// obtaining a new list of compromised credentials. // obtaining a new list of compromised credentials.
void CompromisedCredentialsManager::OnGetCompromisedCredentials( void CompromisedCredentialsManager::OnCompromisedCredentialsChanged(
std::vector<CompromisedCredentials> compromised_credentials) { const std::vector<CompromisedCredentials>& compromised_credentials) {
compromised_credentials_ = std::move(compromised_credentials); compromised_credentials_ = compromised_credentials;
UpdateCachedDataAndNotifyObservers(presenter_->GetSavedPasswords()); UpdateCachedDataAndNotifyObservers(presenter_->GetSavedPasswords());
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/password_manager/core/browser/compromised_credentials_table.h" #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/leak_detection/bulk_leak_check.h"
#include "components/password_manager/core/browser/password_store.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/credential_utils.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h" #include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -96,8 +97,7 @@ struct CredentialMetadata; ...@@ -96,8 +97,7 @@ struct CredentialMetadata;
// autofill::PasswordForms. It supports an observer interface, and clients can // autofill::PasswordForms. It supports an observer interface, and clients can
// register themselves to get notified about changes to the list. // register themselves to get notified about changes to the list.
class CompromisedCredentialsManager class CompromisedCredentialsManager
: public PasswordStore::DatabaseCompromisedCredentialsObserver, : public CompromisedCredentialsReader::Observer,
public CompromisedCredentialsConsumer,
public SavedPasswordsPresenter::Observer { public SavedPasswordsPresenter::Observer {
public: public:
using CredentialsView = base::span<const CredentialWithPassword>; using CredentialsView = base::span<const CredentialWithPassword>;
...@@ -147,12 +147,10 @@ class CompromisedCredentialsManager ...@@ -147,12 +147,10 @@ class CompromisedCredentialsManager
using CredentialPasswordsMap = using CredentialPasswordsMap =
std::map<CredentialView, CredentialMetadata, PasswordCredentialLess>; std::map<CredentialView, CredentialMetadata, PasswordCredentialLess>;
// PasswordStore::DatabaseCompromisedCredentialsObserver: // CompromisedCredentialsReader::Observer:
void OnCompromisedCredentialsChanged() override; void OnCompromisedCredentialsChanged(
const std::vector<CompromisedCredentials>& compromised_credentials)
// CompromisedCredentialsConsumer: override;
void OnGetCompromisedCredentials(
std::vector<CompromisedCredentials> compromised_credentials) override;
// SavedPasswordsPresenter::Observer: // SavedPasswordsPresenter::Observer:
void OnSavedPasswordsChanged( void OnSavedPasswordsChanged(
...@@ -169,6 +167,10 @@ class CompromisedCredentialsManager ...@@ -169,6 +167,10 @@ class CompromisedCredentialsManager
// credentials with saved passwords. Needs to outlive this instance. // credentials with saved passwords. Needs to outlive this instance.
SavedPasswordsPresenter* presenter_ = nullptr; 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. // Cache of the most recently obtained compromised credentials.
std::vector<CompromisedCredentials> compromised_credentials_; std::vector<CompromisedCredentials> compromised_credentials_;
...@@ -176,13 +178,11 @@ class CompromisedCredentialsManager ...@@ -176,13 +178,11 @@ class CompromisedCredentialsManager
// create_type and combined compromise type. // create_type and combined compromise type.
CredentialPasswordsMap credentials_to_forms_; CredentialPasswordsMap credentials_to_forms_;
// A scoped observer for |store_| to listen changes related to // A scoped observer for |compromised_credentials_reader_| to listen changes
// CompromisedCredentials only. // related to CompromisedCredentials only.
ScopedObserver<PasswordStore, ScopedObserver<CompromisedCredentialsReader,
PasswordStore::DatabaseCompromisedCredentialsObserver, CompromisedCredentialsReader::Observer>
&PasswordStore::AddDatabaseCompromisedCredentialsObserver, observed_compromised_credentials_reader_{this};
&PasswordStore::RemoveDatabaseCompromisedCredentialsObserver>
observed_password_store_{this};
// A scoped observer for |presenter_|. // A scoped observer for |presenter_|.
ScopedObserver<SavedPasswordsPresenter, SavedPasswordsPresenter::Observer> 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