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

Side by Side Diff: chrome/browser/browsing_data/passwords_counter.cc

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed round 2 of 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/browsing_data/passwords_counter.h"
6 #include "chrome/browser/password_manager/password_store_factory.h" 6 #include "chrome/browser/password_manager/password_store_factory.h"
7 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
8 #include "components/password_manager/core/browser/password_store.h" 9 #include "components/password_manager/core/browser/password_store.h"
9 10
10 PasswordsCounter::PasswordsCounter() : pref_name_(prefs::kDeletePasswords) {} 11 PasswordsCounter::PasswordsCounter(Profile* profile)
12 : BrowsingDataCounter(prefs::kDeletePasswords), profile_(profile) {}
11 13
12 PasswordsCounter::~PasswordsCounter() { 14 PasswordsCounter::~PasswordsCounter() {
13 if (store_) 15 if (store_)
14 store_->RemoveObserver(this); 16 store_->RemoveObserver(this);
15 } 17 }
16 18
17 void PasswordsCounter::OnInitialized() { 19 void PasswordsCounter::OnInitialized() {
18 store_ = PasswordStoreFactory::GetForProfile( 20 store_ = PasswordStoreFactory::GetForProfile(
Bernhard Bauer 2016/06/27 17:09:45 Also preexisting code, but: PasswordStoreFactory::
ioanap 2016/06/28 14:12:35 Done.
19 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS).get(); 21 profile_, ServiceAccessType::EXPLICIT_ACCESS)
22 .get();
20 if (store_) 23 if (store_)
21 store_->AddObserver(this); 24 store_->AddObserver(this);
22 else 25 else
23 LOG(ERROR) << "No password store! Cannot count passwords."; 26 LOG(ERROR) << "No password store! Cannot count passwords.";
Bernhard Bauer 2016/06/27 17:09:45 This is also a bit strange... Under which circumst
ioanap 2016/06/28 14:12:36 Added the DCHECK since it looks like it can't happ
24 } 27 }
25 28
26 const std::string& PasswordsCounter::GetPrefName() const {
27 return pref_name_;
28 }
29
30 void PasswordsCounter::Count() { 29 void PasswordsCounter::Count() {
31 if (!store_) { 30 if (!store_) {
32 ReportResult(0); 31 ReportResult(0);
33 return; 32 return;
34 } 33 }
35 34
36 cancelable_task_tracker()->TryCancelAll(); 35 cancelable_task_tracker()->TryCancelAll();
37 // TODO(msramek): We don't actually need the logins themselves, just their 36 // TODO(msramek): We don't actually need the logins themselves, just their
38 // count. Consider implementing |PasswordStore::CountAutofillableLogins|. 37 // count. Consider implementing |PasswordStore::CountAutofillableLogins|.
39 // This custom request should also allow us to specify the time range, so that 38 // This custom request should also allow us to specify the time range, so that
40 // we can use it to filter the login creation date in the database. 39 // we can use it to filter the login creation date in the database.
41 store_->GetAutofillableLogins(this); 40 store_->GetAutofillableLogins(this);
42 } 41 }
43 42
44 void PasswordsCounter::OnGetPasswordStoreResults( 43 void PasswordsCounter::OnGetPasswordStoreResults(
45 ScopedVector<autofill::PasswordForm> results) { 44 ScopedVector<autofill::PasswordForm> results) {
46 base::Time start = GetPeriodStart(); 45 base::Time start = GetPeriodStart();
47 ReportResult(std::count_if( 46 ReportResult(std::count_if(
48 results.begin(), 47 results.begin(),
49 results.end(), 48 results.end(),
50 [start](const autofill::PasswordForm* form) { 49 [start](const autofill::PasswordForm* form) {
51 return form->date_created >= start; 50 return form->date_created >= start;
52 })); 51 }));
53 } 52 }
54 53
55 void PasswordsCounter::OnLoginsChanged( 54 void PasswordsCounter::OnLoginsChanged(
56 const password_manager::PasswordStoreChangeList& changes) { 55 const password_manager::PasswordStoreChangeList& changes) {
57 Restart(); 56 Restart();
58 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698