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

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

Issue 1083293004: Implement the statistics table for the passwords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address the comments Created 5 years, 8 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 11 matching lines...) Expand all
22 #include "google_apis/gaia/gaia_auth_util.h" 22 #include "google_apis/gaia/gaia_auth_util.h"
23 #include "google_apis/gaia/gaia_urls.h" 23 #include "google_apis/gaia/gaia_urls.h"
24 #include "sql/connection.h" 24 #include "sql/connection.h"
25 #include "sql/statement.h" 25 #include "sql/statement.h"
26 #include "sql/transaction.h" 26 #include "sql/transaction.h"
27 27
28 using autofill::PasswordForm; 28 using autofill::PasswordForm;
29 29
30 namespace password_manager { 30 namespace password_manager {
31 31
32 const int kCurrentVersionNumber = 12; 32 const int kCurrentVersionNumber = 13;
33 static const int kCompatibleVersionNumber = 1; 33 static const int kCompatibleVersionNumber = 1;
34 34
35 Pickle SerializeVector(const std::vector<base::string16>& vec) { 35 Pickle SerializeVector(const std::vector<base::string16>& vec) {
36 Pickle p; 36 Pickle p;
37 for (size_t i = 0; i < vec.size(); ++i) { 37 for (size_t i = 0; i < vec.size(); ++i) {
38 p.WriteString16(vec[i]); 38 p.WriteString16(vec[i]);
39 } 39 }
40 return p; 40 return p;
41 } 41 }
42 42
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return false; 226 return false;
227 } 227 }
228 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { 228 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
229 LOG(WARNING) << "Password store database is too new."; 229 LOG(WARNING) << "Password store database is too new.";
230 db_.Close(); 230 db_.Close();
231 return false; 231 return false;
232 } 232 }
233 233
234 // Initialize the tables. 234 // Initialize the tables.
235 if (!InitLoginsTable()) { 235 if (!InitLoginsTable()) {
236 LOG(WARNING) << "Unable to initialize the password store database."; 236 LOG(WARNING) << "Unable to initialize the logins table.";
237 db_.Close(); 237 db_.Close();
238 return false; 238 return false;
239 } 239 }
240
241 if (!stats_table_.Init(&db_)) {
242 LOG(WARNING) << "Unable to initialize the stats table.";
243 db_.Close();
244 return false;
245 }
240 246
241 // If the file on disk is an older database version, bring it up to date. 247 // If the file on disk is an older database version, bring it up to date.
242 if (!MigrateOldVersionsAsNeeded()) { 248 if (!MigrateOldVersionsAsNeeded()) {
243 LOG(WARNING) << "Unable to migrate database"; 249 LOG(WARNING) << "Unable to migrate database";
244 db_.Close(); 250 db_.Close();
245 return false; 251 return false;
246 } 252 }
247 253
248 if (!transaction.Commit()) { 254 if (!transaction.Commit()) {
249 db_.Close(); 255 db_.Close();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 !CreateIndexOnSignonRealm(&db_, "logins")) 373 !CreateIndexOnSignonRealm(&db_, "logins"))
368 return false; 374 return false;
369 meta_table_.SetVersionNumber(11); 375 meta_table_.SetVersionNumber(11);
370 } 376 }
371 case 11: 377 case 11:
372 if (!db_.Execute( 378 if (!db_.Execute(
373 "ALTER TABLE logins ADD COLUMN " 379 "ALTER TABLE logins ADD COLUMN "
374 "generation_upload_status INTEGER")) 380 "generation_upload_status INTEGER"))
375 return false; 381 return false;
376 meta_table_.SetVersionNumber(12); 382 meta_table_.SetVersionNumber(12);
383 case 12:
384 // The stats table was added. Nothing to do really.
385 meta_table_.SetVersionNumber(13);
377 case kCurrentVersionNumber: 386 case kCurrentVersionNumber:
378 // Already up to date 387 // Already up to date
379 return true; 388 return true;
380 default: 389 default:
381 NOTREACHED(); 390 NOTREACHED();
382 return false; 391 return false;
383 } 392 }
384 } 393 }
385 394
386 bool LoginDatabase::InitLoginsTable() { 395 bool LoginDatabase::InitLoginsTable() {
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 954 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
946 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); 955 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT);
947 } 956 }
948 957
949 if (!statement->Succeeded()) 958 if (!statement->Succeeded())
950 return false; 959 return false;
951 return true; 960 return true;
952 } 961 }
953 962
954 } // namespace password_manager 963 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698