OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/browsing_data/passwords_counter.h" | |
6 #include "chrome/browser/password_manager/password_store_factory.h" | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "components/browsing_data/core/pref_names.h" | |
9 #include "components/password_manager/core/browser/password_store.h" | |
10 | |
11 PasswordsCounter::PasswordsCounter(Profile* profile) | |
12 : BrowsingDataCounter(browsing_data::prefs::kDeletePasswords), | |
13 profile_(profile) {} | |
14 | |
15 PasswordsCounter::~PasswordsCounter() { | |
16 store_->RemoveObserver(this); | |
17 } | |
18 | |
19 void PasswordsCounter::OnInitialized() { | |
20 store_ = PasswordStoreFactory::GetForProfile( | |
21 profile_, ServiceAccessType::EXPLICIT_ACCESS); | |
22 DCHECK(store_); | |
23 store_->AddObserver(this); | |
24 } | |
25 | |
26 void PasswordsCounter::Count() { | |
27 cancelable_task_tracker()->TryCancelAll(); | |
28 // TODO(msramek): We don't actually need the logins themselves, just their | |
29 // count. Consider implementing |PasswordStore::CountAutofillableLogins|. | |
30 // This custom request should also allow us to specify the time range, so that | |
31 // we can use it to filter the login creation date in the database. | |
32 store_->GetAutofillableLogins(this); | |
33 } | |
34 | |
35 void PasswordsCounter::OnGetPasswordStoreResults( | |
36 ScopedVector<autofill::PasswordForm> results) { | |
37 base::Time start = GetPeriodStart(); | |
38 ReportResult(std::count_if( | |
39 results.begin(), | |
40 results.end(), | |
41 [start](const autofill::PasswordForm* form) { | |
42 return form->date_created >= start; | |
43 })); | |
44 } | |
45 | |
46 void PasswordsCounter::OnLoginsChanged( | |
47 const password_manager::PasswordStoreChangeList& changes) { | |
48 Restart(); | |
49 } | |
OLD | NEW |