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

Side by Side Diff: components/password_manager/core/browser/login_database.cc

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac namespace fixes. Created 5 years, 11 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 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/login_database.h" 5 #include "components/password_manager/core/browser/login_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 148
149 void LogAccountStat(const std::string& name, int sample) { 149 void LogAccountStat(const std::string& name, int sample) {
150 LogDynamicUMAStat(name, sample, 0, 32, 6); 150 LogDynamicUMAStat(name, sample, 0, 32, 6);
151 } 151 }
152 152
153 void LogTimesUsedStat(const std::string& name, int sample) { 153 void LogTimesUsedStat(const std::string& name, int sample) {
154 LogDynamicUMAStat(name, sample, 0, 100, 10); 154 LogDynamicUMAStat(name, sample, 0, 100, 10);
155 } 155 }
156 156
157 // When set, LoginDatabase::Init() on any instance will artificially fail.
158 bool g_simulate_init_failure_for_testing = false;
159
157 } // namespace 160 } // namespace
158 161
159 LoginDatabase::LoginDatabase() { 162 LoginDatabase::LoginDatabase() {
160 } 163 }
161 164
162 LoginDatabase::~LoginDatabase() { 165 LoginDatabase::~LoginDatabase() {
163 } 166 }
164 167
165 bool LoginDatabase::Init(const base::FilePath& db_path) { 168 bool LoginDatabase::Init(const base::FilePath& db_path) {
169 if (g_simulate_init_failure_for_testing)
170 return false;
171
166 // Set pragmas for a small, private database (based on WebDatabase). 172 // Set pragmas for a small, private database (based on WebDatabase).
167 db_.set_page_size(2048); 173 db_.set_page_size(2048);
168 db_.set_cache_size(32); 174 db_.set_cache_size(32);
169 db_.set_exclusive_locking(); 175 db_.set_exclusive_locking();
170 db_.set_restrict_to_user(); 176 db_.set_restrict_to_user();
171 177
172 { 178 {
173 // TODO(vadimt): Remove ScopedTracker below once crbug.com/138903 is fixed. 179 // TODO(vadimt): Remove ScopedTracker below once crbug.com/138903 is fixed.
174 tracked_objects::ScopedTracker tracking_profile( 180 tracked_objects::ScopedTracker tracking_profile(
175 FROM_HERE_WITH_EXPLICIT_FUNCTION("138903 LoginDatabase::Init db init")); 181 FROM_HERE_WITH_EXPLICIT_FUNCTION("138903 LoginDatabase::Init db init"));
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 syncing_account_saved = true; 439 syncing_account_saved = true;
434 break; 440 break;
435 } 441 }
436 } 442 }
437 } 443 }
438 UMA_HISTOGRAM_ENUMERATION("PasswordManager.SyncingAccountState", 444 UMA_HISTOGRAM_ENUMERATION("PasswordManager.SyncingAccountState",
439 2 * sync_username.empty() + syncing_account_saved, 445 2 * sync_username.empty() + syncing_account_saved,
440 4); 446 4);
441 } 447 }
442 448
449 // static
450 void LoginDatabase::set_simulate_init_failure_for_testing(bool fail) {
451 g_simulate_init_failure_for_testing = fail;
452 }
453
443 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { 454 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) {
444 PasswordStoreChangeList list; 455 PasswordStoreChangeList list;
445 if (!DoesMatchConstraints(form)) 456 if (!DoesMatchConstraints(form))
446 return list; 457 return list;
447 std::string encrypted_password; 458 std::string encrypted_password;
448 if (EncryptedString(form.password_value, &encrypted_password) != 459 if (EncryptedString(form.password_value, &encrypted_password) !=
449 ENCRYPTION_RESULT_SUCCESS) 460 ENCRYPTION_RESULT_SUCCESS)
450 return list; 461 return list;
451 462
452 // You *must* change LoginTableColumns if this query changes. 463 // You *must* change LoginTableColumns if this query changes.
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 868
858 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { 869 bool LoginDatabase::DeleteAndRecreateDatabaseFile() {
859 DCHECK(db_.is_open()); 870 DCHECK(db_.is_open());
860 meta_table_.Reset(); 871 meta_table_.Reset();
861 db_.Close(); 872 db_.Close();
862 sql::Connection::Delete(db_path_); 873 sql::Connection::Delete(db_path_);
863 return Init(db_path_); 874 return Init(db_path_);
864 } 875 }
865 876
866 } // namespace password_manager 877 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698