OLD | NEW |
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 Loading... |
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 CheckMigration(); | 160 CheckMigration(); |
161 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { | 161 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { |
162 SortLoginsByOrigin(&forms->get()); | 162 SortLoginsByOrigin(&forms->get()); |
163 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 163 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
164 if (!forms->empty()) | 164 if (!forms->empty()) |
165 allow_fallback_ = false; | 165 allow_fallback_ = false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 backend_.reset(); | 214 backend_.reset(); |
215 // Don't warn again. We'll use the default store because backend_ is NULL. | 215 // Don't warn again. We'll use the default store because backend_ is NULL. |
216 allow_fallback_ = false; | 216 allow_fallback_ = false; |
217 } | 217 } |
218 return !backend_.get(); | 218 return !backend_.get(); |
219 } | 219 } |
220 | 220 |
221 ssize_t PasswordStoreX::MigrateLogins() { | 221 ssize_t PasswordStoreX::MigrateLogins() { |
222 DCHECK(backend_.get()); | 222 DCHECK(backend_.get()); |
223 ScopedVector<autofill::PasswordForm> forms; | 223 ScopedVector<autofill::PasswordForm> forms; |
| 224 ScopedVector<autofill::PasswordForm> blacklist_forms; |
224 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && | 225 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && |
225 PasswordStoreDefault::FillBlacklistLogins(&forms); | 226 PasswordStoreDefault::FillBlacklistLogins(&blacklist_forms); |
| 227 forms.reserve(forms.size() + blacklist_forms.size()); |
| 228 forms.insert(forms.end(), blacklist_forms.begin(), blacklist_forms.end()); |
| 229 blacklist_forms.weak_clear(); |
226 if (ok) { | 230 if (ok) { |
227 // We add all the passwords (and blacklist entries) to the native backend | 231 // 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 | 232 // 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 | 233 // 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. | 234 // another. We'll always have at least one intact store this way. |
231 for (size_t i = 0; i < forms.size(); ++i) { | 235 for (size_t i = 0; i < forms.size(); ++i) { |
232 PasswordStoreChangeList changes; | 236 PasswordStoreChangeList changes; |
233 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { | 237 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { |
234 ok = false; | 238 ok = false; |
235 break; | 239 break; |
(...skipping 12 matching lines...) Expand all Loading... |
248 // Finally, delete the database file itself. We remove the passwords from | 252 // 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 | 253 // 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 | 254 // 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. | 255 // otherwise cause passwords to re-migrate next (or maybe every) time. |
252 DeleteAndRecreateDatabaseFile(); | 256 DeleteAndRecreateDatabaseFile(); |
253 } | 257 } |
254 } | 258 } |
255 ssize_t result = ok ? forms.size() : -1; | 259 ssize_t result = ok ? forms.size() : -1; |
256 return result; | 260 return result; |
257 } | 261 } |
OLD | NEW |