OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_gnome_x.h" | 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gnome-keyring.h> | 8 #include <gnome-keyring.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "components/autofill/core/common/password_form.h" | 25 #include "components/autofill/core/common/password_form.h" |
26 #include "components/password_manager/core/browser/psl_matching_helper.h" | 26 #include "components/password_manager/core/browser/psl_matching_helper.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 | 28 |
29 using autofill::PasswordForm; | 29 using autofill::PasswordForm; |
30 using base::UTF8ToUTF16; | 30 using base::UTF8ToUTF16; |
31 using base::UTF16ToUTF8; | 31 using base::UTF16ToUTF8; |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 | 33 |
34 namespace { | |
35 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); | |
36 } | |
37 | |
34 #define GNOME_KEYRING_DEFINE_POINTER(name) \ | 38 #define GNOME_KEYRING_DEFINE_POINTER(name) \ |
35 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; | 39 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; |
36 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) | 40 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) |
37 #undef GNOME_KEYRING_DEFINE_POINTER | 41 #undef GNOME_KEYRING_DEFINE_POINTER |
38 | 42 |
39 bool GnomeKeyringLoader::keyring_loaded = false; | 43 bool GnomeKeyringLoader::keyring_loaded = false; |
40 | 44 |
41 #if defined(DLOPEN_GNOME_KEYRING) | 45 #if defined(DLOPEN_GNOME_KEYRING) |
42 | 46 |
43 #define GNOME_KEYRING_FUNCTION_INFO(name) \ | 47 #define GNOME_KEYRING_FUNCTION_INFO(name) \ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); | 128 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); |
125 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); | 129 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); |
126 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); | 130 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); |
127 form->signon_realm = string_attr_map["signon_realm"]; | 131 form->signon_realm = string_attr_map["signon_realm"]; |
128 form->ssl_valid = uint_attr_map["ssl_valid"]; | 132 form->ssl_valid = uint_attr_map["ssl_valid"]; |
129 form->preferred = uint_attr_map["preferred"]; | 133 form->preferred = uint_attr_map["preferred"]; |
130 int64 date_created = 0; | 134 int64 date_created = 0; |
131 bool date_ok = base::StringToInt64(string_attr_map["date_created"], | 135 bool date_ok = base::StringToInt64(string_attr_map["date_created"], |
132 &date_created); | 136 &date_created); |
133 DCHECK(date_ok); | 137 DCHECK(date_ok); |
134 form->date_created = base::Time::FromTimeT(date_created); | 138 // In past date_created was stored as time_t. We can distinguish between |
139 // them by taking into consideration that INT_MAX correspond to | |
vabr (Chromium)
2015/02/03 16:06:42
nit: INT_MAX -> kMaxPossibleTimeTValue
(Also for l
dvadym
2015/02/04 10:40:25
Done.
| |
140 // 2038 year in time_t and internal values of base::Time are much bigger. | |
vabr (Chromium)
2015/02/03 16:06:42
Perhaps you could explain more clearly:
In the pas
dvadym
2015/02/04 10:40:25
Done.
| |
141 form->date_created = date_created < kMaxPossibleTimeTValue | |
vabr (Chromium)
2015/02/03 16:06:42
I suggest pulling this check and kMaxPossibleTimeT
dvadym
2015/02/04 10:40:25
Keyring backend will finally disappear, so after o
| |
142 ? base::Time::FromTimeT(date_created) | |
143 : base::Time::FromInternalValue(date_created); | |
135 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; | 144 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; |
136 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); | 145 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); |
137 form->times_used = uint_attr_map["times_used"]; | 146 form->times_used = uint_attr_map["times_used"]; |
138 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); | 147 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); |
139 int64 date_synced = 0; | 148 int64 date_synced = 0; |
140 base::StringToInt64(string_attr_map["date_synced"], &date_synced); | 149 base::StringToInt64(string_attr_map["date_synced"], &date_synced); |
141 form->date_synced = base::Time::FromInternalValue(date_synced); | 150 form->date_synced = base::Time::FromInternalValue(date_synced); |
142 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); | 151 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); |
143 form->avatar_url = GURL(string_attr_map["avatar_url"]); | 152 form->avatar_url = GURL(string_attr_map["avatar_url"]); |
144 form->federation_url = GURL(string_attr_map["federation_url"]); | 153 form->federation_url = GURL(string_attr_map["federation_url"]); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 // matching is used to find a result, then the results signon realm, origin | 319 // matching is used to find a result, then the results signon realm, origin |
311 // and action are stored are replaced by those of |lookup_form_|. | 320 // and action are stored are replaced by those of |lookup_form_|. |
312 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the | 321 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the |
313 // found logins to those which indeed PSL-match the look-up. And finally, | 322 // found logins to those which indeed PSL-match the look-up. And finally, |
314 // |lookup_form_| set to NULL means that PSL matching is not required. | 323 // |lookup_form_| set to NULL means that PSL matching is not required. |
315 scoped_ptr<PasswordForm> lookup_form_; | 324 scoped_ptr<PasswordForm> lookup_form_; |
316 }; | 325 }; |
317 | 326 |
318 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { | 327 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
320 time_t date_created = form.date_created.ToTimeT(); | 329 int64 date_created = form.date_created.ToInternalValue(); |
321 // If we are asked to save a password with 0 date, use the current time. | 330 // If we are asked to save a password with 0 date, use the current time. |
322 // We don't want to actually save passwords as though on January 1, 1970. | 331 // We don't want to actually save passwords as though on January 1, 1601. |
323 if (!date_created) | 332 if (!date_created) |
324 date_created = time(NULL); | 333 date_created = base::Time::Now().ToInternalValue(); |
325 int64 date_synced = form.date_synced.ToInternalValue(); | 334 int64 date_synced = form.date_synced.ToInternalValue(); |
326 gnome_keyring_store_password( | 335 gnome_keyring_store_password( |
327 &kGnomeSchema, | 336 &kGnomeSchema, |
328 NULL, // Default keyring. | 337 NULL, // Default keyring. |
329 form.origin.spec().c_str(), // Display name. | 338 form.origin.spec().c_str(), // Display name. |
330 UTF16ToUTF8(form.password_value).c_str(), | 339 UTF16ToUTF8(form.password_value).c_str(), |
331 OnOperationDone, | 340 OnOperationDone, |
332 this, // data | 341 this, // data |
333 NULL, // destroy_data | 342 NULL, // destroy_data |
334 "origin_url", form.origin.spec().c_str(), | 343 "origin_url", form.origin.spec().c_str(), |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 } | 798 } |
790 return ok; | 799 return ok; |
791 } | 800 } |
792 | 801 |
793 std::string NativeBackendGnome::GetProfileSpecificAppString() const { | 802 std::string NativeBackendGnome::GetProfileSpecificAppString() const { |
794 // Originally, the application string was always just "chrome" and used only | 803 // Originally, the application string was always just "chrome" and used only |
795 // so that we had *something* to search for since GNOME Keyring won't search | 804 // so that we had *something* to search for since GNOME Keyring won't search |
796 // for nothing. Now we use it to distinguish passwords for different profiles. | 805 // for nothing. Now we use it to distinguish passwords for different profiles. |
797 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); | 806 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); |
798 } | 807 } |
OLD | NEW |