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 <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
16 #include "components/password_manager/core/browser/password_store_change.h" | 17 #include "components/password_manager/core/browser/password_store_change.h" |
17 #include "components/password_manager/core/common/password_manager_pref_names.h" | 18 #include "components/password_manager/core/common/password_manager_pref_names.h" |
18 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
(...skipping 18 matching lines...) Expand all Loading... |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 PasswordStoreX::PasswordStoreX( | 41 PasswordStoreX::PasswordStoreX( |
41 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 42 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
42 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
43 scoped_ptr<password_manager::LoginDatabase> login_db, | 44 scoped_ptr<password_manager::LoginDatabase> login_db, |
44 NativeBackend* backend) | 45 NativeBackend* backend) |
45 : PasswordStoreDefault(main_thread_runner, | 46 : PasswordStoreDefault(main_thread_runner, |
46 db_thread_runner, | 47 db_thread_runner, |
47 login_db.Pass()), | 48 std::move(login_db)), |
48 backend_(backend), | 49 backend_(backend), |
49 migration_checked_(!backend), | 50 migration_checked_(!backend), |
50 allow_fallback_(false) { | 51 allow_fallback_(false) {} |
51 } | |
52 | 52 |
53 PasswordStoreX::~PasswordStoreX() {} | 53 PasswordStoreX::~PasswordStoreX() {} |
54 | 54 |
55 PasswordStoreChangeList PasswordStoreX::AddLoginImpl(const PasswordForm& form) { | 55 PasswordStoreChangeList PasswordStoreX::AddLoginImpl(const PasswordForm& form) { |
56 CheckMigration(); | 56 CheckMigration(); |
57 PasswordStoreChangeList changes; | 57 PasswordStoreChangeList changes; |
58 if (use_native_backend() && AddLoginToBackend(backend_, form, &changes)) { | 58 if (use_native_backend() && AddLoginToBackend(backend_, form, &changes)) { |
59 allow_fallback_ = false; | 59 allow_fallback_ = false; |
60 } else if (allow_default_store()) { | 60 } else if (allow_default_store()) { |
61 changes = PasswordStoreDefault::AddLoginImpl(form); | 61 changes = PasswordStoreDefault::AddLoginImpl(form); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.empty()) | 148 if (!matched_forms.empty()) |
149 allow_fallback_ = false; | 149 allow_fallback_ = false; |
150 return matched_forms.Pass(); | 150 return matched_forms; |
151 } | 151 } |
152 if (allow_default_store()) | 152 if (allow_default_store()) |
153 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); | 153 return PasswordStoreDefault::FillMatchingLogins(form, prompt_policy); |
154 return ScopedVector<autofill::PasswordForm>(); | 154 return ScopedVector<autofill::PasswordForm>(); |
155 } | 155 } |
156 | 156 |
157 bool PasswordStoreX::FillAutofillableLogins( | 157 bool PasswordStoreX::FillAutofillableLogins( |
158 ScopedVector<autofill::PasswordForm>* forms) { | 158 ScopedVector<autofill::PasswordForm>* forms) { |
159 CheckMigration(); | 159 CheckMigration(); |
160 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { | 160 if (use_native_backend() && backend_->GetAutofillableLogins(forms)) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Finally, delete the database file itself. We remove the passwords from | 251 // Finally, delete the database file itself. We remove the passwords from |
252 // it before deleting the file just in case there is some problem deleting | 252 // it before deleting the file just in case there is some problem deleting |
253 // the file (e.g. directory is not writable, but file is), which would | 253 // the file (e.g. directory is not writable, but file is), which would |
254 // otherwise cause passwords to re-migrate next (or maybe every) time. | 254 // otherwise cause passwords to re-migrate next (or maybe every) time. |
255 DeleteAndRecreateDatabaseFile(); | 255 DeleteAndRecreateDatabaseFile(); |
256 } | 256 } |
257 } | 257 } |
258 ssize_t result = ok ? forms.size() : -1; | 258 ssize_t result = ok ? forms.size() : -1; |
259 return result; | 259 return result; |
260 } | 260 } |
OLD | NEW |