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

Unified Diff: chrome/browser/password_manager/native_backend_gnome_x.cc

Issue 895653002: Serialize date_created in PasswordStoreX properly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/password_manager/native_backend_gnome_x_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/password_manager/native_backend_gnome_x.cc
diff --git a/chrome/browser/password_manager/native_backend_gnome_x.cc b/chrome/browser/password_manager/native_backend_gnome_x.cc
index 448fda630dbdcb8f73946afa3b67857f2c921679..bf98cd1e78130f2d7276b18f1b5fffecacf0eafd 100644
--- a/chrome/browser/password_manager/native_backend_gnome_x.cc
+++ b/chrome/browser/password_manager/native_backend_gnome_x.cc
@@ -31,6 +31,10 @@ using base::UTF8ToUTF16;
using base::UTF16ToUTF8;
using content::BrowserThread;
+namespace {
+const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max();
+}
+
#define GNOME_KEYRING_DEFINE_POINTER(name) \
typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name;
GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER)
@@ -131,7 +135,15 @@ scoped_ptr<PasswordForm> FormFromAttributes(GnomeKeyringAttributeList* attrs) {
bool date_ok = base::StringToInt64(string_attr_map["date_created"],
&date_created);
DCHECK(date_ok);
- form->date_created = base::Time::FromTimeT(date_created);
+ // In the past |date_created| was stored as time_t. Currently is stored as
+ // base::Time's internal value. We need to distinguish, which format the
+ // number in |date_created| was stored in. We use the fact that
+ // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an
+ // unlikely date back in 17th century, and anything above
+ // kMaxPossibleTimeTValue clearly must be in the internal value format.
+ form->date_created = date_created < kMaxPossibleTimeTValue
+ ? base::Time::FromTimeT(date_created)
+ : base::Time::FromInternalValue(date_created);
form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"];
form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]);
form->times_used = uint_attr_map["times_used"];
@@ -317,11 +329,11 @@ class GKRMethod : public GnomeKeyringLoader {
void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- time_t date_created = form.date_created.ToTimeT();
+ int64 date_created = form.date_created.ToInternalValue();
// If we are asked to save a password with 0 date, use the current time.
- // We don't want to actually save passwords as though on January 1, 1970.
+ // We don't want to actually save passwords as though on January 1, 1601.
if (!date_created)
- date_created = time(NULL);
+ date_created = base::Time::Now().ToInternalValue();
int64 date_synced = form.date_synced.ToInternalValue();
gnome_keyring_store_password(
&kGnomeSchema,
« no previous file with comments | « no previous file | chrome/browser/password_manager/native_backend_gnome_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698