Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 = INT_MAX; | |
|
vabr (Chromium)
2015/02/02 17:01:18
What about std::numeric_limits<int>::max() ?
dvadym
2015/02/03 11:53:49
Done.
| |
| 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 Loading... | |
| 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 past date_created was stored as time_t. We can distinguish between |
| 169 // them by taking into consideration that INT_MAX correspond to | |
| 170 // 2038 year in time_t and internal values of base::Time are much bigger. | |
| 171 form->date_created = date_created < kMaxPossibleTimeTValue | |
| 172 ? base::Time::FromTimeT(date_created) | |
| 173 : base::Time::FromInternalValue(date_created); | |
| 168 form->blacklisted_by_user = | 174 form->blacklisted_by_user = |
| 169 GetUintFromAttributes(attrs, "blacklisted_by_user"); | 175 GetUintFromAttributes(attrs, "blacklisted_by_user"); |
| 170 form->type = | 176 form->type = |
| 171 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type")); | 177 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type")); |
| 172 form->times_used = GetUintFromAttributes(attrs, "times_used"); | 178 form->times_used = GetUintFromAttributes(attrs, "times_used"); |
| 173 form->scheme = | 179 form->scheme = |
| 174 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme")); | 180 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme")); |
| 175 int64 date_synced = 0; | 181 int64 date_synced = 0; |
| 176 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"), | 182 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"), |
| 177 &date_synced); | 183 &date_synced); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 g_error_free(error); | 396 g_error_free(error); |
| 391 if (found) | 397 if (found) |
| 392 g_list_free(found); | 398 g_list_free(found); |
| 393 return; | 399 return; |
| 394 } | 400 } |
| 395 | 401 |
| 396 ConvertFormList(found, &lookup_form, forms); | 402 ConvertFormList(found, &lookup_form, forms); |
| 397 } | 403 } |
| 398 | 404 |
| 399 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { | 405 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { |
| 400 time_t date_created = form.date_created.ToTimeT(); | 406 int64 date_created = form.date_created.ToInternalValue(); |
| 401 // If we are asked to save a password with 0 date, use the current time. | 407 // 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. | 408 // We don't want to actually save passwords as though on January 1, 1601. |
| 403 if (!date_created) | 409 if (!date_created) |
| 404 date_created = time(nullptr); | 410 date_created = base::Time::Now().ToInternalValue(); |
| 405 int64 date_synced = form.date_synced.ToInternalValue(); | 411 int64 date_synced = form.date_synced.ToInternalValue(); |
| 406 GError* error = nullptr; | 412 GError* error = nullptr; |
| 407 secret_password_store_sync( | 413 secret_password_store_sync( |
| 408 &kLibsecretSchema, | 414 &kLibsecretSchema, |
| 409 nullptr, // Default collection. | 415 nullptr, // Default collection. |
| 410 form.origin.spec().c_str(), // Display name. | 416 form.origin.spec().c_str(), // Display name. |
| 411 UTF16ToUTF8(form.password_value).c_str(), | 417 UTF16ToUTF8(form.password_value).c_str(), |
| 412 nullptr, // no cancellable ojbect | 418 nullptr, // no cancellable ojbect |
| 413 &error, "origin_url", form.origin.spec().c_str(), "action_url", | 419 &error, "origin_url", form.origin.spec().c_str(), "action_url", |
| 414 form.action.spec().c_str(), "username_element", | 420 form.action.spec().c_str(), "username_element", |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 return true; | 595 return true; |
| 590 } | 596 } |
| 591 | 597 |
| 592 std::string NativeBackendLibsecret::GetProfileSpecificAppString( | 598 std::string NativeBackendLibsecret::GetProfileSpecificAppString( |
| 593 LocalProfileId id) { | 599 LocalProfileId id) { |
| 594 // Originally, the application string was always just "chrome" and used only | 600 // Originally, the application string was always just "chrome" and used only |
| 595 // so that we had *something* to search for since GNOME Keyring won't search | 601 // so that we had *something* to search for since GNOME Keyring won't search |
| 596 // for nothing. Now we use it to distinguish passwords for different profiles. | 602 // for nothing. Now we use it to distinguish passwords for different profiles. |
| 597 return base::StringPrintf("%s-%d", kLibsecretAppString, id); | 603 return base::StringPrintf("%s-%d", kLibsecretAppString, id); |
| 598 } | 604 } |
| OLD | NEW |