password_store.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/password_manager/core/browser/password_store.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/bind.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_loop.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_loop_proxy.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/histogram.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/stl_util.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/common/password_form.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/password_manager/core/browser/password_store_consumer.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using autofill::PasswordForm; 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using std::vector; 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Calls |consumer| back with the request result, if |consumer| is still alive. 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Takes ownership of the elements in |result|, passing ownership to |consumer| 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// if it is still alive. 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MaybeCallConsumerCallback(base::WeakPtr<PasswordStoreConsumer> consumer, 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<vector<PasswordForm*> > result) { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (consumer.get()) 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) consumer->OnGetPasswordStoreResults(*result); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STLDeleteElements(result.get()); 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PasswordStore::GetLoginsRequest::GetLoginsRequest( 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PasswordStoreConsumer* consumer) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : consumer_weak_(consumer->GetWeakPtr()), 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result_(new vector<PasswordForm*>()) { 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) origin_loop_ = base::MessageLoopProxy::current(); 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PasswordStore::GetLoginsRequest::~GetLoginsRequest() { 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::GetLoginsRequest::ApplyIgnoreLoginsCutoff() { 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!ignore_logins_cutoff_.is_null()) { 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Count down rather than up since we may be deleting elements. 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that in principle it could be more efficient to copy the whole array 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // since that's worst-case linear time, but we expect that elements will be 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // deleted rarely and lists will be small, so this avoids the copies. 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = result_->size(); i > 0; --i) { 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if ((*result_)[i - 1]->date_created < ignore_logins_cutoff_) { 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete (*result_)[i - 1]; 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result_->erase(result_->begin() + (i - 1)); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::GetLoginsRequest::ForwardResult() { 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) origin_loop_->PostTask(FROM_HERE, 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&MaybeCallConsumerCallback, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) consumer_weak_, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Passed(result_.Pass()))); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PasswordStore::PasswordStore( 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : main_thread_runner_(main_thread_runner), 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) db_thread_runner_(db_thread_runner), 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_(new ObserverListThreadSafe<Observer>()), 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shutdown_called_(false) {} 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool PasswordStore::Init() { 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ReportMetrics(); 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::AddLogin(const PasswordForm& form) { 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask( 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::WrapModificationTask, this, 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::AddLoginImpl, this, form))); 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::UpdateLogin(const PasswordForm& form) { 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask( 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::WrapModificationTask, this, 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::UpdateLoginImpl, this, form))); 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::RemoveLogin(const PasswordForm& form) { 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask( 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::WrapModificationTask, this, 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::RemoveLoginImpl, this, form))); 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::RemoveLoginsCreatedBetween(const base::Time& delete_begin, 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Time& delete_end) { 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask( 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::WrapModificationTask, this, 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::RemoveLoginsCreatedBetweenImpl, 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, delete_begin, delete_end))); 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::GetLogins( 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const PasswordForm& form, 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AuthorizationPromptPolicy prompt_policy, 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PasswordStoreConsumer* consumer) { 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Per http://crbug.com/121738, we deliberately ignore saved logins for 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // http*://www.google.com/ that were stored prior to 2012. (Google now uses 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // https://accounts.google.com/ for all login forms, so these should be 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // unused.) We don't delete them just yet, and they'll still be visible in the 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // password manager, but we won't use them to autofill any forms. This is a 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // security feature to help minimize damage that can be done by XSS attacks. 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(mdm): actually delete them at some point, say M24 or so. 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Time ignore_logins_cutoff; // the null time 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (form.scheme == PasswordForm::SCHEME_HTML && 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (form.signon_realm == "http://www.google.com" || 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) form.signon_realm == "http://www.google.com/" || 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) form.signon_realm == "https://www.google.com" || 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) form.signon_realm == "https://www.google.com/")) { 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const base::Time::Exploded exploded_cutoff = 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 2012, 1, 0, 1, 0, 0, 0, 0 }; // 00:00 Jan 1 2012 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ignore_logins_cutoff = base::Time::FromUTCExploded(exploded_cutoff); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetLoginsRequest* request = new GetLoginsRequest(consumer); 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request->set_ignore_logins_cutoff(ignore_logins_cutoff); 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConsumerCallbackRunner callback_runner = 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&PasswordStore::CopyAndForwardLoginsResult, 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, base::Owned(request)); 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask(base::Bind(&PasswordStore::GetLoginsImpl, 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, form, prompt_policy, callback_runner)); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::GetAutofillableLogins(PasswordStoreConsumer* consumer) { 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Schedule(&PasswordStore::GetAutofillableLoginsImpl, consumer); 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Schedule(&PasswordStore::GetBlacklistLoginsImpl, consumer); 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::ReportMetrics() { 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScheduleTask(base::Bind(&PasswordStore::ReportMetricsImpl, this)); 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::AddObserver(Observer* observer) { 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_->AddObserver(observer); 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::RemoveObserver(Observer* observer) { 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_->RemoveObserver(observer); 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::Shutdown() { shutdown_called_ = true; } 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PasswordStore::~PasswordStore() { DCHECK(shutdown_called_); } 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool PasswordStore::ScheduleTask(const base::Closure& task) { 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<base::SingleThreadTaskRunner> task_runner( 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetBackgroundTaskRunner()); 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (task_runner.get()) 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return task_runner->PostTask(FROM_HERE, task); 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)scoped_refptr<base::SingleThreadTaskRunner> 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PasswordStore::GetBackgroundTaskRunner() { 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return db_thread_runner_; 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) { 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request->ApplyIgnoreLoginsCutoff(); 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request->ForwardResult(); 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::CopyAndForwardLoginsResult( 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PasswordStore::GetLoginsRequest* request, 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const vector<PasswordForm*>& matched_forms) { 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Copy the contents of |matched_forms| into the request. The request takes 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // ownership of the PasswordForm elements. 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *(request->result()) = matched_forms; 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ForwardLoginsResult(request); 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::LogStatsForBulkDeletion(int num_deletions) { 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedByBulkDelete", 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) num_deletions); 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)template<typename BackendFunc> 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::Schedule( 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BackendFunc func, 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PasswordStoreConsumer* consumer) { 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetLoginsRequest* request = new GetLoginsRequest(consumer); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) consumer->cancelable_task_tracker()->PostTask( 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetBackgroundTaskRunner(), 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(func, this, base::Owned(request))); 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::WrapModificationTask(ModificationTask task) { 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PasswordStoreChangeList changes = task.Run(); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NotifyLoginsChanged(changes); 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PasswordStore::NotifyLoginsChanged( 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const PasswordStoreChangeList& changes) { 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!changes.empty()) 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_->Notify(&Observer::OnLoginsChanged, changes); 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 214