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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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.size() > 0) |
| 149 allow_fallback_ = false; | 149 allow_fallback_ = false; |
| 150 } else if (allow_default_store()) { | 150 } else if (allow_default_store()) { |
| 151 DCHECK(matched_forms.empty()); | 151 DCHECK(matched_forms.empty()); |
| 152 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); | 152 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); |
| 153 } | 153 } |
| 154 return matched_forms.Pass(); | 154 return matched_forms.Pass(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void PasswordStoreX::GetAutofillableLoginsImpl( | 157 void PasswordStoreX::GetAutofillableLoginsImpl( |
|
engedy
2015/02/25 15:17:48
Do we override the base class implementation for t
vabr (Chromium)
2015/03/09 10:56:19
This sounds very reasonable.
I propose to do it in
engedy
2015/03/09 13:33:17
Acknowledged.
| |
| 158 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | 158 scoped_ptr<PasswordStore::GetLoginsRequest> request) { |
| 159 CheckMigration(); | 159 CheckMigration(); |
| 160 ScopedVector<autofill::PasswordForm> obtained_forms; | 160 ScopedVector<autofill::PasswordForm> obtained_forms; |
| 161 if (use_native_backend() && | 161 if (use_native_backend() && |
| 162 backend_->GetAutofillableLogins(&obtained_forms)) { | 162 backend_->GetAutofillableLogins(&obtained_forms)) { |
| 163 SortLoginsByOrigin(&obtained_forms.get()); | 163 SortLoginsByOrigin(&obtained_forms.get()); |
| 164 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 164 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| 165 if (!obtained_forms.empty()) | 165 if (!obtained_forms.empty()) |
| 166 allow_fallback_ = false; | 166 allow_fallback_ = false; |
| 167 request->NotifyConsumerWithResults(obtained_forms.Pass()); | 167 request->NotifyConsumerWithResults(obtained_forms.Pass()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 188 } else if (allow_default_store()) { | 188 } else if (allow_default_store()) { |
| 189 PasswordStoreDefault::GetBlacklistLoginsImpl(request.Pass()); | 189 PasswordStoreDefault::GetBlacklistLoginsImpl(request.Pass()); |
| 190 return; | 190 return; |
| 191 } | 191 } |
| 192 // The consumer will be left hanging unless we reply. | 192 // The consumer will be left hanging unless we reply. |
| 193 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); | 193 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 bool PasswordStoreX::FillAutofillableLogins( | 196 bool PasswordStoreX::FillAutofillableLogins( |
| 197 ScopedVector<autofill::PasswordForm>* forms) { | 197 ScopedVector<autofill::PasswordForm>* forms) { |
| 198 CheckMigration(); | 198 CheckMigration(); |
|
engedy
2015/02/25 15:17:48
Need to clear |forms| here.
vabr (Chromium)
2015/03/09 10:56:19
Done.
| |
| 199 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { | 199 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { |
| 200 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 200 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| 201 if (forms->size() > 0) | 201 if (forms->size() > 0) |
| 202 allow_fallback_ = false; | 202 allow_fallback_ = false; |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 if (allow_default_store()) | 205 if (allow_default_store()) |
| 206 return PasswordStoreDefault::FillAutofillableLogins(forms); | 206 return PasswordStoreDefault::FillAutofillableLogins(forms); |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool PasswordStoreX::FillBlacklistLogins( | 210 bool PasswordStoreX::FillBlacklistLogins( |
| 211 ScopedVector<autofill::PasswordForm>* forms) { | 211 ScopedVector<autofill::PasswordForm>* forms) { |
| 212 CheckMigration(); | 212 CheckMigration(); |
|
engedy
2015/02/25 15:17:48
Need to clear |forms| here.
vabr (Chromium)
2015/03/09 10:56:19
Done.
| |
| 213 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { | 213 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { |
| 214 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 214 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
| 215 if (forms->size() > 0) | 215 if (forms->size() > 0) |
| 216 allow_fallback_ = false; | 216 allow_fallback_ = false; |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| 219 if (allow_default_store()) | 219 if (allow_default_store()) |
| 220 return PasswordStoreDefault::FillBlacklistLogins(forms); | 220 return PasswordStoreDefault::FillBlacklistLogins(forms); |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 250 backend_.reset(); | 250 backend_.reset(); |
| 251 // Don't warn again. We'll use the default store because backend_ is NULL. | 251 // Don't warn again. We'll use the default store because backend_ is NULL. |
| 252 allow_fallback_ = false; | 252 allow_fallback_ = false; |
| 253 } | 253 } |
| 254 return !backend_.get(); | 254 return !backend_.get(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 ssize_t PasswordStoreX::MigrateLogins() { | 257 ssize_t PasswordStoreX::MigrateLogins() { |
| 258 DCHECK(backend_.get()); | 258 DCHECK(backend_.get()); |
| 259 ScopedVector<autofill::PasswordForm> forms; | 259 ScopedVector<autofill::PasswordForm> forms; |
| 260 ScopedVector<autofill::PasswordForm> blacklist_forms; | |
| 260 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && | 261 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && |
| 261 PasswordStoreDefault::FillBlacklistLogins(&forms); | 262 PasswordStoreDefault::FillBlacklistLogins(&blacklist_forms); |
| 263 forms.reserve(forms.size() + blacklist_forms.size()); | |
| 264 forms.insert(forms.end(), blacklist_forms.begin(), blacklist_forms.end()); | |
| 265 blacklist_forms.weak_clear(); | |
| 262 if (ok) { | 266 if (ok) { |
| 263 // We add all the passwords (and blacklist entries) to the native backend | 267 // 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 | 268 // 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 | 269 // 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. | 270 // another. We'll always have at least one intact store this way. |
| 267 for (size_t i = 0; i < forms.size(); ++i) { | 271 for (size_t i = 0; i < forms.size(); ++i) { |
| 268 PasswordStoreChangeList changes; | 272 PasswordStoreChangeList changes; |
| 269 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { | 273 if (!AddLoginToBackend(backend_, *forms[i], &changes)) { |
| 270 ok = false; | 274 ok = false; |
| 271 break; | 275 break; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 284 // Finally, delete the database file itself. We remove the passwords from | 288 // 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 | 289 // 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 | 290 // 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. | 291 // otherwise cause passwords to re-migrate next (or maybe every) time. |
| 288 DeleteAndRecreateDatabaseFile(); | 292 DeleteAndRecreateDatabaseFile(); |
| 289 } | 293 } |
| 290 } | 294 } |
| 291 ssize_t result = ok ? forms.size() : -1; | 295 ssize_t result = ok ? forms.size() : -1; |
| 292 return result; | 296 return result; |
| 293 } | 297 } |
| OLD | NEW |