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

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

Issue 1238283002: Collect SQL statistics on passwords. Print more information on error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 LoginDatabase::~LoginDatabase() { 206 LoginDatabase::~LoginDatabase() {
207 } 207 }
208 208
209 bool LoginDatabase::Init() { 209 bool LoginDatabase::Init() {
210 // Set pragmas for a small, private database (based on WebDatabase). 210 // Set pragmas for a small, private database (based on WebDatabase).
211 db_.set_page_size(2048); 211 db_.set_page_size(2048);
212 db_.set_cache_size(32); 212 db_.set_cache_size(32);
213 db_.set_exclusive_locking(); 213 db_.set_exclusive_locking();
214 db_.set_restrict_to_user(); 214 db_.set_restrict_to_user();
215 db_.set_histogram_tag("Passwords");
215 216
216 if (!db_.Open(db_path_)) { 217 if (!db_.Open(db_path_)) {
217 LOG(WARNING) << "Unable to open the password store database."; 218 LOG(ERROR) << "Unable to open the password store database.";
218 return false; 219 return false;
219 } 220 }
220 221
221 sql::Transaction transaction(&db_); 222 sql::Transaction transaction(&db_);
222 transaction.Begin(); 223 if (!transaction.Begin()) {
224 LOG(ERROR) << "Unable to start a transaction.";
225 db_.Close();
226 return false;
227 }
223 228
224 // Check the database version. 229 // Check the database version.
225 if (!meta_table_.Init(&db_, kCurrentVersionNumber, 230 if (!meta_table_.Init(&db_, kCurrentVersionNumber,
226 kCompatibleVersionNumber)) { 231 kCompatibleVersionNumber)) {
232 LOG(ERROR) << "Unable to create the meta table.";
227 db_.Close(); 233 db_.Close();
228 return false; 234 return false;
229 } 235 }
230 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { 236 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
231 LOG(WARNING) << "Password store database is too new."; 237 LOG(ERROR) << "Password store database is too new, kCurrentVersionNumber="
238 << kCurrentVersionNumber << ", GetCompatibleVersionNumber="
239 << meta_table_.GetCompatibleVersionNumber();
232 db_.Close(); 240 db_.Close();
233 return false; 241 return false;
234 } 242 }
235 243
236 // Initialize the tables. 244 // Initialize the tables.
237 if (!InitLoginsTable()) { 245 if (!InitLoginsTable()) {
238 LOG(WARNING) << "Unable to initialize the logins table."; 246 LOG(ERROR) << "Unable to initialize the logins table.";
239 db_.Close(); 247 db_.Close();
240 return false; 248 return false;
241 } 249 }
242 250
243 if (!stats_table_.Init(&db_)) { 251 if (!stats_table_.Init(&db_)) {
244 LOG(WARNING) << "Unable to initialize the stats table."; 252 LOG(ERROR) << "Unable to initialize the stats table.";
245 db_.Close(); 253 db_.Close();
246 return false; 254 return false;
247 } 255 }
248 256
249 // If the file on disk is an older database version, bring it up to date. 257 // If the file on disk is an older database version, bring it up to date.
250 if (!MigrateOldVersionsAsNeeded()) { 258 if (!MigrateOldVersionsAsNeeded()) {
251 LOG(WARNING) << "Unable to migrate database"; 259 LOG(ERROR) << "Unable to migrate database from "
260 << meta_table_.GetVersionNumber() << " to "
261 << kCurrentVersionNumber;
252 db_.Close(); 262 db_.Close();
253 return false; 263 return false;
254 } 264 }
255 265
256 if (!transaction.Commit()) { 266 if (!transaction.Commit()) {
267 LOG(ERROR) << "Unable to commit a transaction.";
257 db_.Close(); 268 db_.Close();
258 return false; 269 return false;
259 } 270 }
260 271
261 return true; 272 return true;
262 } 273 }
263 274
264 bool LoginDatabase::MigrateOldVersionsAsNeeded() { 275 bool LoginDatabase::MigrateOldVersionsAsNeeded() {
265 switch (meta_table_.GetVersionNumber()) { 276 switch (meta_table_.GetVersionNumber()) {
266 case 1: 277 case 1:
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 985 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
975 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); 986 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT);
976 } 987 }
977 988
978 if (!statement->Succeeded()) 989 if (!statement->Succeeded())
979 return false; 990 return false;
980 return true; 991 return true;
981 } 992 }
982 993
983 } // namespace password_manager 994 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698