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

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

Issue 1285223002: Add metrics for tracking LoginDatabase::Init failure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 COLUMN_DATE_SYNCED, 77 COLUMN_DATE_SYNCED,
78 COLUMN_DISPLAY_NAME, 78 COLUMN_DISPLAY_NAME,
79 COLUMN_AVATAR_URL, 79 COLUMN_AVATAR_URL,
80 COLUMN_FEDERATION_URL, 80 COLUMN_FEDERATION_URL,
81 COLUMN_SKIP_ZERO_CLICK, 81 COLUMN_SKIP_ZERO_CLICK,
82 COLUMN_GENERATION_UPLOAD_STATUS, 82 COLUMN_GENERATION_UPLOAD_STATUS,
83 }; 83 };
84 84
85 enum class HistogramSize { SMALL, LARGE }; 85 enum class HistogramSize { SMALL, LARGE };
86 86
87 enum DatabaseInitError {
Ilya Sherman 2015/08/13 00:34:18 Please document that this is used to back an UMA h
vasilii 2015/08/13 09:04:33 Done.
88 OPEN_FILE_ERROR,
89 START_TRANSACTION_ERROR,
90 META_TABLE_INIT_ERROR,
91 INCOMPATIBLE_VERSION,
92 INIT_LOGINS_ERROR,
93 INIT_STATS_ERROR,
94 MIGRATION_ERROR,
95 COMMIT_TRANSACTION_ERROR,
96
97 DATABASE_INIT_ERROR_COUNT,
98 };
99
87 void BindAddStatement(const PasswordForm& form, 100 void BindAddStatement(const PasswordForm& form,
88 const std::string& encrypted_password, 101 const std::string& encrypted_password,
89 sql::Statement* s) { 102 sql::Statement* s) {
90 s->BindString(COLUMN_ORIGIN_URL, form.origin.spec()); 103 s->BindString(COLUMN_ORIGIN_URL, form.origin.spec());
91 s->BindString(COLUMN_ACTION_URL, form.action.spec()); 104 s->BindString(COLUMN_ACTION_URL, form.action.spec());
92 s->BindString16(COLUMN_USERNAME_ELEMENT, form.username_element); 105 s->BindString16(COLUMN_USERNAME_ELEMENT, form.username_element);
93 s->BindString16(COLUMN_USERNAME_VALUE, form.username_value); 106 s->BindString16(COLUMN_USERNAME_VALUE, form.username_value);
94 s->BindString16(COLUMN_PASSWORD_ELEMENT, form.password_element); 107 s->BindString16(COLUMN_PASSWORD_ELEMENT, form.password_element);
95 s->BindBlob(COLUMN_PASSWORD_VALUE, encrypted_password.data(), 108 s->BindBlob(COLUMN_PASSWORD_VALUE, encrypted_password.data(),
96 static_cast<int>(encrypted_password.length())); 109 static_cast<int>(encrypted_password.length()));
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 303
291 bool LoginDatabase::Init() { 304 bool LoginDatabase::Init() {
292 // Set pragmas for a small, private database (based on WebDatabase). 305 // Set pragmas for a small, private database (based on WebDatabase).
293 db_.set_page_size(2048); 306 db_.set_page_size(2048);
294 db_.set_cache_size(32); 307 db_.set_cache_size(32);
295 db_.set_exclusive_locking(); 308 db_.set_exclusive_locking();
296 db_.set_restrict_to_user(); 309 db_.set_restrict_to_user();
297 db_.set_histogram_tag("Passwords"); 310 db_.set_histogram_tag("Passwords");
298 311
299 if (!db_.Open(db_path_)) { 312 if (!db_.Open(db_path_)) {
313 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
314 OPEN_FILE_ERROR, DATABASE_INIT_ERROR_COUNT);
Ilya Sherman 2015/08/13 00:34:18 Please create a wrapper function for emitting to t
vasilii 2015/08/13 09:04:33 Done.
300 LOG(ERROR) << "Unable to open the password store database."; 315 LOG(ERROR) << "Unable to open the password store database.";
301 return false; 316 return false;
302 } 317 }
303 318
304 sql::Transaction transaction(&db_); 319 sql::Transaction transaction(&db_);
305 if (!transaction.Begin()) { 320 if (!transaction.Begin()) {
321 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
322 START_TRANSACTION_ERROR,
323 DATABASE_INIT_ERROR_COUNT);
306 LOG(ERROR) << "Unable to start a transaction."; 324 LOG(ERROR) << "Unable to start a transaction.";
307 db_.Close(); 325 db_.Close();
308 return false; 326 return false;
309 } 327 }
310 328
311 // Check the database version. 329 // Check the database version.
312 if (!meta_table_.Init(&db_, kCurrentVersionNumber, 330 if (!meta_table_.Init(&db_, kCurrentVersionNumber,
313 kCompatibleVersionNumber)) { 331 kCompatibleVersionNumber)) {
332 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
333 META_TABLE_INIT_ERROR, DATABASE_INIT_ERROR_COUNT);
314 LOG(ERROR) << "Unable to create the meta table."; 334 LOG(ERROR) << "Unable to create the meta table.";
315 db_.Close(); 335 db_.Close();
316 return false; 336 return false;
317 } 337 }
318 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { 338 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
339 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
340 INCOMPATIBLE_VERSION, DATABASE_INIT_ERROR_COUNT);
319 LOG(ERROR) << "Password store database is too new, kCurrentVersionNumber=" 341 LOG(ERROR) << "Password store database is too new, kCurrentVersionNumber="
320 << kCurrentVersionNumber << ", GetCompatibleVersionNumber=" 342 << kCurrentVersionNumber << ", GetCompatibleVersionNumber="
321 << meta_table_.GetCompatibleVersionNumber(); 343 << meta_table_.GetCompatibleVersionNumber();
322 db_.Close(); 344 db_.Close();
323 return false; 345 return false;
324 } 346 }
325 347
326 // Initialize the tables. 348 // Initialize the tables.
327 if (!InitLoginsTable()) { 349 if (!InitLoginsTable()) {
350 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
351 INIT_LOGINS_ERROR, DATABASE_INIT_ERROR_COUNT);
328 LOG(ERROR) << "Unable to initialize the logins table."; 352 LOG(ERROR) << "Unable to initialize the logins table.";
329 db_.Close(); 353 db_.Close();
330 return false; 354 return false;
331 } 355 }
332 356
333 if (!stats_table_.Init(&db_)) { 357 if (!stats_table_.Init(&db_)) {
358 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
359 INIT_STATS_ERROR, DATABASE_INIT_ERROR_COUNT);
334 LOG(ERROR) << "Unable to initialize the stats table."; 360 LOG(ERROR) << "Unable to initialize the stats table.";
335 db_.Close(); 361 db_.Close();
336 return false; 362 return false;
337 } 363 }
338 364
339 // If the file on disk is an older database version, bring it up to date. 365 // If the file on disk is an older database version, bring it up to date.
340 if (!MigrateOldVersionsAsNeeded()) { 366 if (!MigrateOldVersionsAsNeeded()) {
367 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
368 MIGRATION_ERROR, DATABASE_INIT_ERROR_COUNT);
369 UMA_HISTOGRAM_CUSTOM_COUNTS("PasswordManager.LoginDatabaseFailedVersion",
370 meta_table_.GetVersionNumber(), 1, 30, 30);
Ilya Sherman 2015/08/13 00:34:18 nit: Would a sparse histogram be appropriate here?
vasilii 2015/08/13 09:04:33 Done.
341 LOG(ERROR) << "Unable to migrate database from " 371 LOG(ERROR) << "Unable to migrate database from "
342 << meta_table_.GetVersionNumber() << " to " 372 << meta_table_.GetVersionNumber() << " to "
343 << kCurrentVersionNumber; 373 << kCurrentVersionNumber;
344 db_.Close(); 374 db_.Close();
345 return false; 375 return false;
346 } 376 }
347 377
348 if (!transaction.Commit()) { 378 if (!transaction.Commit()) {
379 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LoginDatabaseInit",
380 COMMIT_TRANSACTION_ERROR,
381 DATABASE_INIT_ERROR_COUNT);
349 LOG(ERROR) << "Unable to commit a transaction."; 382 LOG(ERROR) << "Unable to commit a transaction.";
350 db_.Close(); 383 db_.Close();
351 return false; 384 return false;
352 } 385 }
353 386
354 return true; 387 return true;
355 } 388 }
356 389
357 bool LoginDatabase::MigrateOldVersionsAsNeeded() { 390 bool LoginDatabase::MigrateOldVersionsAsNeeded() {
358 switch (meta_table_.GetVersionNumber()) { 391 switch (meta_table_.GetVersionNumber()) {
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 1147 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
1115 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); 1148 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT);
1116 } 1149 }
1117 1150
1118 if (!statement->Succeeded()) 1151 if (!statement->Succeeded())
1119 return false; 1152 return false;
1120 return true; 1153 return true;
1121 } 1154 }
1122 1155
1123 } // namespace password_manager 1156 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698