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

Unified Diff: components/password_manager/core/browser/login_database.cc

Issue 702893005: Use higher precision to store the login database's date_created field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clear statement before closing db in unittest. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/login_database.cc
diff --git a/components/password_manager/core/browser/login_database.cc b/components/password_manager/core/browser/login_database.cc
index e1cf8a2f928901493ad163d1cf42c37bad08f5dd..f2ab2e4bad5719c6d1a8ebb1f20fff4bb8511762 100644
--- a/components/password_manager/core/browser/login_database.cc
+++ b/components/password_manager/core/browser/login_database.cc
@@ -27,7 +27,7 @@ using autofill::PasswordForm;
namespace password_manager {
-static const int kCurrentVersionNumber = 8;
+static const int kCurrentVersionNumber = 9;
static const int kCompatibleVersionNumber = 1;
Pickle SerializeVector(const std::vector<base::string16>& vec) {
@@ -91,7 +91,7 @@ void BindAddStatement(const PasswordForm& form,
s->BindString(COLUMN_SIGNON_REALM, form.signon_realm);
s->BindInt(COLUMN_SSL_VALID, form.ssl_valid);
s->BindInt(COLUMN_PREFERRED, form.preferred);
- s->BindInt64(COLUMN_DATE_CREATED, form.date_created.ToTimeT());
+ s->BindInt64(COLUMN_DATE_CREATED, form.date_created.ToInternalValue());
s->BindInt(COLUMN_BLACKLISTED_BY_USER, form.blacklisted_by_user);
s->BindInt(COLUMN_SCHEME, form.scheme);
s->BindInt(COLUMN_PASSWORD_TYPE, form.type);
@@ -257,6 +257,19 @@ bool LoginDatabase::MigrateOldVersionsAsNeeded() {
// Fall through.
// TODO(gcasto): Remove use_additional_auth by copying table.
// https://www.sqlite.org/lang_altertable.html
+ case 8: {
+ sql::Statement s;
+ s.Assign(db_.GetCachedStatement(SQL_FROM_HERE,
+ "UPDATE logins SET "
+ "date_created = "
+ "(date_created * ?) + ?"));
+ s.BindInt64(0, base::Time::kMicrosecondsPerSecond);
+ s.BindInt64(1, base::Time::kTimeTToMicrosecondsOffset);
+ if (!s.Run())
+ return false;
+ meta_table_.SetVersionNumber(9);
+ // Fall through.
+ }
case kCurrentVersionNumber:
// Already up to date
return true;
@@ -476,7 +489,7 @@ PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) {
s.BindInt(5, form.times_used);
s.BindString16(6, form.submit_element);
s.BindInt64(7, form.date_synced.ToInternalValue());
- s.BindInt64(8, form.date_created.ToTimeT());
+ s.BindInt64(8, form.date_created.ToInternalValue());
s.BindInt(9, form.blacklisted_by_user);
s.BindInt(10, form.scheme);
s.BindInt(11, form.type);
@@ -527,9 +540,9 @@ bool LoginDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin,
sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
"DELETE FROM logins WHERE "
"date_created >= ? AND date_created < ?"));
- s.BindInt64(0, delete_begin.ToTimeT());
+ s.BindInt64(0, delete_begin.ToInternalValue());
s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64>::max()
- : delete_end.ToTimeT());
+ : delete_end.ToInternalValue());
return s.Run();
}
@@ -571,8 +584,8 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
form->signon_realm = tmp;
form->ssl_valid = (s.ColumnInt(COLUMN_SSL_VALID) > 0);
form->preferred = (s.ColumnInt(COLUMN_PREFERRED) > 0);
- form->date_created = base::Time::FromTimeT(
- s.ColumnInt64(COLUMN_DATE_CREATED));
+ form->date_created =
+ base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED));
form->blacklisted_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0);
int scheme_int = s.ColumnInt(COLUMN_SCHEME);
DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER));
@@ -711,9 +724,9 @@ bool LoginDatabase::GetLoginsCreatedBetween(
"federation_url, is_zero_click FROM logins "
"WHERE date_created >= ? AND date_created < ?"
"ORDER BY origin_url"));
- s.BindInt64(0, begin.ToTimeT());
+ s.BindInt64(0, begin.ToInternalValue());
s.BindInt64(1, end.is_null() ? std::numeric_limits<int64>::max()
- : end.ToTimeT());
+ : end.ToInternalValue());
while (s.Step()) {
scoped_ptr<PasswordForm> new_form(new PasswordForm());
« no previous file with comments | « components/components_tests.gyp ('k') | components/password_manager/core/browser/login_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698