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

Side by Side Diff: chrome/browser/password_manager/password_store_x.cc

Issue 2565173002: Remove ScopedVector from PasswordStoreX (Closed)
Patch Set: back_inserter, no =nullptr, drop autofill:: 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 (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/password_store_x.h" 5 #include "chrome/browser/password_manager/password_store_x.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 return (!changes->empty() && 37 return (!changes->empty() &&
38 changes->back().type() == PasswordStoreChange::ADD); 38 changes->back().type() == PasswordStoreChange::ADD);
39 } 39 }
40 40
41 bool RemoveLoginsByURLAndTimeFromBackend( 41 bool RemoveLoginsByURLAndTimeFromBackend(
42 PasswordStoreX::NativeBackend* backend, 42 PasswordStoreX::NativeBackend* backend,
43 const base::Callback<bool(const GURL&)>& url_filter, 43 const base::Callback<bool(const GURL&)>& url_filter,
44 base::Time delete_begin, 44 base::Time delete_begin,
45 base::Time delete_end, 45 base::Time delete_end,
46 PasswordStoreChangeList* changes) { 46 PasswordStoreChangeList* changes) {
47 ScopedVector<autofill::PasswordForm> forms; 47 std::vector<std::unique_ptr<PasswordForm>> forms;
48 if (!backend->GetAllLogins(&forms)) 48 if (!backend->GetAllLogins(&forms))
49 return false; 49 return false;
50 50
51 for (const autofill::PasswordForm* form : forms) { 51 for (const auto& form : forms) {
52 if (url_filter.Run(form->origin) && form->date_created >= delete_begin && 52 if (url_filter.Run(form->origin) && form->date_created >= delete_begin &&
53 (delete_end.is_null() || form->date_created < delete_end) && 53 (delete_end.is_null() || form->date_created < delete_end) &&
54 !backend->RemoveLogin(*form, changes)) 54 !backend->RemoveLogin(*form, changes))
55 return false; 55 return false;
56 } 56 }
57 57
58 return true; 58 return true;
59 } 59 }
60 60
61 } // namespace 61 } // namespace
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 const std::unique_ptr<PasswordForm>& b) { 185 const std::unique_ptr<PasswordForm>& b) {
186 return a->origin < b->origin; 186 return a->origin < b->origin;
187 }); 187 });
188 } 188 }
189 189
190 } // anonymous namespace 190 } // anonymous namespace
191 191
192 std::vector<std::unique_ptr<PasswordForm>> PasswordStoreX::FillMatchingLogins( 192 std::vector<std::unique_ptr<PasswordForm>> PasswordStoreX::FillMatchingLogins(
193 const FormDigest& form) { 193 const FormDigest& form) {
194 CheckMigration(); 194 CheckMigration();
195 ScopedVector<autofill::PasswordForm> matched_forms_scopedvector; 195 std::vector<std::unique_ptr<PasswordForm>> matched_forms;
196 if (use_native_backend() && 196 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) {
197 backend_->GetLogins(form, &matched_forms_scopedvector)) {
198 std::vector<std::unique_ptr<PasswordForm>> matched_forms =
199 password_manager_util::ConvertScopedVector(
200 std::move(matched_forms_scopedvector));
201 SortLoginsByOrigin(&matched_forms); 197 SortLoginsByOrigin(&matched_forms);
202 // The native backend may succeed and return no data even while locked, if 198 // The native backend may succeed and return no data even while locked, if
203 // the query did not match anything stored. So we continue to allow fallback 199 // the query did not match anything stored. So we continue to allow fallback
204 // until we perform a write operation, or until a read returns actual data. 200 // until we perform a write operation, or until a read returns actual data.
205 if (!matched_forms.empty()) 201 if (!matched_forms.empty())
206 allow_fallback_ = false; 202 allow_fallback_ = false;
207 return matched_forms; 203 return matched_forms;
208 } 204 }
209 if (allow_default_store()) 205 if (allow_default_store())
210 return PasswordStoreDefault::FillMatchingLogins(form); 206 return PasswordStoreDefault::FillMatchingLogins(form);
211 return std::vector<std::unique_ptr<PasswordForm>>(); 207 return std::vector<std::unique_ptr<PasswordForm>>();
212 } 208 }
213 209
214 bool PasswordStoreX::FillAutofillableLogins( 210 bool PasswordStoreX::FillAutofillableLogins(
215 std::vector<std::unique_ptr<PasswordForm>>* forms) { 211 std::vector<std::unique_ptr<PasswordForm>>* forms) {
216 CheckMigration(); 212 CheckMigration();
217 ScopedVector<autofill::PasswordForm> forms_scopedvector; 213 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) {
218 if (use_native_backend() &&
219 backend_->GetAutofillableLogins(&forms_scopedvector)) {
220 *forms = password_manager_util::ConvertScopedVector(
221 std::move(forms_scopedvector));
222 SortLoginsByOrigin(forms); 214 SortLoginsByOrigin(forms);
223 // See GetLoginsImpl() for why we disallow fallback conditionally here. 215 // See GetLoginsImpl() for why we disallow fallback conditionally here.
224 if (!forms->empty()) 216 if (!forms->empty())
225 allow_fallback_ = false; 217 allow_fallback_ = false;
226 return true; 218 return true;
227 } 219 }
228 if (allow_default_store()) 220 if (allow_default_store())
229 return PasswordStoreDefault::FillAutofillableLogins(forms); 221 return PasswordStoreDefault::FillAutofillableLogins(forms);
230 return false; 222 return false;
231 } 223 }
232 224
233 bool PasswordStoreX::FillBlacklistLogins( 225 bool PasswordStoreX::FillBlacklistLogins(
234 std::vector<std::unique_ptr<PasswordForm>>* forms) { 226 std::vector<std::unique_ptr<PasswordForm>>* forms) {
235 CheckMigration(); 227 CheckMigration();
236 ScopedVector<autofill::PasswordForm> forms_scopedvector; 228 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) {
237 if (use_native_backend() &&
238 backend_->GetBlacklistLogins(&forms_scopedvector)) {
239 *forms = password_manager_util::ConvertScopedVector(
240 std::move(forms_scopedvector));
241 // See GetLoginsImpl() for why we disallow fallback conditionally here. 229 // See GetLoginsImpl() for why we disallow fallback conditionally here.
242 SortLoginsByOrigin(forms); 230 SortLoginsByOrigin(forms);
243 if (!forms->empty()) 231 if (!forms->empty())
244 allow_fallback_ = false; 232 allow_fallback_ = false;
245 return true; 233 return true;
246 } 234 }
247 if (allow_default_store()) 235 if (allow_default_store())
248 return PasswordStoreDefault::FillBlacklistLogins(forms); 236 return PasswordStoreDefault::FillBlacklistLogins(forms);
249 return false; 237 return false;
250 } 238 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // Finally, delete the database file itself. We remove the passwords from 305 // Finally, delete the database file itself. We remove the passwords from
318 // it before deleting the file just in case there is some problem deleting 306 // it before deleting the file just in case there is some problem deleting
319 // the file (e.g. directory is not writable, but file is), which would 307 // the file (e.g. directory is not writable, but file is), which would
320 // otherwise cause passwords to re-migrate next (or maybe every) time. 308 // otherwise cause passwords to re-migrate next (or maybe every) time.
321 DeleteAndRecreateDatabaseFile(); 309 DeleteAndRecreateDatabaseFile();
322 } 310 }
323 } 311 }
324 ssize_t result = ok ? forms.size() : -1; 312 ssize_t result = ok ? forms.size() : -1;
325 return result; 313 return result;
326 } 314 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_x.h ('k') | chrome/browser/password_manager/password_store_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698