Chromium Code Reviews| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins( | 138 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins( |
| 139 const autofill::PasswordForm& form, | 139 const autofill::PasswordForm& form, |
| 140 AuthorizationPromptPolicy prompt_policy) { | 140 AuthorizationPromptPolicy prompt_policy) { |
| 141 CheckMigration(); | 141 CheckMigration(); |
| 142 ScopedVector<autofill::PasswordForm> matched_forms; | 142 ScopedVector<autofill::PasswordForm> matched_forms; |
| 143 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) { | 143 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) { |
| 144 SortLoginsByOrigin(&matched_forms.get()); | 144 SortLoginsByOrigin(&matched_forms.get()); |
| 145 // The native backend may succeed and return no data even while locked, if | 145 // The native backend may succeed and return no data even while locked, if |
| 146 // the query did not match anything stored. So we continue to allow fallback | 146 // the query did not match anything stored. So we continue to allow fallback |
| 147 // until we perform a write operation, or until a read returns actual data. | 147 // until we perform a write operation, or until a read returns actual data. |
| 148 if (matched_forms.size() > 0) | 148 if (!matched_forms.empty()) |
| 149 allow_fallback_ = false; | 149 allow_fallback_ = false; |
| 150 } else if (allow_default_store()) { | 150 return matched_forms.Pass(); |
| 151 DCHECK(matched_forms.empty()); | 151 } |
| 152 if (allow_default_store()) { | |
|
engedy
2015/03/09 13:33:18
nit: -{}
vabr (Chromium)
2015/03/09 17:44:15
Done.
| |
| 152 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); | 153 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); |
| 153 } | 154 } |
| 154 return matched_forms.Pass(); | 155 return ScopedVector<autofill::PasswordForm>(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 void PasswordStoreX::GetAutofillableLoginsImpl( | 158 void PasswordStoreX::GetAutofillableLoginsImpl( |
| 158 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | 159 scoped_ptr<PasswordStore::GetLoginsRequest> request) { |
| 159 CheckMigration(); | 160 CheckMigration(); |
| 160 ScopedVector<autofill::PasswordForm> obtained_forms; | 161 ScopedVector<autofill::PasswordForm> obtained_forms; |
| 161 if (use_native_backend() && | 162 if (use_native_backend() && |
| 162 backend_->GetAutofillableLogins(&obtained_forms)) { | 163 backend_->GetAutofillableLogins(&obtained_forms)) { |
| 163 SortLoginsByOrigin(&obtained_forms.get()); | 164 SortLoginsByOrigin(&obtained_forms.get()); |
| 164 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 165 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 188 } else if (allow_default_store()) { | 189 } else if (allow_default_store()) { |
| 189 PasswordStoreDefault::GetBlacklistLoginsImpl(request.Pass()); | 190 PasswordStoreDefault::GetBlacklistLoginsImpl(request.Pass()); |
| 190 return; | 191 return; |
| 191 } | 192 } |
| 192 // The consumer will be left hanging unless we reply. | 193 // The consumer will be left hanging unless we reply. |
| 193 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); | 194 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 bool PasswordStoreX::FillAutofillableLogins( | 197 bool PasswordStoreX::FillAutofillableLogins( |
| 197 ScopedVector<autofill::PasswordForm>* forms) { | 198 ScopedVector<autofill::PasswordForm>* forms) { |
| 199 forms->clear(); | |
| 198 CheckMigration(); | 200 CheckMigration(); |
| 199 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { | 201 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { |
| 200 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 202 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| 201 if (forms->size() > 0) | 203 if (forms->size() > 0) |
| 202 allow_fallback_ = false; | 204 allow_fallback_ = false; |
| 203 return true; | 205 return true; |
| 204 } | 206 } |
| 205 if (allow_default_store()) | 207 if (allow_default_store()) |
| 206 return PasswordStoreDefault::FillAutofillableLogins(forms); | 208 return PasswordStoreDefault::FillAutofillableLogins(forms); |
| 207 return false; | 209 return false; |
| 208 } | 210 } |
| 209 | 211 |
| 210 bool PasswordStoreX::FillBlacklistLogins( | 212 bool PasswordStoreX::FillBlacklistLogins( |
| 211 ScopedVector<autofill::PasswordForm>* forms) { | 213 ScopedVector<autofill::PasswordForm>* forms) { |
| 214 forms->clear(); | |
| 212 CheckMigration(); | 215 CheckMigration(); |
| 213 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { | 216 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { |
| 214 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 217 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| 215 if (forms->size() > 0) | 218 if (forms->size() > 0) |
| 216 allow_fallback_ = false; | 219 allow_fallback_ = false; |
| 217 return true; | 220 return true; |
| 218 } | 221 } |
| 219 if (allow_default_store()) | 222 if (allow_default_store()) |
| 220 return PasswordStoreDefault::FillBlacklistLogins(forms); | 223 return PasswordStoreDefault::FillBlacklistLogins(forms); |
| 221 return false; | 224 return false; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 250 backend_.reset(); | 253 backend_.reset(); |
| 251 // Don't warn again. We'll use the default store because backend_ is NULL. | 254 // Don't warn again. We'll use the default store because backend_ is NULL. |
| 252 allow_fallback_ = false; | 255 allow_fallback_ = false; |
| 253 } | 256 } |
| 254 return !backend_.get(); | 257 return !backend_.get(); |
| 255 } | 258 } |
| 256 | 259 |
| 257 ssize_t PasswordStoreX::MigrateLogins() { | 260 ssize_t PasswordStoreX::MigrateLogins() { |
| 258 DCHECK(backend_.get()); | 261 DCHECK(backend_.get()); |
| 259 ScopedVector<autofill::PasswordForm> forms; | 262 ScopedVector<autofill::PasswordForm> forms; |
| 263 ScopedVector<autofill::PasswordForm> blacklist_forms; | |
| 260 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && | 264 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && |
| 261 PasswordStoreDefault::FillBlacklistLogins(&forms); | 265 PasswordStoreDefault::FillBlacklistLogins(&blacklist_forms); |
| 266 forms.reserve(forms.size() + blacklist_forms.size()); | |
| 267 forms.insert(forms.end(), blacklist_forms.begin(), blacklist_forms.end()); | |
| 268 blacklist_forms.weak_clear(); | |
| 262 if (ok) { | 269 if (ok) { |
| 263 // We add all the passwords (and blacklist entries) to the native backend | 270 // We add all the passwords (and blacklist entries) to the native backend |
| 264 // before attempting to remove any from the login database, to make sure we | 271 // before attempting to remove any from the login database, to make sure we |
| 265 // don't somehow end up with some of the passwords in one store and some in | 272 // don't somehow end up with some of the passwords in one store and some in |
| 266 // another. We'll always have at least one intact store this way. | 273 // another. We'll always have at least one intact store this way. |
| 267 for (size_t i = 0; i < forms.size(); ++i) { | 274 for (size_t i = 0; i < forms.size(); ++i) { |
| 268 PasswordStoreChangeList changes; | 275 PasswordStoreChangeList changes; |
| 269 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { | 276 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { |
| 270 ok = false; | 277 ok = false; |
| 271 break; | 278 break; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 284 // Finally, delete the database file itself. We remove the passwords from | 291 // Finally, delete the database file itself. We remove the passwords from |
| 285 // it before deleting the file just in case there is some problem deleting | 292 // it before deleting the file just in case there is some problem deleting |
| 286 // the file (e.g. directory is not writable, but file is), which would | 293 // the file (e.g. directory is not writable, but file is), which would |
| 287 // otherwise cause passwords to re-migrate next (or maybe every) time. | 294 // otherwise cause passwords to re-migrate next (or maybe every) time. |
| 288 DeleteAndRecreateDatabaseFile(); | 295 DeleteAndRecreateDatabaseFile(); |
| 289 } | 296 } |
| 290 } | 297 } |
| 291 ssize_t result = ok ? forms.size() : -1; | 298 ssize_t result = ok ? forms.size() : -1; |
| 292 return result; | 299 return result; |
| 293 } | 300 } |
| OLD | NEW |