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

Side by Side Diff: chrome/browser/password_manager/native_backend_libsecret.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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "chrome/browser/password_manager/native_backend_libsecret.h" 5 #include "chrome/browser/password_manager/native_backend_libsecret.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <list> 8 #include <list>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 17
18 using autofill::PasswordForm; 18 using autofill::PasswordForm;
19 using base::UTF8ToUTF16; 19 using base::UTF8ToUTF16;
20 using base::UTF16ToUTF8; 20 using base::UTF16ToUTF8;
21 21
22 namespace { 22 namespace {
23 const char kEmptyString[] = ""; 23 const char kEmptyString[] = "";
24 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max();
24 } 25 }
25 26
26 typeof(&::secret_password_store_sync) 27 typeof(&::secret_password_store_sync)
27 LibsecretLoader::secret_password_store_sync; 28 LibsecretLoader::secret_password_store_sync;
28 typeof(&::secret_service_search_sync) 29 typeof(&::secret_service_search_sync)
29 LibsecretLoader::secret_service_search_sync; 30 LibsecretLoader::secret_service_search_sync;
30 typeof(&::secret_password_clear_sync) 31 typeof(&::secret_password_clear_sync)
31 LibsecretLoader::secret_password_clear_sync; 32 LibsecretLoader::secret_password_clear_sync;
32 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; 33 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret;
33 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; 34 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 UTF8ToUTF16(GetStringFromAttributes(attrs, "password_element")); 158 UTF8ToUTF16(GetStringFromAttributes(attrs, "password_element"));
158 form->submit_element = 159 form->submit_element =
159 UTF8ToUTF16(GetStringFromAttributes(attrs, "submit_element")); 160 UTF8ToUTF16(GetStringFromAttributes(attrs, "submit_element"));
160 form->signon_realm = GetStringFromAttributes(attrs, "signon_realm"); 161 form->signon_realm = GetStringFromAttributes(attrs, "signon_realm");
161 form->ssl_valid = GetUintFromAttributes(attrs, "ssl_valid"); 162 form->ssl_valid = GetUintFromAttributes(attrs, "ssl_valid");
162 form->preferred = GetUintFromAttributes(attrs, "preferred"); 163 form->preferred = GetUintFromAttributes(attrs, "preferred");
163 int64 date_created = 0; 164 int64 date_created = 0;
164 bool date_ok = base::StringToInt64( 165 bool date_ok = base::StringToInt64(
165 GetStringFromAttributes(attrs, "date_created"), &date_created); 166 GetStringFromAttributes(attrs, "date_created"), &date_created);
166 DCHECK(date_ok); 167 DCHECK(date_ok);
167 form->date_created = base::Time::FromTimeT(date_created); 168 // In the past |date_created| was stored as time_t. Currently is stored as
169 // base::Time's internal value. We need to distinguish, which format the
170 // number in |date_created| was stored in. We use the fact that
171 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an
172 // unlikely date back in 17th century, and anything above
173 // kMaxPossibleTimeTValue clearly must be in the internal value format.
174 form->date_created = date_created < kMaxPossibleTimeTValue
175 ? base::Time::FromTimeT(date_created)
176 : base::Time::FromInternalValue(date_created);
168 form->blacklisted_by_user = 177 form->blacklisted_by_user =
169 GetUintFromAttributes(attrs, "blacklisted_by_user"); 178 GetUintFromAttributes(attrs, "blacklisted_by_user");
170 form->type = 179 form->type =
171 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type")); 180 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type"));
172 form->times_used = GetUintFromAttributes(attrs, "times_used"); 181 form->times_used = GetUintFromAttributes(attrs, "times_used");
173 form->scheme = 182 form->scheme =
174 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme")); 183 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme"));
175 int64 date_synced = 0; 184 int64 date_synced = 0;
176 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"), 185 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"),
177 &date_synced); 186 &date_synced);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 g_error_free(error); 399 g_error_free(error);
391 if (found) 400 if (found)
392 g_list_free(found); 401 g_list_free(found);
393 return; 402 return;
394 } 403 }
395 404
396 ConvertFormList(found, &lookup_form, forms); 405 ConvertFormList(found, &lookup_form, forms);
397 } 406 }
398 407
399 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { 408 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) {
400 time_t date_created = form.date_created.ToTimeT(); 409 int64 date_created = form.date_created.ToInternalValue();
401 // If we are asked to save a password with 0 date, use the current time. 410 // If we are asked to save a password with 0 date, use the current time.
402 // We don't want to actually save passwords as though on January 1, 1970. 411 // We don't want to actually save passwords as though on January 1, 1601.
403 if (!date_created) 412 if (!date_created)
404 date_created = time(nullptr); 413 date_created = base::Time::Now().ToInternalValue();
405 int64 date_synced = form.date_synced.ToInternalValue(); 414 int64 date_synced = form.date_synced.ToInternalValue();
406 GError* error = nullptr; 415 GError* error = nullptr;
407 secret_password_store_sync( 416 secret_password_store_sync(
408 &kLibsecretSchema, 417 &kLibsecretSchema,
409 nullptr, // Default collection. 418 nullptr, // Default collection.
410 form.origin.spec().c_str(), // Display name. 419 form.origin.spec().c_str(), // Display name.
411 UTF16ToUTF8(form.password_value).c_str(), 420 UTF16ToUTF8(form.password_value).c_str(),
412 nullptr, // no cancellable ojbect 421 nullptr, // no cancellable ojbect
413 &error, 422 &error,
414 "origin_url", form.origin.spec().c_str(), 423 "origin_url", form.origin.spec().c_str(),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return true; 604 return true;
596 } 605 }
597 606
598 std::string NativeBackendLibsecret::GetProfileSpecificAppString( 607 std::string NativeBackendLibsecret::GetProfileSpecificAppString(
599 LocalProfileId id) { 608 LocalProfileId id) {
600 // Originally, the application string was always just "chrome" and used only 609 // Originally, the application string was always just "chrome" and used only
601 // so that we had *something* to search for since GNOME Keyring won't search 610 // so that we had *something* to search for since GNOME Keyring won't search
602 // for nothing. Now we use it to distinguish passwords for different profiles. 611 // for nothing. Now we use it to distinguish passwords for different profiles.
603 return base::StringPrintf("%s-%d", kLibsecretAppString, id); 612 return base::StringPrintf("%s-%d", kLibsecretAppString, id);
604 } 613 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698