| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 8 #include <map> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
| 12 #include "chrome/browser/password_manager/password_store_change.h" | 13 #include "chrome/browser/password_manager/password_store_change.h" |
| 13 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 14 #include "content/common/notification_service.h" | 15 #include "content/common/notification_service.h" |
| 15 | 16 |
| 16 using std::vector; | 17 using std::vector; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 Source<PasswordStore>(this), | 92 Source<PasswordStore>(this), |
| 92 Details<PasswordStoreChangeList>(&changes)); | 93 Details<PasswordStoreChangeList>(&changes)); |
| 93 allow_fallback_ = false; | 94 allow_fallback_ = false; |
| 94 } else if (allow_default_store()) { | 95 } else if (allow_default_store()) { |
| 95 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, | 96 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, |
| 96 delete_end); | 97 delete_end); |
| 97 } | 98 } |
| 98 STLDeleteElements(&forms); | 99 STLDeleteElements(&forms); |
| 99 } | 100 } |
| 100 | 101 |
| 102 namespace { |
| 103 struct LoginLessThan { |
| 104 bool operator()(const PasswordForm* a, const PasswordForm* b) { |
| 105 return a->origin < b->origin; |
| 106 } |
| 107 }; |
| 108 } // anonymous namespace |
| 109 |
| 110 void PasswordStoreX::SortLoginsByOrigin(NativeBackend::PasswordFormList* list) { |
| 111 // In login_database.cc, the query has ORDER BY origin_url. Simulate that. |
| 112 std::sort(list->begin(), list->end(), LoginLessThan()); |
| 113 } |
| 114 |
| 101 void PasswordStoreX::GetLoginsImpl(GetLoginsRequest* request, | 115 void PasswordStoreX::GetLoginsImpl(GetLoginsRequest* request, |
| 102 const PasswordForm& form) { | 116 const PasswordForm& form) { |
| 103 CheckMigration(); | 117 CheckMigration(); |
| 104 if (use_native_backend() && backend_->GetLogins(form, &request->value)) { | 118 if (use_native_backend() && backend_->GetLogins(form, &request->value)) { |
| 119 SortLoginsByOrigin(&request->value); |
| 105 ForwardLoginsResult(request); | 120 ForwardLoginsResult(request); |
| 106 allow_fallback_ = false; | 121 allow_fallback_ = false; |
| 107 } else if (allow_default_store()) { | 122 } else if (allow_default_store()) { |
| 108 PasswordStoreDefault::GetLoginsImpl(request, form); | 123 PasswordStoreDefault::GetLoginsImpl(request, form); |
| 109 } else { | 124 } else { |
| 110 // The consumer will be left hanging unless we reply. | 125 // The consumer will be left hanging unless we reply. |
| 111 ForwardLoginsResult(request); | 126 ForwardLoginsResult(request); |
| 112 } | 127 } |
| 113 } | 128 } |
| 114 | 129 |
| 115 void PasswordStoreX::GetAutofillableLoginsImpl(GetLoginsRequest* request) { | 130 void PasswordStoreX::GetAutofillableLoginsImpl(GetLoginsRequest* request) { |
| 116 CheckMigration(); | 131 CheckMigration(); |
| 117 if (use_native_backend() && | 132 if (use_native_backend() && |
| 118 backend_->GetAutofillableLogins(&request->value)) { | 133 backend_->GetAutofillableLogins(&request->value)) { |
| 134 SortLoginsByOrigin(&request->value); |
| 119 ForwardLoginsResult(request); | 135 ForwardLoginsResult(request); |
| 120 allow_fallback_ = false; | 136 allow_fallback_ = false; |
| 121 } else if (allow_default_store()) { | 137 } else if (allow_default_store()) { |
| 122 PasswordStoreDefault::GetAutofillableLoginsImpl(request); | 138 PasswordStoreDefault::GetAutofillableLoginsImpl(request); |
| 123 } else { | 139 } else { |
| 124 // The consumer will be left hanging unless we reply. | 140 // The consumer will be left hanging unless we reply. |
| 125 ForwardLoginsResult(request); | 141 ForwardLoginsResult(request); |
| 126 } | 142 } |
| 127 } | 143 } |
| 128 | 144 |
| 129 void PasswordStoreX::GetBlacklistLoginsImpl(GetLoginsRequest* request) { | 145 void PasswordStoreX::GetBlacklistLoginsImpl(GetLoginsRequest* request) { |
| 130 CheckMigration(); | 146 CheckMigration(); |
| 131 if (use_native_backend() && | 147 if (use_native_backend() && |
| 132 backend_->GetBlacklistLogins(&request->value)) { | 148 backend_->GetBlacklistLogins(&request->value)) { |
| 149 SortLoginsByOrigin(&request->value); |
| 133 ForwardLoginsResult(request); | 150 ForwardLoginsResult(request); |
| 134 allow_fallback_ = false; | 151 allow_fallback_ = false; |
| 135 } else if (allow_default_store()) { | 152 } else if (allow_default_store()) { |
| 136 PasswordStoreDefault::GetBlacklistLoginsImpl(request); | 153 PasswordStoreDefault::GetBlacklistLoginsImpl(request); |
| 137 } else { | 154 } else { |
| 138 // The consumer will be left hanging unless we reply. | 155 // The consumer will be left hanging unless we reply. |
| 139 ForwardLoginsResult(request); | 156 ForwardLoginsResult(request); |
| 140 } | 157 } |
| 141 } | 158 } |
| 142 | 159 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // it before deleting the file just in case there is some problem deleting | 258 // it before deleting the file just in case there is some problem deleting |
| 242 // the file (e.g. directory is not writable, but file is), which would | 259 // the file (e.g. directory is not writable, but file is), which would |
| 243 // otherwise cause passwords to re-migrate next (or maybe every) time. | 260 // otherwise cause passwords to re-migrate next (or maybe every) time. |
| 244 DeleteAndRecreateDatabaseFile(); | 261 DeleteAndRecreateDatabaseFile(); |
| 245 } | 262 } |
| 246 } | 263 } |
| 247 ssize_t result = ok ? forms.size() : -1; | 264 ssize_t result = ok ? forms.size() : -1; |
| 248 STLDeleteElements(&forms); | 265 STLDeleteElements(&forms); |
| 249 return result; | 266 return result; |
| 250 } | 267 } |
| OLD | NEW |