Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: components/browsing_data/core/counters/passwords_counter.cc

Issue 2153863002: Move counters for passwords, history and autofill to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate_build_targets_in_components_bd
Patch Set: Addressed comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/browsing_data/core/counters/passwords_counter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data/passwords_counter.h" 5 #include "components/browsing_data/core/counters/passwords_counter.h"
6 #include "chrome/browser/password_manager/password_store_factory.h" 6
7 #include "chrome/browser/profiles/profile.h"
8 #include "components/browsing_data/core/pref_names.h" 7 #include "components/browsing_data/core/pref_names.h"
9 #include "components/password_manager/core/browser/password_store.h" 8 #include "components/password_manager/core/browser/password_store.h"
10 9
11 PasswordsCounter::PasswordsCounter(Profile* profile) 10 namespace browsing_data {
12 : BrowsingDataCounter(browsing_data::prefs::kDeletePasswords), 11
13 profile_(profile) {} 12 PasswordsCounter::PasswordsCounter(
13 scoped_refptr<password_manager::PasswordStore> store) : store_(store) {}
14 14
15 PasswordsCounter::~PasswordsCounter() { 15 PasswordsCounter::~PasswordsCounter() {
16 store_->RemoveObserver(this); 16 store_->RemoveObserver(this);
17 } 17 }
18 18
19 void PasswordsCounter::OnInitialized() { 19 void PasswordsCounter::OnInitialized() {
20 store_ = PasswordStoreFactory::GetForProfile(
21 profile_, ServiceAccessType::EXPLICIT_ACCESS);
22 DCHECK(store_); 20 DCHECK(store_);
23 store_->AddObserver(this); 21 store_->AddObserver(this);
24 } 22 }
25 23
24 const char* PasswordsCounter::GetPrefName() const {
25 return browsing_data::prefs::kDeletePasswords;
26 }
27
26 void PasswordsCounter::Count() { 28 void PasswordsCounter::Count() {
27 cancelable_task_tracker()->TryCancelAll(); 29 cancelable_task_tracker()->TryCancelAll();
28 // TODO(msramek): We don't actually need the logins themselves, just their 30 // TODO(msramek): We don't actually need the logins themselves, just their
29 // count. Consider implementing |PasswordStore::CountAutofillableLogins|. 31 // count. Consider implementing |PasswordStore::CountAutofillableLogins|.
30 // This custom request should also allow us to specify the time range, so that 32 // 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. 33 // we can use it to filter the login creation date in the database.
32 store_->GetAutofillableLogins(this); 34 store_->GetAutofillableLogins(this);
33 } 35 }
34 36
35 void PasswordsCounter::OnGetPasswordStoreResults( 37 void PasswordsCounter::OnGetPasswordStoreResults(
36 ScopedVector<autofill::PasswordForm> results) { 38 ScopedVector<autofill::PasswordForm> results) {
37 base::Time start = GetPeriodStart(); 39 base::Time start = GetPeriodStart();
38 ReportResult(std::count_if( 40 ReportResult(std::count_if(results.begin(), results.end(),
39 results.begin(), 41 [start](const autofill::PasswordForm* form) {
40 results.end(), 42 return form->date_created >= start;
41 [start](const autofill::PasswordForm* form) { 43 }));
42 return form->date_created >= start;
43 }));
44 } 44 }
45 45
46 void PasswordsCounter::OnLoginsChanged( 46 void PasswordsCounter::OnLoginsChanged(
47 const password_manager::PasswordStoreChangeList& changes) { 47 const password_manager::PasswordStoreChangeList& changes) {
48 Restart(); 48 Restart();
49 } 49 }
50
51 } // namespace browsing_data
OLDNEW
« no previous file with comments | « components/browsing_data/core/counters/passwords_counter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698