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

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

Issue 2566873002: Remove ScopedVector from PasswordStoreMac (Closed)
Patch Set: back_inserter Created 4 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 s.BindString16(2, form.username_value); 903 s.BindString16(2, form.username_value);
904 s.BindString16(3, form.password_element); 904 s.BindString16(3, form.password_element);
905 s.BindString(4, form.signon_realm); 905 s.BindString(4, form.signon_realm);
906 906
907 return s.Run() && db_.GetLastChangeCount() > 0; 907 return s.Run() && db_.GetLastChangeCount() > 0;
908 } 908 }
909 909
910 bool LoginDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin, 910 bool LoginDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin,
911 base::Time delete_end) { 911 base::Time delete_end) {
912 #if defined(OS_IOS) 912 #if defined(OS_IOS)
913 ScopedVector<autofill::PasswordForm> forms; 913 std::vector<std::unique_ptr<PasswordForm>> forms;
914 if (GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) { 914 if (GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) {
915 for (size_t i = 0; i < forms.size(); i++) { 915 for (size_t i = 0; i < forms.size(); i++) {
916 DeleteEncryptedPassword(*forms[i]); 916 DeleteEncryptedPassword(*forms[i]);
917 } 917 }
918 } 918 }
919 #endif 919 #endif
920 920
921 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 921 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
922 "DELETE FROM logins WHERE " 922 "DELETE FROM logins WHERE "
923 "date_created >= ? AND date_created < ?")); 923 "date_created >= ? AND date_created < ?"));
(...skipping 11 matching lines...) Expand all
935 "DELETE FROM logins WHERE date_synced >= ? AND date_synced < ?")); 935 "DELETE FROM logins WHERE date_synced >= ? AND date_synced < ?"));
936 s.BindInt64(0, delete_begin.ToInternalValue()); 936 s.BindInt64(0, delete_begin.ToInternalValue());
937 s.BindInt64(1, 937 s.BindInt64(1,
938 delete_end.is_null() ? base::Time::Max().ToInternalValue() 938 delete_end.is_null() ? base::Time::Max().ToInternalValue()
939 : delete_end.ToInternalValue()); 939 : delete_end.ToInternalValue());
940 940
941 return s.Run(); 941 return s.Run();
942 } 942 }
943 943
944 bool LoginDatabase::GetAutoSignInLogins( 944 bool LoginDatabase::GetAutoSignInLogins(
945 ScopedVector<autofill::PasswordForm>* forms) const { 945 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
946 DCHECK(forms); 946 DCHECK(forms);
947 DCHECK(!autosignin_statement_.empty()); 947 DCHECK(!autosignin_statement_.empty());
948 sql::Statement s( 948 sql::Statement s(
949 db_.GetCachedStatement(SQL_FROM_HERE, autosignin_statement_.c_str())); 949 db_.GetCachedStatement(SQL_FROM_HERE, autosignin_statement_.c_str()));
950 950
951 return StatementToForms(&s, nullptr, forms); 951 return StatementToForms(&s, nullptr, forms);
952 } 952 }
953 953
954 bool LoginDatabase::DisableAutoSignInForOrigin(const GURL& origin) { 954 bool LoginDatabase::DisableAutoSignInForOrigin(const GURL& origin) {
955 sql::Statement s(db_.GetCachedStatement( 955 sql::Statement s(db_.GetCachedStatement(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 DCHECK(generation_upload_status_int >= 0 && 1028 DCHECK(generation_upload_status_int >= 0 &&
1029 generation_upload_status_int <= PasswordForm::UNKNOWN_STATUS); 1029 generation_upload_status_int <= PasswordForm::UNKNOWN_STATUS);
1030 form->generation_upload_status = 1030 form->generation_upload_status =
1031 static_cast<PasswordForm::GenerationUploadStatus>( 1031 static_cast<PasswordForm::GenerationUploadStatus>(
1032 generation_upload_status_int); 1032 generation_upload_status_int);
1033 return ENCRYPTION_RESULT_SUCCESS; 1033 return ENCRYPTION_RESULT_SUCCESS;
1034 } 1034 }
1035 1035
1036 bool LoginDatabase::GetLogins( 1036 bool LoginDatabase::GetLogins(
1037 const PasswordStore::FormDigest& form, 1037 const PasswordStore::FormDigest& form,
1038 std::vector<std::unique_ptr<autofill::PasswordForm>>* forms) const { 1038 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1039 DCHECK(forms); 1039 DCHECK(forms);
1040 const GURL signon_realm(form.signon_realm); 1040 const GURL signon_realm(form.signon_realm);
1041 std::string registered_domain = GetRegistryControlledDomain(signon_realm); 1041 std::string registered_domain = GetRegistryControlledDomain(signon_realm);
1042 const bool should_PSL_matching_apply = 1042 const bool should_PSL_matching_apply =
1043 form.scheme == PasswordForm::SCHEME_HTML && 1043 form.scheme == PasswordForm::SCHEME_HTML &&
1044 ShouldPSLDomainMatchingApply(registered_domain); 1044 ShouldPSLDomainMatchingApply(registered_domain);
1045 const bool should_federated_apply = form.scheme == PasswordForm::SCHEME_HTML; 1045 const bool should_federated_apply = form.scheme == PasswordForm::SCHEME_HTML;
1046 DCHECK(!get_statement_.empty()); 1046 DCHECK(!get_statement_.empty());
1047 DCHECK(!get_statement_psl_.empty()); 1047 DCHECK(!get_statement_psl_.empty());
1048 DCHECK(!get_statement_federated_.empty()); 1048 DCHECK(!get_statement_federated_.empty());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 s.BindString(placeholder++, expression); 1092 s.BindString(placeholder++, expression);
1093 } 1093 }
1094 1094
1095 if (!should_PSL_matching_apply && !should_federated_apply) { 1095 if (!should_PSL_matching_apply && !should_federated_apply) {
1096 // Otherwise the histogram is reported in StatementToForms. 1096 // Otherwise the histogram is reported in StatementToForms.
1097 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 1097 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
1098 PSL_DOMAIN_MATCH_NOT_USED, 1098 PSL_DOMAIN_MATCH_NOT_USED,
1099 PSL_DOMAIN_MATCH_COUNT); 1099 PSL_DOMAIN_MATCH_COUNT);
1100 } 1100 }
1101 1101
1102 ScopedVector<autofill::PasswordForm> forms_scopedvector;
1103 bool success = StatementToForms( 1102 bool success = StatementToForms(
1104 &s, should_PSL_matching_apply || should_federated_apply ? &form : nullptr, 1103 &s, should_PSL_matching_apply || should_federated_apply ? &form : nullptr,
1105 &forms_scopedvector); 1104 forms);
1106 if (success) { 1105 if (success)
1107 *forms = password_manager_util::ConvertScopedVector(
1108 std::move(forms_scopedvector));
1109 return true; 1106 return true;
1110 }
1111 forms->clear(); 1107 forms->clear();
1112 return false; 1108 return false;
1113 } 1109 }
1114 1110
1115 bool LoginDatabase::GetLoginsCreatedBetween( 1111 bool LoginDatabase::GetLoginsCreatedBetween(
1116 const base::Time begin, 1112 const base::Time begin,
1117 const base::Time end, 1113 const base::Time end,
1118 ScopedVector<autofill::PasswordForm>* forms) const { 1114 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1119 DCHECK(forms); 1115 DCHECK(forms);
1120 DCHECK(!created_statement_.empty()); 1116 DCHECK(!created_statement_.empty());
1121 sql::Statement s( 1117 sql::Statement s(
1122 db_.GetCachedStatement(SQL_FROM_HERE, created_statement_.c_str())); 1118 db_.GetCachedStatement(SQL_FROM_HERE, created_statement_.c_str()));
1123 s.BindInt64(0, begin.ToInternalValue()); 1119 s.BindInt64(0, begin.ToInternalValue());
1124 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64_t>::max() 1120 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64_t>::max()
1125 : end.ToInternalValue()); 1121 : end.ToInternalValue());
1126 1122
1127 return StatementToForms(&s, nullptr, forms); 1123 return StatementToForms(&s, nullptr, forms);
1128 } 1124 }
1129 1125
1130 bool LoginDatabase::GetLoginsSyncedBetween( 1126 bool LoginDatabase::GetLoginsSyncedBetween(
1131 const base::Time begin, 1127 const base::Time begin,
1132 const base::Time end, 1128 const base::Time end,
1133 ScopedVector<autofill::PasswordForm>* forms) const { 1129 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1134 DCHECK(forms); 1130 DCHECK(forms);
1135 DCHECK(!synced_statement_.empty()); 1131 DCHECK(!synced_statement_.empty());
1136 sql::Statement s( 1132 sql::Statement s(
1137 db_.GetCachedStatement(SQL_FROM_HERE, synced_statement_.c_str())); 1133 db_.GetCachedStatement(SQL_FROM_HERE, synced_statement_.c_str()));
1138 s.BindInt64(0, begin.ToInternalValue()); 1134 s.BindInt64(0, begin.ToInternalValue());
1139 s.BindInt64(1, 1135 s.BindInt64(1,
1140 end.is_null() ? base::Time::Max().ToInternalValue() 1136 end.is_null() ? base::Time::Max().ToInternalValue()
1141 : end.ToInternalValue()); 1137 : end.ToInternalValue());
1142 1138
1143 return StatementToForms(&s, nullptr, forms); 1139 return StatementToForms(&s, nullptr, forms);
1144 } 1140 }
1145 1141
1146 bool LoginDatabase::GetAutofillableLogins( 1142 bool LoginDatabase::GetAutofillableLogins(
1147 std::vector<std::unique_ptr<autofill::PasswordForm>>* forms) const { 1143 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1148 return GetAllLoginsWithBlacklistSetting(false, forms); 1144 return GetAllLoginsWithBlacklistSetting(false, forms);
1149 } 1145 }
1150 1146
1151 bool LoginDatabase::GetBlacklistLogins( 1147 bool LoginDatabase::GetBlacklistLogins(
1152 std::vector<std::unique_ptr<autofill::PasswordForm>>* forms) const { 1148 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1153 return GetAllLoginsWithBlacklistSetting(true, forms); 1149 return GetAllLoginsWithBlacklistSetting(true, forms);
1154 } 1150 }
1155 1151
1156 bool LoginDatabase::GetAllLoginsWithBlacklistSetting( 1152 bool LoginDatabase::GetAllLoginsWithBlacklistSetting(
1157 bool blacklisted, 1153 bool blacklisted,
1158 std::vector<std::unique_ptr<PasswordForm>>* forms) const { 1154 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1159 DCHECK(forms); 1155 DCHECK(forms);
1160 DCHECK(!blacklisted_statement_.empty()); 1156 DCHECK(!blacklisted_statement_.empty());
1161 sql::Statement s( 1157 sql::Statement s(
1162 db_.GetCachedStatement(SQL_FROM_HERE, blacklisted_statement_.c_str())); 1158 db_.GetCachedStatement(SQL_FROM_HERE, blacklisted_statement_.c_str()));
1163 s.BindInt(0, blacklisted ? 1 : 0); 1159 s.BindInt(0, blacklisted ? 1 : 0);
1164 1160
1165 ScopedVector<autofill::PasswordForm> forms_scopedvector; 1161 bool success = StatementToForms(&s, nullptr, forms);
1166 bool success = StatementToForms(&s, nullptr, &forms_scopedvector); 1162 if (success)
1167 if (success) {
1168 *forms = password_manager_util::ConvertScopedVector(
1169 std::move(forms_scopedvector));
1170 return true; 1163 return true;
1171 }
1172 forms->clear(); 1164 forms->clear();
1173 return false; 1165 return false;
1174 } 1166 }
1175 1167
1176 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { 1168 bool LoginDatabase::DeleteAndRecreateDatabaseFile() {
1177 DCHECK(db_.is_open()); 1169 DCHECK(db_.is_open());
1178 meta_table_.Reset(); 1170 meta_table_.Reset();
1179 db_.Close(); 1171 db_.Close();
1180 sql::Connection::Delete(db_path_); 1172 sql::Connection::Delete(db_path_);
1181 return Init(); 1173 return Init();
1182 } 1174 }
1183 1175
1184 std::string LoginDatabase::GetEncryptedPassword( 1176 std::string LoginDatabase::GetEncryptedPassword(
1185 const autofill::PasswordForm& form) const { 1177 const PasswordForm& form) const {
1186 DCHECK(!encrypted_statement_.empty()); 1178 DCHECK(!encrypted_statement_.empty());
1187 sql::Statement s( 1179 sql::Statement s(
1188 db_.GetCachedStatement(SQL_FROM_HERE, encrypted_statement_.c_str())); 1180 db_.GetCachedStatement(SQL_FROM_HERE, encrypted_statement_.c_str()));
1189 1181
1190 s.BindString(0, form.origin.spec()); 1182 s.BindString(0, form.origin.spec());
1191 s.BindString16(1, form.username_element); 1183 s.BindString16(1, form.username_element);
1192 s.BindString16(2, form.username_value); 1184 s.BindString16(2, form.username_value);
1193 s.BindString16(3, form.password_element); 1185 s.BindString16(3, form.password_element);
1194 s.BindString(4, form.signon_realm); 1186 s.BindString(4, form.signon_realm);
1195 1187
1196 std::string encrypted_password; 1188 std::string encrypted_password;
1197 if (s.Step()) { 1189 if (s.Step()) {
1198 s.ColumnBlobAsString(0, &encrypted_password); 1190 s.ColumnBlobAsString(0, &encrypted_password);
1199 } 1191 }
1200 return encrypted_password; 1192 return encrypted_password;
1201 } 1193 }
1202 1194
1203 // static 1195 // static
1204 bool LoginDatabase::StatementToForms( 1196 bool LoginDatabase::StatementToForms(
1205 sql::Statement* statement, 1197 sql::Statement* statement,
1206 const PasswordStore::FormDigest* matched_form, 1198 const PasswordStore::FormDigest* matched_form,
1207 ScopedVector<autofill::PasswordForm>* forms) { 1199 std::vector<std::unique_ptr<PasswordForm>>* forms) {
1208 PSLDomainMatchMetric psl_domain_match_metric = PSL_DOMAIN_MATCH_NONE; 1200 PSLDomainMatchMetric psl_domain_match_metric = PSL_DOMAIN_MATCH_NONE;
1209 1201
1210 forms->clear(); 1202 forms->clear();
1211 while (statement->Step()) { 1203 while (statement->Step()) {
1212 std::unique_ptr<PasswordForm> new_form(new PasswordForm()); 1204 auto new_form = base::MakeUnique<PasswordForm>();
1213 EncryptionResult result = 1205 EncryptionResult result =
1214 InitPasswordFormFromStatement(new_form.get(), *statement); 1206 InitPasswordFormFromStatement(new_form.get(), *statement);
1215 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE) 1207 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE)
1216 return false; 1208 return false;
1217 if (result == ENCRYPTION_RESULT_ITEM_FAILURE) 1209 if (result == ENCRYPTION_RESULT_ITEM_FAILURE)
1218 continue; 1210 continue;
1219 DCHECK_EQ(ENCRYPTION_RESULT_SUCCESS, result); 1211 DCHECK_EQ(ENCRYPTION_RESULT_SUCCESS, result);
1220 if (matched_form && matched_form->signon_realm != new_form->signon_realm) { 1212 if (matched_form && matched_form->signon_realm != new_form->signon_realm) {
1221 if (new_form->scheme != PasswordForm::SCHEME_HTML) 1213 if (new_form->scheme != PasswordForm::SCHEME_HTML)
1222 continue; // Ignore non-HTML matches. 1214 continue; // Ignore non-HTML matches.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 DCHECK(blacklisted_statement_.empty()); 1295 DCHECK(blacklisted_statement_.empty());
1304 blacklisted_statement_ = 1296 blacklisted_statement_ =
1305 "SELECT " + all_column_names + 1297 "SELECT " + all_column_names +
1306 " FROM logins WHERE blacklisted_by_user == ? ORDER BY origin_url"; 1298 " FROM logins WHERE blacklisted_by_user == ? ORDER BY origin_url";
1307 DCHECK(encrypted_statement_.empty()); 1299 DCHECK(encrypted_statement_.empty());
1308 encrypted_statement_ = 1300 encrypted_statement_ =
1309 "SELECT password_value FROM logins WHERE " + all_unique_key_column_names; 1301 "SELECT password_value FROM logins WHERE " + all_unique_key_column_names;
1310 } 1302 }
1311 1303
1312 } // namespace password_manager 1304 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698