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

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

Issue 906973007: PasswordStore: Clean up expectations about rewriting vectors of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed, except for dropping clear() (yet) Created 5 years, 9 months 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 <vector> 9 #include <vector>
10 10
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins( 139 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins(
140 const autofill::PasswordForm& form, 140 const autofill::PasswordForm& form,
141 AuthorizationPromptPolicy prompt_policy) { 141 AuthorizationPromptPolicy prompt_policy) {
142 CheckMigration(); 142 CheckMigration();
143 ScopedVector<autofill::PasswordForm> matched_forms; 143 ScopedVector<autofill::PasswordForm> matched_forms;
144 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) { 144 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) {
145 SortLoginsByOrigin(&matched_forms.get()); 145 SortLoginsByOrigin(&matched_forms.get());
146 // The native backend may succeed and return no data even while locked, if 146 // The native backend may succeed and return no data even while locked, if
147 // the query did not match anything stored. So we continue to allow fallback 147 // the query did not match anything stored. So we continue to allow fallback
148 // until we perform a write operation, or until a read returns actual data. 148 // until we perform a write operation, or until a read returns actual data.
149 if (matched_forms.size() > 0) 149 if (!matched_forms.empty())
150 allow_fallback_ = false; 150 allow_fallback_ = false;
151 } else if (allow_default_store()) { 151 return matched_forms.Pass();
152 DCHECK(matched_forms.empty()); 152 }
153 if (allow_default_store())
153 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); 154 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy);
154 } 155 return ScopedVector<autofill::PasswordForm>();
155 return matched_forms.Pass();
156 } 156 }
157 157
158 bool PasswordStoreX::FillAutofillableLogins( 158 bool PasswordStoreX::FillAutofillableLogins(
159 ScopedVector<autofill::PasswordForm>* forms) { 159 ScopedVector<autofill::PasswordForm>* forms) {
160 forms->clear();
160 CheckMigration(); 161 CheckMigration();
161 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { 162 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) {
162 SortLoginsByOrigin(&forms->get()); 163 SortLoginsByOrigin(&forms->get());
163 // See GetLoginsImpl() for why we disallow fallback conditionally here. 164 // See GetLoginsImpl() for why we disallow fallback conditionally here.
164 if (!forms->empty()) 165 if (!forms->empty())
165 allow_fallback_ = false; 166 allow_fallback_ = false;
166 return true; 167 return true;
167 } 168 }
168 if (allow_default_store()) 169 if (allow_default_store())
169 return PasswordStoreDefault::FillAutofillableLogins(forms); 170 return PasswordStoreDefault::FillAutofillableLogins(forms);
170 return false; 171 return false;
171 } 172 }
172 173
173 bool PasswordStoreX::FillBlacklistLogins( 174 bool PasswordStoreX::FillBlacklistLogins(
174 ScopedVector<autofill::PasswordForm>* forms) { 175 ScopedVector<autofill::PasswordForm>* forms) {
176 forms->clear();
175 CheckMigration(); 177 CheckMigration();
176 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { 178 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) {
177 // See GetLoginsImpl() for why we disallow fallback conditionally here. 179 // See GetLoginsImpl() for why we disallow fallback conditionally here.
178 SortLoginsByOrigin(&forms->get()); 180 SortLoginsByOrigin(&forms->get());
179 if (!forms->empty()) 181 if (!forms->empty())
180 allow_fallback_ = false; 182 allow_fallback_ = false;
181 return true; 183 return true;
182 } 184 }
183 if (allow_default_store()) 185 if (allow_default_store())
184 return PasswordStoreDefault::FillBlacklistLogins(forms); 186 return PasswordStoreDefault::FillBlacklistLogins(forms);
(...skipping 29 matching lines...) Expand all
214 backend_.reset(); 216 backend_.reset();
215 // Don't warn again. We'll use the default store because backend_ is NULL. 217 // Don't warn again. We'll use the default store because backend_ is NULL.
216 allow_fallback_ = false; 218 allow_fallback_ = false;
217 } 219 }
218 return !backend_.get(); 220 return !backend_.get();
219 } 221 }
220 222
221 ssize_t PasswordStoreX::MigrateLogins() { 223 ssize_t PasswordStoreX::MigrateLogins() {
222 DCHECK(backend_.get()); 224 DCHECK(backend_.get());
223 ScopedVector<autofill::PasswordForm> forms; 225 ScopedVector<autofill::PasswordForm> forms;
226 ScopedVector<autofill::PasswordForm> blacklist_forms;
224 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && 227 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) &&
225 PasswordStoreDefault::FillBlacklistLogins(&forms); 228 PasswordStoreDefault::FillBlacklistLogins(&blacklist_forms);
229 forms.reserve(forms.size() + blacklist_forms.size());
230 forms.insert(forms.end(), blacklist_forms.begin(), blacklist_forms.end());
231 blacklist_forms.weak_clear();
226 if (ok) { 232 if (ok) {
227 // We add all the passwords (and blacklist entries) to the native backend 233 // We add all the passwords (and blacklist entries) to the native backend
228 // before attempting to remove any from the login database, to make sure we 234 // before attempting to remove any from the login database, to make sure we
229 // don't somehow end up with some of the passwords in one store and some in 235 // don't somehow end up with some of the passwords in one store and some in
230 // another. We'll always have at least one intact store this way. 236 // another. We'll always have at least one intact store this way.
231 for (size_t i = 0; i < forms.size(); ++i) { 237 for (size_t i = 0; i < forms.size(); ++i) {
232 PasswordStoreChangeList changes; 238 PasswordStoreChangeList changes;
233 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { 239 if (!AddLoginToBackend(backend_, *forms[i], &changes)) {
234 ok = false; 240 ok = false;
235 break; 241 break;
(...skipping 12 matching lines...) Expand all
248 // Finally, delete the database file itself. We remove the passwords from 254 // Finally, delete the database file itself. We remove the passwords from
249 // it before deleting the file just in case there is some problem deleting 255 // it before deleting the file just in case there is some problem deleting
250 // the file (e.g. directory is not writable, but file is), which would 256 // the file (e.g. directory is not writable, but file is), which would
251 // otherwise cause passwords to re-migrate next (or maybe every) time. 257 // otherwise cause passwords to re-migrate next (or maybe every) time.
252 DeleteAndRecreateDatabaseFile(); 258 DeleteAndRecreateDatabaseFile();
253 } 259 }
254 } 260 }
255 ssize_t result = ok ? forms.size() : -1; 261 ssize_t result = ok ? forms.size() : -1;
256 return result; 262 return result;
257 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698