Commit 1bd3a396 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Introduce CompromisedCredentialsReader

This CL only introduce the simplest version of the reader which handles
only one store.

Follow-up CL will wire it up to the rest of the code, and then make it
handle multiple stores.

Bug: 1108422
Change-Id: If5202f5112cb841bd1c3ac65b37b5a1fa0eade4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367065
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800538}
parent f96c1765
......@@ -230,6 +230,8 @@ static_library("browser") {
"ui/bulk_leak_check_service_adapter.h",
"ui/compromised_credentials_manager.cc",
"ui/compromised_credentials_manager.h",
"ui/compromised_credentials_reader.cc",
"ui/compromised_credentials_reader.h",
"ui/credential_provider_interface.h",
"ui/credential_utils.h",
"ui/export_flow.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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/ui/compromised_credentials_reader.h"
namespace password_manager {
CompromisedCredentialsReader::CompromisedCredentialsReader(PasswordStore* store)
: store_(store) {
DCHECK(store_);
observed_password_store_.Add(store_);
}
CompromisedCredentialsReader::~CompromisedCredentialsReader() = default;
void CompromisedCredentialsReader::Init() {
store_->GetAllCompromisedCredentials(this);
}
void CompromisedCredentialsReader::OnCompromisedCredentialsChanged() {
// Cancel ongoing requests to the password store and issue a new request.
cancelable_task_tracker()->TryCancelAll();
store_->GetAllCompromisedCredentials(this);
}
void CompromisedCredentialsReader::OnGetCompromisedCredentials(
std::vector<CompromisedCredentials> compromised_credentials) {
for (auto& observer : observers_)
observer.OnCompromisedCredentialsChanged(compromised_credentials);
}
void CompromisedCredentialsReader::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void CompromisedCredentialsReader::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
} // namespace password_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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_UI_COMPROMISED_CREDENTIALS_READER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_UI_COMPROMISED_CREDENTIALS_READER_H_
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "components/password_manager/core/browser/compromised_credentials_consumer.h"
#include "components/password_manager/core/browser/password_store.h"
namespace password_manager {
// This class is responsible for reading and listening to change in the
// compormised credentials in the underlying password stores.
class CompromisedCredentialsReader
: public PasswordStore::DatabaseCompromisedCredentialsObserver,
public CompromisedCredentialsConsumer {
public:
// Observer interface. Clients can implement this to get notified about
// changes to the list of compromised credentials. Clients can register and
// de-register themselves, and are expected to do so before the provider gets
// out of scope.
class Observer : public base::CheckedObserver {
public:
virtual void OnCompromisedCredentialsChanged(
const std::vector<CompromisedCredentials>& compromised_credentials) = 0;
};
// |store| cannot be null, and must outlive this class.
explicit CompromisedCredentialsReader(PasswordStore* store);
CompromisedCredentialsReader(const CompromisedCredentialsReader&) = delete;
CompromisedCredentialsReader& operator=(const CompromisedCredentialsReader&) =
delete;
~CompromisedCredentialsReader() override;
void Init();
// Allows clients and register and de-register themselves.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
// PasswordStore::DatabaseCompromisedCredentialsObserver:
void OnCompromisedCredentialsChanged() override;
// CompromisedCredentialsConsumer:
void OnGetCompromisedCredentials(
std::vector<CompromisedCredentials> compromised_credentials) override;
// The password store containing the compromised credentials. It must outlive
// this class.
PasswordStore* store_;
// A scoped observer for |store_| to listen changes related to
// CompromisedCredentials only.
ScopedObserver<PasswordStore,
PasswordStore::DatabaseCompromisedCredentialsObserver,
&PasswordStore::AddDatabaseCompromisedCredentialsObserver,
&PasswordStore::RemoveDatabaseCompromisedCredentialsObserver>
observed_password_store_{this};
base::ObserverList<Observer, /*check_empty=*/true> observers_;
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_UI_COMPROMISED_CREDENTIALS_READER_H_
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