password_store_default.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 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 "components/password_manager/core/browser/password_store_default.h" 6 7#include <set> 8 9#include "base/logging.h" 10#include "base/prefs/pref_service.h" 11#include "base/stl_util.h" 12#include "components/password_manager/core/browser/password_store_change.h" 13 14using autofill::PasswordForm; 15 16PasswordStoreDefault::PasswordStoreDefault( 17 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 18 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 19 LoginDatabase* login_db) 20 : PasswordStore(main_thread_runner, db_thread_runner), login_db_(login_db) { 21 DCHECK(login_db); 22} 23 24PasswordStoreDefault::~PasswordStoreDefault() { 25} 26 27void PasswordStoreDefault::ReportMetricsImpl() { 28 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 29 login_db_->ReportMetrics(); 30} 31 32PasswordStoreChangeList PasswordStoreDefault::AddLoginImpl( 33 const PasswordForm& form) { 34 PasswordStoreChangeList changes; 35 if (login_db_->AddLogin(form)) 36 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); 37 return changes; 38} 39 40PasswordStoreChangeList PasswordStoreDefault::UpdateLoginImpl( 41 const PasswordForm& form) { 42 PasswordStoreChangeList changes; 43 if (login_db_->UpdateLogin(form, NULL)) 44 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); 45 return changes; 46} 47 48PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl( 49 const PasswordForm& form) { 50 PasswordStoreChangeList changes; 51 if (login_db_->RemoveLogin(form)) 52 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 53 return changes; 54} 55 56PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl( 57 const base::Time& delete_begin, const base::Time& delete_end) { 58 std::vector<PasswordForm*> forms; 59 PasswordStoreChangeList changes; 60 if (login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) { 61 if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { 62 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); 63 it != forms.end(); ++it) { 64 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, 65 **it)); 66 } 67 LogStatsForBulkDeletion(changes.size()); 68 } 69 } 70 STLDeleteElements(&forms); 71 return changes; 72} 73 74void PasswordStoreDefault::GetLoginsImpl( 75 const autofill::PasswordForm& form, 76 AuthorizationPromptPolicy prompt_policy, 77 const ConsumerCallbackRunner& callback_runner) { 78 std::vector<PasswordForm*> matched_forms; 79 login_db_->GetLogins(form, &matched_forms); 80 callback_runner.Run(matched_forms); 81} 82 83void PasswordStoreDefault::GetAutofillableLoginsImpl( 84 GetLoginsRequest* request) { 85 FillAutofillableLogins(request->result()); 86 ForwardLoginsResult(request); 87} 88 89void PasswordStoreDefault::GetBlacklistLoginsImpl( 90 GetLoginsRequest* request) { 91 FillBlacklistLogins(request->result()); 92 ForwardLoginsResult(request); 93} 94 95bool PasswordStoreDefault::FillAutofillableLogins( 96 std::vector<PasswordForm*>* forms) { 97 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 98 return login_db_->GetAutofillableLogins(forms); 99} 100 101bool PasswordStoreDefault::FillBlacklistLogins( 102 std::vector<PasswordForm*>* forms) { 103 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 104 return login_db_->GetBlacklistLogins(forms); 105} 106