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

Side by Side Diff: components/password_manager/core/browser/login_database.cc

Issue 1480153002: Investigate Android build problems in review 1414463004. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add //url dep on GN test_support target. Created 5 years 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 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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 &decrypted_password) == ENCRYPTION_RESULT_SUCCESS) { 822 &decrypted_password) == ENCRYPTION_RESULT_SUCCESS) {
823 passwords_to_realms[decrypted_password].push_back(signon_realm); 823 passwords_to_realms[decrypted_password].push_back(signon_realm);
824 } 824 }
825 } 825 }
826 826
827 for (const auto& password_to_realms : passwords_to_realms) 827 for (const auto& password_to_realms : passwords_to_realms)
828 LogPasswordReuseMetrics(password_to_realms.second); 828 LogPasswordReuseMetrics(password_to_realms.second);
829 } 829 }
830 830
831 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { 831 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) {
832 VLOG(0) << "LoginDatabase::AddLogin: Started.";
832 PasswordStoreChangeList list; 833 PasswordStoreChangeList list;
833 if (!DoesMatchConstraints(form)) 834 if (!DoesMatchConstraints(form)) {
835 VLOG(0) << "LoginDatabase::AddLogin: Constraints not matching.";
834 return list; 836 return list;
837 }
835 std::string encrypted_password; 838 std::string encrypted_password;
836 if (EncryptedString( 839 if (EncryptedString(
837 clear_password_values_ ? base::string16() : form.password_value, 840 clear_password_values_ ? base::string16() : form.password_value,
838 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS) 841 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS) {
842 VLOG(0) << "LoginDatabase::AddLogin: Encryption failed.";
839 return list; 843 return list;
844 }
840 845
846 VLOG(0) << "LoginDatabase::AddLogin: Preparing INSERT SQL statement.";
841 // You *must* change LoginTableColumns if this query changes. 847 // You *must* change LoginTableColumns if this query changes.
842 sql::Statement s(db_.GetCachedStatement( 848 sql::Statement s(db_.GetCachedStatement(
843 SQL_FROM_HERE, 849 SQL_FROM_HERE,
844 "INSERT INTO logins " 850 "INSERT INTO logins "
845 "(origin_url, action_url, username_element, username_value, " 851 "(origin_url, action_url, username_element, username_value, "
846 " password_element, password_value, submit_element, " 852 " password_element, password_value, submit_element, "
847 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, " 853 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, "
848 " scheme, password_type, possible_usernames, times_used, form_data, " 854 " scheme, password_type, possible_usernames, times_used, form_data, "
849 " date_synced, display_name, icon_url," 855 " date_synced, display_name, icon_url,"
850 " federation_url, skip_zero_click, generation_upload_status) VALUES " 856 " federation_url, skip_zero_click, generation_upload_status) VALUES "
851 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); 857 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
858 VLOG(0) << "LoginDatabase::AddLogin: Binding INSERT SQL parameters.";
852 BindAddStatement(form, encrypted_password, &s); 859 BindAddStatement(form, encrypted_password, &s);
853 db_.set_error_callback(base::Bind(&AddCallback)); 860 db_.set_error_callback(base::Bind(&AddCallback));
861 VLOG(0) << "LoginDatabase::AddLogin: Running INSERT SQL statement.";
854 const bool success = s.Run(); 862 const bool success = s.Run();
855 db_.reset_error_callback(); 863 db_.reset_error_callback();
856 if (success) { 864 if (success) {
865 VLOG(0) << "LoginDatabase::AddLogin: INSERT SQL operation succeeded.";
857 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); 866 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
858 return list; 867 return list;
859 } 868 }
860 // Repeat the same statement but with REPLACE semantic. 869 // Repeat the same statement but with REPLACE semantic.
870 VLOG(0)
871 << "LoginDatabase::AddLogin: Adding failed -- trying REPLACE semantics.";
872
873 VLOG(0) << "LoginDatabase::AddLogin: Preparing REPLACE SQL statement.";
861 s.Assign(db_.GetCachedStatement( 874 s.Assign(db_.GetCachedStatement(
862 SQL_FROM_HERE, 875 SQL_FROM_HERE,
863 "INSERT OR REPLACE INTO logins " 876 "INSERT OR REPLACE INTO logins "
864 "(origin_url, action_url, username_element, username_value, " 877 "(origin_url, action_url, username_element, username_value, "
865 " password_element, password_value, submit_element, " 878 " password_element, password_value, submit_element, "
866 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, " 879 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, "
867 " scheme, password_type, possible_usernames, times_used, form_data, " 880 " scheme, password_type, possible_usernames, times_used, form_data, "
868 " date_synced, display_name, icon_url," 881 " date_synced, display_name, icon_url,"
869 " federation_url, skip_zero_click, generation_upload_status) VALUES " 882 " federation_url, skip_zero_click, generation_upload_status) VALUES "
870 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); 883 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
884
885 VLOG(0) << "LoginDatabase::AddLogin: Binding REPLACE SQL parameters.";
871 BindAddStatement(form, encrypted_password, &s); 886 BindAddStatement(form, encrypted_password, &s);
887 VLOG(0) << "LoginDatabase::AddLogin: Running REPLACE SQL statement.";
872 if (s.Run()) { 888 if (s.Run()) {
889 VLOG(0) << "LoginDatabase::AddLogin: REPLACE SQL operation succeeded.";
873 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 890 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form));
874 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); 891 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
875 } 892 }
893 VLOG(0) << "LoginDatabase::AddLogin: Returning result.";
876 return list; 894 return list;
877 } 895 }
878 896
879 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) { 897 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) {
880 std::string encrypted_password; 898 std::string encrypted_password;
881 if (EncryptedString( 899 if (EncryptedString(
882 clear_password_values_ ? base::string16() : form.password_value, 900 clear_password_values_ ? base::string16() : form.password_value,
883 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS) 901 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS)
884 return PasswordStoreChangeList(); 902 return PasswordStoreChangeList();
885 903
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 return PasswordStoreChangeList(); 961 return PasswordStoreChangeList();
944 962
945 PasswordStoreChangeList list; 963 PasswordStoreChangeList list;
946 if (db_.GetLastChangeCount()) 964 if (db_.GetLastChangeCount())
947 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); 965 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form));
948 966
949 return list; 967 return list;
950 } 968 }
951 969
952 bool LoginDatabase::RemoveLogin(const PasswordForm& form) { 970 bool LoginDatabase::RemoveLogin(const PasswordForm& form) {
971 VLOG(0) << "LoginDatabase::RemoveLogin: Started.";
972
953 if (form.is_public_suffix_match) { 973 if (form.is_public_suffix_match) {
954 // TODO(dvadym): Discuss whether we should allow to remove PSL matched 974 // TODO(dvadym): Discuss whether we should allow to remove PSL matched
955 // credentials. 975 // credentials.
976 VLOG(0) << "LoginDatabase::RemoveLogin: Public suffix match exists.";
956 return false; 977 return false;
957 } 978 }
958 #if defined(OS_IOS) 979 #if defined(OS_IOS)
959 DeleteEncryptedPassword(form); 980 DeleteEncryptedPassword(form);
960 #endif 981 #endif
982 VLOG(0) << "LoginDatabase::RemoveLogin: Preparing SQL statement.";
961 // Remove a login by UNIQUE-constrained fields. 983 // Remove a login by UNIQUE-constrained fields.
962 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 984 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
963 "DELETE FROM logins WHERE " 985 "DELETE FROM logins WHERE "
964 "origin_url = ? AND " 986 "origin_url = ? AND "
965 "username_element = ? AND " 987 "username_element = ? AND "
966 "username_value = ? AND " 988 "username_value = ? AND "
967 "password_element = ? AND " 989 "password_element = ? AND "
968 "submit_element = ? AND " 990 "submit_element = ? AND "
969 "signon_realm = ? ")); 991 "signon_realm = ? "));
992
993 VLOG(0) << "LoginDatabase::RemoveLogin: Binding SQL parameters.";
970 s.BindString(0, form.origin.spec()); 994 s.BindString(0, form.origin.spec());
971 s.BindString16(1, form.username_element); 995 s.BindString16(1, form.username_element);
972 s.BindString16(2, form.username_value); 996 s.BindString16(2, form.username_value);
973 s.BindString16(3, form.password_element); 997 s.BindString16(3, form.password_element);
974 s.BindString16(4, form.submit_element); 998 s.BindString16(4, form.submit_element);
975 s.BindString(5, form.signon_realm); 999 s.BindString(5, form.signon_realm);
976 1000
1001 VLOG(0) << "LoginDatabase::RemoveLogin: Running SQL statement.";
977 return s.Run() && db_.GetLastChangeCount() > 0; 1002 return s.Run() && db_.GetLastChangeCount() > 0;
978 } 1003 }
979 1004
980 bool LoginDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin, 1005 bool LoginDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin,
981 base::Time delete_end) { 1006 base::Time delete_end) {
982 #if defined(OS_IOS) 1007 #if defined(OS_IOS)
983 ScopedVector<autofill::PasswordForm> forms; 1008 ScopedVector<autofill::PasswordForm> forms;
984 if (GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) { 1009 if (GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) {
985 for (size_t i = 0; i < forms.size(); i++) { 1010 for (size_t i = 0; i < forms.size(); i++) {
986 DeleteEncryptedPassword(*forms[i]); 1011 DeleteEncryptedPassword(*forms[i]);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1165 }
1141 1166
1142 return StatementToForms(&s, should_PSL_matching_apply ? &form : nullptr, 1167 return StatementToForms(&s, should_PSL_matching_apply ? &form : nullptr,
1143 forms); 1168 forms);
1144 } 1169 }
1145 1170
1146 bool LoginDatabase::GetLoginsCreatedBetween( 1171 bool LoginDatabase::GetLoginsCreatedBetween(
1147 const base::Time begin, 1172 const base::Time begin,
1148 const base::Time end, 1173 const base::Time end,
1149 ScopedVector<autofill::PasswordForm>* forms) const { 1174 ScopedVector<autofill::PasswordForm>* forms) const {
1175 VLOG(0) << "LoginDatabase::GetLoginsCreatedBetween: Started.";
1150 DCHECK(forms); 1176 DCHECK(forms);
1177 VLOG(0) << "LoginDatabase::GetLoginsCreatedBetween: Preparing SQL statement.";
1151 sql::Statement s(db_.GetCachedStatement( 1178 sql::Statement s(db_.GetCachedStatement(
1152 SQL_FROM_HERE, 1179 SQL_FROM_HERE,
1153 "SELECT origin_url, action_url, " 1180 "SELECT origin_url, action_url, "
1154 "username_element, username_value, " 1181 "username_element, username_value, "
1155 "password_element, password_value, submit_element, " 1182 "password_element, password_value, submit_element, "
1156 "signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, " 1183 "signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, "
1157 "scheme, password_type, possible_usernames, times_used, form_data, " 1184 "scheme, password_type, possible_usernames, times_used, form_data, "
1158 "date_synced, display_name, icon_url, " 1185 "date_synced, display_name, icon_url, "
1159 "federation_url, skip_zero_click, generation_upload_status FROM logins " 1186 "federation_url, skip_zero_click, generation_upload_status FROM logins "
1160 "WHERE date_created >= ? AND date_created < ?" 1187 "WHERE date_created >= ? AND date_created < ?"
1161 "ORDER BY origin_url")); 1188 "ORDER BY origin_url"));
1189 VLOG(0) << "LoginDatabase::GetLoginsCreatedBetween: Binding SQL parameters.";
1162 s.BindInt64(0, begin.ToInternalValue()); 1190 s.BindInt64(0, begin.ToInternalValue());
1163 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64>::max() 1191 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64>::max()
1164 : end.ToInternalValue()); 1192 : end.ToInternalValue());
1165 1193
1194 VLOG(0) << "LoginDatabase::GetLoginsCreatedBetween: Running SQL statement.";
1166 return StatementToForms(&s, nullptr, forms); 1195 return StatementToForms(&s, nullptr, forms);
1167 } 1196 }
1168 1197
1169 bool LoginDatabase::GetLoginsSyncedBetween( 1198 bool LoginDatabase::GetLoginsSyncedBetween(
1170 const base::Time begin, 1199 const base::Time begin,
1171 const base::Time end, 1200 const base::Time end,
1172 ScopedVector<autofill::PasswordForm>* forms) const { 1201 ScopedVector<autofill::PasswordForm>* forms) const {
1173 DCHECK(forms); 1202 DCHECK(forms);
1174 sql::Statement s(db_.GetCachedStatement( 1203 sql::Statement s(db_.GetCachedStatement(
1175 SQL_FROM_HERE, 1204 SQL_FROM_HERE,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 1318 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
1290 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); 1319 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT);
1291 } 1320 }
1292 1321
1293 if (!statement->Succeeded()) 1322 if (!statement->Succeeded())
1294 return false; 1323 return false;
1295 return true; 1324 return true;
1296 } 1325 }
1297 1326
1298 } // namespace password_manager 1327 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698