| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "sql/statement.h" | 25 #include "sql/statement.h" |
| 26 #include "sql/transaction.h" | 26 #include "sql/transaction.h" |
| 27 | 27 |
| 28 using autofill::PasswordForm; | 28 using autofill::PasswordForm; |
| 29 | 29 |
| 30 namespace password_manager { | 30 namespace password_manager { |
| 31 | 31 |
| 32 const int kCurrentVersionNumber = 13; | 32 const int kCurrentVersionNumber = 13; |
| 33 static const int kCompatibleVersionNumber = 1; | 33 static const int kCompatibleVersionNumber = 1; |
| 34 | 34 |
| 35 Pickle SerializeVector(const std::vector<base::string16>& vec) { | 35 base::Pickle SerializeVector(const std::vector<base::string16>& vec) { |
| 36 Pickle p; | 36 base::Pickle p; |
| 37 for (size_t i = 0; i < vec.size(); ++i) { | 37 for (size_t i = 0; i < vec.size(); ++i) { |
| 38 p.WriteString16(vec[i]); | 38 p.WriteString16(vec[i]); |
| 39 } | 39 } |
| 40 return p; | 40 return p; |
| 41 } | 41 } |
| 42 | 42 |
| 43 std::vector<base::string16> DeserializeVector(const Pickle& p) { | 43 std::vector<base::string16> DeserializeVector(const base::Pickle& p) { |
| 44 std::vector<base::string16> ret; | 44 std::vector<base::string16> ret; |
| 45 base::string16 str; | 45 base::string16 str; |
| 46 | 46 |
| 47 PickleIterator iterator(p); | 47 base::PickleIterator iterator(p); |
| 48 while (iterator.ReadString16(&str)) { | 48 while (iterator.ReadString16(&str)) { |
| 49 ret.push_back(str); | 49 ret.push_back(str); |
| 50 } | 50 } |
| 51 return ret; | 51 return ret; |
| 52 } | 52 } |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 // Convenience enum for interacting with SQL queries that use all the columns. | 56 // Convenience enum for interacting with SQL queries that use all the columns. |
| 57 enum LoginTableColumns { | 57 enum LoginTableColumns { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 s->BindBlob(COLUMN_PASSWORD_VALUE, encrypted_password.data(), | 91 s->BindBlob(COLUMN_PASSWORD_VALUE, encrypted_password.data(), |
| 92 static_cast<int>(encrypted_password.length())); | 92 static_cast<int>(encrypted_password.length())); |
| 93 s->BindString16(COLUMN_SUBMIT_ELEMENT, form.submit_element); | 93 s->BindString16(COLUMN_SUBMIT_ELEMENT, form.submit_element); |
| 94 s->BindString(COLUMN_SIGNON_REALM, form.signon_realm); | 94 s->BindString(COLUMN_SIGNON_REALM, form.signon_realm); |
| 95 s->BindInt(COLUMN_SSL_VALID, form.ssl_valid); | 95 s->BindInt(COLUMN_SSL_VALID, form.ssl_valid); |
| 96 s->BindInt(COLUMN_PREFERRED, form.preferred); | 96 s->BindInt(COLUMN_PREFERRED, form.preferred); |
| 97 s->BindInt64(COLUMN_DATE_CREATED, form.date_created.ToInternalValue()); | 97 s->BindInt64(COLUMN_DATE_CREATED, form.date_created.ToInternalValue()); |
| 98 s->BindInt(COLUMN_BLACKLISTED_BY_USER, form.blacklisted_by_user); | 98 s->BindInt(COLUMN_BLACKLISTED_BY_USER, form.blacklisted_by_user); |
| 99 s->BindInt(COLUMN_SCHEME, form.scheme); | 99 s->BindInt(COLUMN_SCHEME, form.scheme); |
| 100 s->BindInt(COLUMN_PASSWORD_TYPE, form.type); | 100 s->BindInt(COLUMN_PASSWORD_TYPE, form.type); |
| 101 Pickle usernames_pickle = SerializeVector(form.other_possible_usernames); | 101 base::Pickle usernames_pickle = |
| 102 SerializeVector(form.other_possible_usernames); |
| 102 s->BindBlob(COLUMN_POSSIBLE_USERNAMES, | 103 s->BindBlob(COLUMN_POSSIBLE_USERNAMES, |
| 103 usernames_pickle.data(), | 104 usernames_pickle.data(), |
| 104 usernames_pickle.size()); | 105 usernames_pickle.size()); |
| 105 s->BindInt(COLUMN_TIMES_USED, form.times_used); | 106 s->BindInt(COLUMN_TIMES_USED, form.times_used); |
| 106 Pickle form_data_pickle; | 107 base::Pickle form_data_pickle; |
| 107 autofill::SerializeFormData(form.form_data, &form_data_pickle); | 108 autofill::SerializeFormData(form.form_data, &form_data_pickle); |
| 108 s->BindBlob(COLUMN_FORM_DATA, | 109 s->BindBlob(COLUMN_FORM_DATA, |
| 109 form_data_pickle.data(), | 110 form_data_pickle.data(), |
| 110 form_data_pickle.size()); | 111 form_data_pickle.size()); |
| 111 s->BindInt64(COLUMN_DATE_SYNCED, form.date_synced.ToInternalValue()); | 112 s->BindInt64(COLUMN_DATE_SYNCED, form.date_synced.ToInternalValue()); |
| 112 s->BindString16(COLUMN_DISPLAY_NAME, form.display_name); | 113 s->BindString16(COLUMN_DISPLAY_NAME, form.display_name); |
| 113 s->BindString(COLUMN_AVATAR_URL, form.avatar_url.spec()); | 114 s->BindString(COLUMN_AVATAR_URL, form.avatar_url.spec()); |
| 114 s->BindString(COLUMN_FEDERATION_URL, form.federation_url.spec()); | 115 s->BindString(COLUMN_FEDERATION_URL, form.federation_url.spec()); |
| 115 s->BindInt(COLUMN_SKIP_ZERO_CLICK, form.skip_zero_click); | 116 s->BindInt(COLUMN_SKIP_ZERO_CLICK, form.skip_zero_click); |
| 116 s->BindInt(COLUMN_GENERATION_UPLOAD_STATUS, form.generation_upload_status); | 117 s->BindInt(COLUMN_GENERATION_UPLOAD_STATUS, form.generation_upload_status); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 "WHERE origin_url = ? AND " | 606 "WHERE origin_url = ? AND " |
| 606 "username_element = ? AND " | 607 "username_element = ? AND " |
| 607 "username_value = ? AND " | 608 "username_value = ? AND " |
| 608 "password_element = ? AND " | 609 "password_element = ? AND " |
| 609 "signon_realm = ?")); | 610 "signon_realm = ?")); |
| 610 s.BindString(0, form.action.spec()); | 611 s.BindString(0, form.action.spec()); |
| 611 s.BindBlob(1, encrypted_password.data(), | 612 s.BindBlob(1, encrypted_password.data(), |
| 612 static_cast<int>(encrypted_password.length())); | 613 static_cast<int>(encrypted_password.length())); |
| 613 s.BindInt(2, form.ssl_valid); | 614 s.BindInt(2, form.ssl_valid); |
| 614 s.BindInt(3, form.preferred); | 615 s.BindInt(3, form.preferred); |
| 615 Pickle pickle = SerializeVector(form.other_possible_usernames); | 616 base::Pickle pickle = SerializeVector(form.other_possible_usernames); |
| 616 s.BindBlob(4, pickle.data(), pickle.size()); | 617 s.BindBlob(4, pickle.data(), pickle.size()); |
| 617 s.BindInt(5, form.times_used); | 618 s.BindInt(5, form.times_used); |
| 618 s.BindString16(6, form.submit_element); | 619 s.BindString16(6, form.submit_element); |
| 619 s.BindInt64(7, form.date_synced.ToInternalValue()); | 620 s.BindInt64(7, form.date_synced.ToInternalValue()); |
| 620 s.BindInt64(8, form.date_created.ToInternalValue()); | 621 s.BindInt64(8, form.date_created.ToInternalValue()); |
| 621 s.BindInt(9, form.blacklisted_by_user); | 622 s.BindInt(9, form.blacklisted_by_user); |
| 622 s.BindInt(10, form.scheme); | 623 s.BindInt(10, form.scheme); |
| 623 s.BindInt(11, form.type); | 624 s.BindInt(11, form.type); |
| 624 s.BindString16(12, form.display_name); | 625 s.BindString16(12, form.display_name); |
| 625 s.BindString(13, form.avatar_url.spec()); | 626 s.BindString(13, form.avatar_url.spec()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 form->date_created = | 723 form->date_created = |
| 723 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED)); | 724 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED)); |
| 724 form->blacklisted_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0); | 725 form->blacklisted_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0); |
| 725 int scheme_int = s.ColumnInt(COLUMN_SCHEME); | 726 int scheme_int = s.ColumnInt(COLUMN_SCHEME); |
| 726 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER)); | 727 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER)); |
| 727 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); | 728 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); |
| 728 int type_int = s.ColumnInt(COLUMN_PASSWORD_TYPE); | 729 int type_int = s.ColumnInt(COLUMN_PASSWORD_TYPE); |
| 729 DCHECK(type_int >= 0 && type_int <= PasswordForm::TYPE_GENERATED); | 730 DCHECK(type_int >= 0 && type_int <= PasswordForm::TYPE_GENERATED); |
| 730 form->type = static_cast<PasswordForm::Type>(type_int); | 731 form->type = static_cast<PasswordForm::Type>(type_int); |
| 731 if (s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)) { | 732 if (s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)) { |
| 732 Pickle pickle( | 733 base::Pickle pickle( |
| 733 static_cast<const char*>(s.ColumnBlob(COLUMN_POSSIBLE_USERNAMES)), | 734 static_cast<const char*>(s.ColumnBlob(COLUMN_POSSIBLE_USERNAMES)), |
| 734 s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)); | 735 s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)); |
| 735 form->other_possible_usernames = DeserializeVector(pickle); | 736 form->other_possible_usernames = DeserializeVector(pickle); |
| 736 } | 737 } |
| 737 form->times_used = s.ColumnInt(COLUMN_TIMES_USED); | 738 form->times_used = s.ColumnInt(COLUMN_TIMES_USED); |
| 738 if (s.ColumnByteLength(COLUMN_FORM_DATA)) { | 739 if (s.ColumnByteLength(COLUMN_FORM_DATA)) { |
| 739 Pickle form_data_pickle( | 740 base::Pickle form_data_pickle( |
| 740 static_cast<const char*>(s.ColumnBlob(COLUMN_FORM_DATA)), | 741 static_cast<const char*>(s.ColumnBlob(COLUMN_FORM_DATA)), |
| 741 s.ColumnByteLength(COLUMN_FORM_DATA)); | 742 s.ColumnByteLength(COLUMN_FORM_DATA)); |
| 742 PickleIterator form_data_iter(form_data_pickle); | 743 base::PickleIterator form_data_iter(form_data_pickle); |
| 743 bool success = | 744 bool success = |
| 744 autofill::DeserializeFormData(&form_data_iter, &form->form_data); | 745 autofill::DeserializeFormData(&form_data_iter, &form->form_data); |
| 745 metrics_util::FormDeserializationStatus status = | 746 metrics_util::FormDeserializationStatus status = |
| 746 success ? metrics_util::LOGIN_DATABASE_SUCCESS | 747 success ? metrics_util::LOGIN_DATABASE_SUCCESS |
| 747 : metrics_util::LOGIN_DATABASE_FAILURE; | 748 : metrics_util::LOGIN_DATABASE_FAILURE; |
| 748 metrics_util::LogFormDataDeserializationStatus(status); | 749 metrics_util::LogFormDataDeserializationStatus(status); |
| 749 } | 750 } |
| 750 form->date_synced = | 751 form->date_synced = |
| 751 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_SYNCED)); | 752 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_SYNCED)); |
| 752 form->display_name = s.ColumnString16(COLUMN_DISPLAY_NAME); | 753 form->display_name = s.ColumnString16(COLUMN_DISPLAY_NAME); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 955 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
| 955 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); | 956 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); |
| 956 } | 957 } |
| 957 | 958 |
| 958 if (!statement->Succeeded()) | 959 if (!statement->Succeeded()) |
| 959 return false; | 960 return false; |
| 960 return true; | 961 return true; |
| 961 } | 962 } |
| 962 | 963 |
| 963 } // namespace password_manager | 964 } // namespace password_manager |
| OLD | NEW |