| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/password_manager/core/browser/password_store_default.h" | 5 #include "components/password_manager/core/browser/password_store_default.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "components/password_manager/core/browser/password_store_change.h" | 12 #include "components/password_manager/core/browser/password_store_change.h" |
| 13 | 13 |
| 14 using autofill::PasswordForm; | 14 using autofill::PasswordForm; |
| 15 | 15 |
| 16 namespace password_manager { | 16 namespace password_manager { |
| 17 | 17 |
| 18 PasswordStoreDefault::PasswordStoreDefault( | 18 PasswordStoreDefault::PasswordStoreDefault( |
| 19 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 19 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
| 21 scoped_ptr<LoginDatabase> login_db) | 21 scoped_ptr<LoginDatabase> login_db) |
| 22 : PasswordStore(main_thread_runner, db_thread_runner), | 22 : PasswordStore(main_thread_runner, db_thread_runner), |
| 23 login_db_(login_db.Pass()) { | 23 login_db_(login_db.Pass()) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 PasswordStoreDefault::~PasswordStoreDefault() { | 26 PasswordStoreDefault::~PasswordStoreDefault() { |
| 27 if (!GetBackgroundTaskRunner()->BelongsToCurrentThread()) | |
| 28 GetBackgroundTaskRunner()->DeleteSoon(FROM_HERE, login_db_.release()); | |
| 29 } | 27 } |
| 30 | 28 |
| 31 bool PasswordStoreDefault::Init( | 29 bool PasswordStoreDefault::Init( |
| 32 const syncer::SyncableService::StartSyncFlare& flare) { | 30 const syncer::SyncableService::StartSyncFlare& flare) { |
| 33 ScheduleTask(base::Bind(&PasswordStoreDefault::InitOnDBThread, this)); | 31 ScheduleTask(base::Bind(&PasswordStoreDefault::InitOnDBThread, this)); |
| 34 return PasswordStore::Init(flare); | 32 return PasswordStore::Init(flare); |
| 35 } | 33 } |
| 36 | 34 |
| 35 void PasswordStoreDefault::Shutdown() { |
| 36 PasswordStore::Shutdown(); |
| 37 ScheduleTask(base::Bind(&PasswordStoreDefault::ResetLoginDB, this)); |
| 38 } |
| 39 |
| 37 void PasswordStoreDefault::InitOnDBThread() { | 40 void PasswordStoreDefault::InitOnDBThread() { |
| 38 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | 41 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
| 39 DCHECK(login_db_); | 42 DCHECK(login_db_); |
| 40 if (!login_db_->Init()) { | 43 if (!login_db_->Init()) { |
| 41 login_db_.reset(); | 44 login_db_.reset(); |
| 42 LOG(ERROR) << "Could not create/open login database."; | 45 LOG(ERROR) << "Could not create/open login database."; |
| 43 } | 46 } |
| 44 } | 47 } |
| 45 | 48 |
| 46 void PasswordStoreDefault::ReportMetricsImpl( | 49 void PasswordStoreDefault::ReportMetricsImpl( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 login_db_->stats_table().RemoveRow(origin_domain); | 165 login_db_->stats_table().RemoveRow(origin_domain); |
| 163 } | 166 } |
| 164 | 167 |
| 165 scoped_ptr<InteractionsStats> PasswordStoreDefault::GetSiteStatsImpl( | 168 scoped_ptr<InteractionsStats> PasswordStoreDefault::GetSiteStatsImpl( |
| 166 const GURL& origin_domain) { | 169 const GURL& origin_domain) { |
| 167 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | 170 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
| 168 return login_db_ ? login_db_->stats_table().GetRow(origin_domain) | 171 return login_db_ ? login_db_->stats_table().GetRow(origin_domain) |
| 169 : scoped_ptr<InteractionsStats>(); | 172 : scoped_ptr<InteractionsStats>(); |
| 170 } | 173 } |
| 171 | 174 |
| 175 void PasswordStoreDefault::ResetLoginDB() { |
| 176 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
| 177 login_db_.reset(); |
| 178 } |
| 179 |
| 172 } // namespace password_manager | 180 } // namespace password_manager |
| OLD | NEW |