Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / browsing_data / passwords_counter.cc
blob6c805e580552acc006e93b71401003ff85884b3b
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/passwords_counter.h"
6 #include "chrome/browser/password_manager/password_store_factory.h"
7 #include "chrome/common/pref_names.h"
8 #include "components/password_manager/core/browser/password_store.h"
10 PasswordsCounter::PasswordsCounter() : pref_name_(prefs::kDeletePasswords) {}
12 PasswordsCounter::~PasswordsCounter() {
13 if (store_)
14 store_->RemoveObserver(this);
17 void PasswordsCounter::OnInitialized() {
18 store_ = PasswordStoreFactory::GetForProfile(
19 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS).get();
20 if (store_)
21 store_->AddObserver(this);
22 else
23 LOG(ERROR) << "No password store! Cannot count passwords.";
26 const std::string& PasswordsCounter::GetPrefName() const {
27 return pref_name_;
30 void PasswordsCounter::Count() {
31 if (!store_) {
32 ReportResult(0);
33 return;
36 cancelable_task_tracker()->TryCancelAll();
37 // TODO(msramek): We don't actually need the logins themselves, just their
38 // count. Consider implementing |PasswordStore::CountAutofillableLogins|.
39 store_->GetAutofillableLogins(this);
42 void PasswordsCounter::OnGetPasswordStoreResults(
43 ScopedVector<autofill::PasswordForm> results) {
44 ReportResult(results.size());
47 void PasswordsCounter::OnLoginsChanged(
48 const password_manager::PasswordStoreChangeList& changes) {
49 RestartCounting();