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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 LogStatsForBulkDeletionDuringRollback(changes.size()); | 115 LogStatsForBulkDeletionDuringRollback(changes.size()); |
116 allow_fallback_ = false; | 116 allow_fallback_ = false; |
117 } else if (allow_default_store()) { | 117 } else if (allow_default_store()) { |
118 changes = PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl(delete_begin, | 118 changes = PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl(delete_begin, |
119 delete_end); | 119 delete_end); |
120 } | 120 } |
121 return changes; | 121 return changes; |
122 } | 122 } |
123 | 123 |
124 namespace { | 124 namespace { |
| 125 |
125 struct LoginLessThan { | 126 struct LoginLessThan { |
126 bool operator()(const PasswordForm* a, const PasswordForm* b) { | 127 bool operator()(const PasswordForm* a, const PasswordForm* b) { |
127 return a->origin < b->origin; | 128 return a->origin < b->origin; |
128 } | 129 } |
129 }; | 130 }; |
130 } // anonymous namespace | |
131 | 131 |
132 void PasswordStoreX::SortLoginsByOrigin( | 132 // Sorts |list| by origin, like the ORDER BY clause in login_database.cc. |
133 std::vector<autofill::PasswordForm*>* list) { | 133 void SortLoginsByOrigin(std::vector<autofill::PasswordForm*>* list) { |
134 // In login_database.cc, the query has ORDER BY origin_url. Simulate that. | |
135 std::sort(list->begin(), list->end(), LoginLessThan()); | 134 std::sort(list->begin(), list->end(), LoginLessThan()); |
136 } | 135 } |
137 | 136 |
| 137 } // anonymous namespace |
| 138 |
138 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins( | 139 ScopedVector<autofill::PasswordForm> PasswordStoreX::FillMatchingLogins( |
139 const autofill::PasswordForm& form, | 140 const autofill::PasswordForm& form, |
140 AuthorizationPromptPolicy prompt_policy) { | 141 AuthorizationPromptPolicy prompt_policy) { |
141 CheckMigration(); | 142 CheckMigration(); |
142 ScopedVector<autofill::PasswordForm> matched_forms; | 143 ScopedVector<autofill::PasswordForm> matched_forms; |
143 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) { | 144 if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) { |
144 SortLoginsByOrigin(&matched_forms.get()); | 145 SortLoginsByOrigin(&matched_forms.get()); |
145 // 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 |
146 // 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 |
147 // 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. |
148 if (matched_forms.size() > 0) | 149 if (matched_forms.size() > 0) |
149 allow_fallback_ = false; | 150 allow_fallback_ = false; |
150 } else if (allow_default_store()) { | 151 } else if (allow_default_store()) { |
151 DCHECK(matched_forms.empty()); | 152 DCHECK(matched_forms.empty()); |
152 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); | 153 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); |
153 } | 154 } |
154 return matched_forms.Pass(); | 155 return matched_forms.Pass(); |
155 } | 156 } |
156 | 157 |
157 void PasswordStoreX::GetAutofillableLoginsImpl( | |
158 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | |
159 CheckMigration(); | |
160 ScopedVector<autofill::PasswordForm> obtained_forms; | |
161 if (use_native_backend() && | |
162 backend_->GetAutofillableLogins(&obtained_forms)) { | |
163 SortLoginsByOrigin(&obtained_forms.get()); | |
164 // See GetLoginsImpl() for why we disallow fallback conditionally here. | |
165 if (!obtained_forms.empty()) | |
166 allow_fallback_ = false; | |
167 request->NotifyConsumerWithResults(obtained_forms.Pass()); | |
168 return; | |
169 } else if (allow_default_store()) { | |
170 PasswordStoreDefault::GetAutofillableLoginsImpl(request.Pass()); | |
171 return; | |
172 } | |
173 // The consumer will be left hanging unless we reply. | |
174 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); | |
175 } | |
176 | |
177 void PasswordStoreX::GetBlacklistLoginsImpl( | |
178 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | |
179 CheckMigration(); | |
180 ScopedVector<autofill::PasswordForm> obtained_forms; | |
181 if (use_native_backend() && backend_->GetBlacklistLogins(&obtained_forms)) { | |
182 SortLoginsByOrigin(&obtained_forms.get()); | |
183 // See GetLoginsImpl() for why we disallow fallback conditionally here. | |
184 if (!obtained_forms.empty()) | |
185 allow_fallback_ = false; | |
186 request->NotifyConsumerWithResults(obtained_forms.Pass()); | |
187 return; | |
188 } else if (allow_default_store()) { | |
189 PasswordStoreDefault::GetBlacklistLoginsImpl(request.Pass()); | |
190 return; | |
191 } | |
192 // The consumer will be left hanging unless we reply. | |
193 request->NotifyConsumerWithResults(ScopedVector<autofill::PasswordForm>()); | |
194 } | |
195 | |
196 bool PasswordStoreX::FillAutofillableLogins( | 158 bool PasswordStoreX::FillAutofillableLogins( |
197 ScopedVector<autofill::PasswordForm>* forms) { | 159 ScopedVector<autofill::PasswordForm>* forms) { |
198 CheckMigration(); | 160 CheckMigration(); |
199 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { | 161 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { |
| 162 SortLoginsByOrigin(&forms->get()); |
200 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 163 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
201 if (forms->size() > 0) | 164 if (!forms->empty()) |
202 allow_fallback_ = false; | 165 allow_fallback_ = false; |
203 return true; | 166 return true; |
204 } | 167 } |
205 if (allow_default_store()) | 168 if (allow_default_store()) |
206 return PasswordStoreDefault::FillAutofillableLogins(forms); | 169 return PasswordStoreDefault::FillAutofillableLogins(forms); |
207 return false; | 170 return false; |
208 } | 171 } |
209 | 172 |
210 bool PasswordStoreX::FillBlacklistLogins( | 173 bool PasswordStoreX::FillBlacklistLogins( |
211 ScopedVector<autofill::PasswordForm>* forms) { | 174 ScopedVector<autofill::PasswordForm>* forms) { |
212 CheckMigration(); | 175 CheckMigration(); |
213 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { | 176 if (use_native_backend() && backend_->GetBlacklistLogins(forms)) { |
214 // See GetLoginsImpl() for why we disallow fallback conditionally here. | 177 // See GetLoginsImpl() for why we disallow fallback conditionally here. |
215 if (forms->size() > 0) | 178 SortLoginsByOrigin(&forms->get()); |
| 179 if (!forms->empty()) |
216 allow_fallback_ = false; | 180 allow_fallback_ = false; |
217 return true; | 181 return true; |
218 } | 182 } |
219 if (allow_default_store()) | 183 if (allow_default_store()) |
220 return PasswordStoreDefault::FillBlacklistLogins(forms); | 184 return PasswordStoreDefault::FillBlacklistLogins(forms); |
221 return false; | 185 return false; |
222 } | 186 } |
223 | 187 |
224 void PasswordStoreX::CheckMigration() { | 188 void PasswordStoreX::CheckMigration() { |
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // Finally, delete the database file itself. We remove the passwords from | 248 // 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 | 249 // 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 | 250 // 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. | 251 // otherwise cause passwords to re-migrate next (or maybe every) time. |
288 DeleteAndRecreateDatabaseFile(); | 252 DeleteAndRecreateDatabaseFile(); |
289 } | 253 } |
290 } | 254 } |
291 ssize_t result = ok ? forms.size() : -1; | 255 ssize_t result = ok ? forms.size() : -1; |
292 return result; | 256 return result; |
293 } | 257 } |
OLD | NEW |