| Index: components/browsing_data/core/counters/passwords_counter.cc
|
| diff --git a/components/browsing_data/core/counters/passwords_counter.cc b/components/browsing_data/core/counters/passwords_counter.cc
|
| index 8585158b83981f8184fd1c8d7bfdcd214df9af1b..5bc03978b99223bc19f4b292836129cf4cef54f5 100644
|
| --- a/components/browsing_data/core/counters/passwords_counter.cc
|
| +++ b/components/browsing_data/core/counters/passwords_counter.cc
|
| @@ -5,20 +5,41 @@
|
| #include "components/browsing_data/core/counters/passwords_counter.h"
|
|
|
| #include "components/browsing_data/core/pref_names.h"
|
| +#include "components/password_manager/core/browser/password_manager_util.h"
|
| #include "components/password_manager/core/browser/password_store.h"
|
| +#include "components/sync/driver/sync_service.h"
|
| +
|
| +namespace {
|
| +
|
| +bool IsPasswordSyncEnabled(const syncer::SyncService* sync_service) {
|
| + if (!sync_service)
|
| + return false;
|
| + return password_manager_util::GetPasswordSyncState(sync_service) !=
|
| + password_manager::PasswordSyncState::NOT_SYNCING_PASSWORDS;
|
| +}
|
| +
|
| +} // namespace
|
|
|
| namespace browsing_data {
|
|
|
| PasswordsCounter::PasswordsCounter(
|
| - scoped_refptr<password_manager::PasswordStore> store) : store_(store) {}
|
| + scoped_refptr<password_manager::PasswordStore> store,
|
| + syncer::SyncService* sync_service)
|
| + : store_(store), sync_service_(sync_service), password_sync_enabled_() {
|
| + DCHECK(store_);
|
| +}
|
|
|
| PasswordsCounter::~PasswordsCounter() {
|
| store_->RemoveObserver(this);
|
| + if (sync_service_)
|
| + sync_service_->RemoveObserver(this);
|
| }
|
|
|
| void PasswordsCounter::OnInitialized() {
|
| - DCHECK(store_);
|
| store_->AddObserver(this);
|
| + if (sync_service_)
|
| + sync_service_->AddObserver(this);
|
| + password_sync_enabled_ = IsPasswordSyncEnabled(sync_service_);
|
| }
|
|
|
| const char* PasswordsCounter::GetPrefName() const {
|
| @@ -37,11 +58,13 @@ void PasswordsCounter::Count() {
|
| void PasswordsCounter::OnGetPasswordStoreResults(
|
| std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
|
| base::Time start = GetPeriodStart();
|
| - ReportResult(std::count_if(
|
| + int num_passwords = std::count_if(
|
| results.begin(), results.end(),
|
| [start](const std::unique_ptr<autofill::PasswordForm>& form) {
|
| return form->date_created >= start;
|
| - }));
|
| + });
|
| + ReportResult(base::MakeUnique<PasswordResult>(this, num_passwords,
|
| + password_sync_enabled_));
|
| }
|
|
|
| void PasswordsCounter::OnLoginsChanged(
|
| @@ -49,4 +72,23 @@ void PasswordsCounter::OnLoginsChanged(
|
| Restart();
|
| }
|
|
|
| +void PasswordsCounter::OnStateChanged(syncer::SyncService* sync) {
|
| + bool sync_enabled_new = IsPasswordSyncEnabled(sync_service_);
|
| +
|
| + if (password_sync_enabled_ != sync_enabled_new) {
|
| + password_sync_enabled_ = sync_enabled_new;
|
| + Restart();
|
| + }
|
| +}
|
| +
|
| +// PasswordsCounter::PasswordResult
|
| +
|
| +PasswordsCounter::PasswordResult::PasswordResult(const PasswordsCounter* source,
|
| + ResultInt value,
|
| + bool password_sync_enabled)
|
| + : FinishedResult(source, value),
|
| + password_sync_enabled_(password_sync_enabled) {}
|
| +
|
| +PasswordsCounter::PasswordResult::~PasswordResult() {}
|
| +
|
| } // namespace browsing_data
|
|
|