OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/core/browser/password_store.h" | 5 #include "components/password_manager/core/browser/password_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/dump_without_crashing.h" | 8 #include "base/debug/dump_without_crashing.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 using autofill::PasswordForm; | 22 using autofill::PasswordForm; |
23 | 23 |
24 namespace password_manager { | 24 namespace password_manager { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Calls |consumer| back with the request result, if |consumer| is still alive. | 28 // Calls |consumer| back with the request result, if |consumer| is still alive. |
29 // Takes ownership of the elements in |result|, passing ownership to |consumer| | 29 // Takes ownership of the elements in |result|, passing ownership to |consumer| |
30 // if it is still alive. | 30 // if it is still alive. |
31 void MaybeCallConsumerCallback(base::WeakPtr<PasswordStoreConsumer> consumer, | 31 void MaybeCallConsumerCallback(base::WeakPtr<PasswordStoreConsumer> consumer, |
32 scoped_ptr<std::vector<PasswordForm*>> result) { | 32 ScopedVector<autofill::PasswordForm> result) { |
33 if (consumer.get()) | 33 if (consumer) { |
34 consumer->OnGetPasswordStoreResults(*result); | 34 consumer->results()->clear(); |
vasilii
2015/02/03 19:22:16
Do you need it?
vabr (Chromium)
2015/02/04 16:13:44
I don't, but I left it to make it clear that the c
| |
35 else | 35 consumer->results()->swap(result); |
36 STLDeleteElements(result.get()); | 36 consumer->OnGetPasswordStoreResults(); |
37 } | |
37 } | 38 } |
38 | 39 |
39 // http://crbug.com/404012. Let's see where the empty fields come from. | 40 // http://crbug.com/404012. Let's see where the empty fields come from. |
40 void CheckForEmptyUsernameAndPassword(const PasswordForm& form) { | 41 void CheckForEmptyUsernameAndPassword(const PasswordForm& form) { |
41 if (form.username_value.empty() && | 42 if (form.username_value.empty() && |
42 form.password_value.empty() && | 43 form.password_value.empty() && |
43 !form.blacklisted_by_user) | 44 !form.blacklisted_by_user) |
44 base::debug::DumpWithoutCrashing(); | 45 base::debug::DumpWithoutCrashing(); |
45 } | 46 } |
46 | 47 |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 PasswordStore::GetLoginsRequest::GetLoginsRequest( | 50 PasswordStore::GetLoginsRequest::GetLoginsRequest( |
50 PasswordStoreConsumer* consumer) | 51 PasswordStoreConsumer* consumer) |
51 : consumer_weak_(consumer->GetWeakPtr()), | 52 : consumer_weak_(consumer->GetWeakPtr()) { |
52 result_(new std::vector<PasswordForm*>()) { | 53 // TODO(vabr): As long as |thread_checker_| gets constructed without failures, |
54 // this DCHECK is always trivially true. It looks like we could get rid of the | |
55 // |thread_checker_| unless it was meant to make sure that threads are | |
56 // actually present in relevant tests. But in that case, we should do better | |
57 // than to hog production code because of tests. | |
53 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
vasilii
2015/02/03 19:22:17
Looks like this is the only place where it's used.
vabr (Chromium)
2015/02/04 16:13:44
It is explained in the TODO I added above. We migh
| |
54 origin_loop_ = base::MessageLoopProxy::current(); | 59 origin_loop_ = base::MessageLoopProxy::current(); |
55 } | 60 } |
56 | 61 |
57 PasswordStore::GetLoginsRequest::~GetLoginsRequest() { | 62 PasswordStore::GetLoginsRequest::~GetLoginsRequest() { |
58 } | 63 } |
59 | 64 |
60 void PasswordStore::GetLoginsRequest::ApplyIgnoreLoginsCutoff() { | 65 void PasswordStore::GetLoginsRequest::ApplyIgnoreLoginsCutoff() { |
61 if (!ignore_logins_cutoff_.is_null()) { | 66 if (!ignore_logins_cutoff_.is_null()) { |
62 // Count down rather than up since we may be deleting elements. | 67 ScopedVector<autofill::PasswordForm> remaining_logins; |
63 // Note that in principle it could be more efficient to copy the whole array | 68 remaining_logins.reserve(result_.size()); |
64 // since that's worst-case linear time, but we expect that elements will be | 69 for (auto& login : result_) { |
65 // deleted rarely and lists will be small, so this avoids the copies. | 70 if (login->date_created >= ignore_logins_cutoff_) { |
66 for (size_t i = result_->size(); i > 0; --i) { | 71 remaining_logins.push_back(login); |
67 if ((*result_)[i - 1]->date_created < ignore_logins_cutoff_) { | 72 login = nullptr; |
68 delete (*result_)[i - 1]; | |
69 result_->erase(result_->begin() + (i - 1)); | |
70 } | 73 } |
71 } | 74 } |
75 remaining_logins.swap(result_); | |
72 } | 76 } |
73 } | 77 } |
74 | 78 |
75 void PasswordStore::GetLoginsRequest::ForwardResult() { | 79 void PasswordStore::GetLoginsRequest::ForwardResult() { |
76 origin_loop_->PostTask(FROM_HERE, | 80 origin_loop_->PostTask(FROM_HERE, |
77 base::Bind(&MaybeCallConsumerCallback, | 81 base::Bind(&MaybeCallConsumerCallback, consumer_weak_, |
78 consumer_weak_, | |
79 base::Passed(result_.Pass()))); | 82 base::Passed(result_.Pass()))); |
vasilii
2015/02/03 19:22:16
base::Passed(&result_)?
vabr (Chromium)
2015/02/04 16:13:44
Done.
| |
80 } | 83 } |
81 | 84 |
82 PasswordStore::PasswordStore( | 85 PasswordStore::PasswordStore( |
83 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 86 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
84 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner) | 87 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner) |
85 : main_thread_runner_(main_thread_runner), | 88 : main_thread_runner_(main_thread_runner), |
86 db_thread_runner_(db_thread_runner), | 89 db_thread_runner_(db_thread_runner), |
87 observers_(new ObserverListThreadSafe<Observer>()), | 90 observers_(new ObserverListThreadSafe<Observer>()), |
88 shutdown_called_(false) { | 91 shutdown_called_(false) { |
89 } | 92 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 base::Time ignore_logins_cutoff; // the null time | 137 base::Time ignore_logins_cutoff; // the null time |
135 if (form.scheme == PasswordForm::SCHEME_HTML && | 138 if (form.scheme == PasswordForm::SCHEME_HTML && |
136 (form.signon_realm == "http://www.google.com" || | 139 (form.signon_realm == "http://www.google.com" || |
137 form.signon_realm == "http://www.google.com/" || | 140 form.signon_realm == "http://www.google.com/" || |
138 form.signon_realm == "https://www.google.com" || | 141 form.signon_realm == "https://www.google.com" || |
139 form.signon_realm == "https://www.google.com/")) { | 142 form.signon_realm == "https://www.google.com/")) { |
140 static const base::Time::Exploded exploded_cutoff = | 143 static const base::Time::Exploded exploded_cutoff = |
141 { 2012, 1, 0, 1, 0, 0, 0, 0 }; // 00:00 Jan 1 2012 | 144 { 2012, 1, 0, 1, 0, 0, 0, 0 }; // 00:00 Jan 1 2012 |
142 ignore_logins_cutoff = base::Time::FromUTCExploded(exploded_cutoff); | 145 ignore_logins_cutoff = base::Time::FromUTCExploded(exploded_cutoff); |
143 } | 146 } |
144 GetLoginsRequest* request = new GetLoginsRequest(consumer); | 147 scoped_ptr<GetLoginsRequest> request(new GetLoginsRequest(consumer)); |
145 request->set_ignore_logins_cutoff(ignore_logins_cutoff); | 148 request->set_ignore_logins_cutoff(ignore_logins_cutoff); |
146 | 149 |
147 ConsumerCallbackRunner callback_runner = base::Bind( | 150 ConsumerCallbackRunner callback_runner = |
148 &PasswordStore::CopyAndForwardLoginsResult, base::Owned(request)); | 151 base::Bind(&CopyAndForwardLoginsResult, base::Passed(request.Pass())); |
vasilii
2015/02/03 19:22:16
base::Passed(&request)?
vabr (Chromium)
2015/02/04 16:13:44
Done.
| |
149 ScheduleTask(base::Bind(&PasswordStore::GetLoginsImpl, this, form, | 152 ScheduleTask(base::Bind(&PasswordStore::GetLoginsImpl, this, form, |
150 prompt_policy, callback_runner)); | 153 prompt_policy, callback_runner)); |
151 } | 154 } |
152 | 155 |
153 void PasswordStore::GetAutofillableLogins(PasswordStoreConsumer* consumer) { | 156 void PasswordStore::GetAutofillableLogins(PasswordStoreConsumer* consumer) { |
154 Schedule(&PasswordStore::GetAutofillableLoginsImpl, consumer); | 157 Schedule(&PasswordStore::GetAutofillableLoginsImpl, consumer); |
155 } | 158 } |
156 | 159 |
157 void PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { | 160 void PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { |
158 Schedule(&PasswordStore::GetBlacklistLoginsImpl, consumer); | 161 Schedule(&PasswordStore::GetBlacklistLoginsImpl, consumer); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 PasswordStore::~PasswordStore() { | 204 PasswordStore::~PasswordStore() { |
202 DCHECK(shutdown_called_); | 205 DCHECK(shutdown_called_); |
203 } | 206 } |
204 | 207 |
205 scoped_refptr<base::SingleThreadTaskRunner> | 208 scoped_refptr<base::SingleThreadTaskRunner> |
206 PasswordStore::GetBackgroundTaskRunner() { | 209 PasswordStore::GetBackgroundTaskRunner() { |
207 return db_thread_runner_; | 210 return db_thread_runner_; |
208 } | 211 } |
209 | 212 |
210 // static | 213 // static |
211 void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) { | 214 void PasswordStore::ForwardLoginsResult(scoped_ptr<GetLoginsRequest> request) { |
212 request->ApplyIgnoreLoginsCutoff(); | 215 request->ApplyIgnoreLoginsCutoff(); |
213 request->ForwardResult(); | 216 request->ForwardResult(); |
214 } | 217 } |
215 | 218 |
216 // static | 219 // static |
217 void PasswordStore::CopyAndForwardLoginsResult( | 220 void PasswordStore::CopyAndForwardLoginsResult( |
218 PasswordStore::GetLoginsRequest* request, | 221 scoped_ptr<PasswordStore::GetLoginsRequest> request, |
219 ScopedVector<autofill::PasswordForm> matched_forms) { | 222 ScopedVector<autofill::PasswordForm> matched_forms) { |
220 // Move the contents of |matched_forms| into the request. | 223 DCHECK(request->result()->empty()); |
221 request->result()->swap(matched_forms.get()); | 224 request->result()->swap(matched_forms); |
222 ForwardLoginsResult(request); | 225 ForwardLoginsResult(request.Pass()); |
223 } | 226 } |
224 | 227 |
225 void PasswordStore::LogStatsForBulkDeletion(int num_deletions) { | 228 void PasswordStore::LogStatsForBulkDeletion(int num_deletions) { |
226 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedByBulkDelete", | 229 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedByBulkDelete", |
227 num_deletions); | 230 num_deletions); |
228 } | 231 } |
229 | 232 |
230 void PasswordStore::LogStatsForBulkDeletionDuringRollback(int num_deletions) { | 233 void PasswordStore::LogStatsForBulkDeletionDuringRollback(int num_deletions) { |
231 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedDuringRollback", | 234 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedDuringRollback", |
232 num_deletions); | 235 num_deletions); |
233 } | 236 } |
234 | 237 |
235 void PasswordStore::NotifyLoginsChanged( | 238 void PasswordStore::NotifyLoginsChanged( |
236 const PasswordStoreChangeList& changes) { | 239 const PasswordStoreChangeList& changes) { |
237 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | 240 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
238 if (!changes.empty()) { | 241 if (!changes.empty()) { |
239 observers_->Notify(&Observer::OnLoginsChanged, changes); | 242 observers_->Notify(&Observer::OnLoginsChanged, changes); |
240 #if defined(PASSWORD_MANAGER_ENABLE_SYNC) | 243 #if defined(PASSWORD_MANAGER_ENABLE_SYNC) |
241 if (syncable_service_) | 244 if (syncable_service_) |
242 syncable_service_->ActOnPasswordStoreChanges(changes); | 245 syncable_service_->ActOnPasswordStoreChanges(changes); |
243 #endif | 246 #endif |
244 } | 247 } |
245 } | 248 } |
246 | 249 |
247 template <typename BackendFunc> | 250 template <typename BackendFunc> |
248 void PasswordStore::Schedule(BackendFunc func, | 251 void PasswordStore::Schedule(BackendFunc func, |
vasilii
2015/02/03 19:22:17
Optional: you can get rid of the template because
vabr (Chromium)
2015/02/04 16:13:44
Sounds reasonable, the function signature was rest
| |
249 PasswordStoreConsumer* consumer) { | 252 PasswordStoreConsumer* consumer) { |
250 GetLoginsRequest* request = new GetLoginsRequest(consumer); | 253 scoped_ptr<GetLoginsRequest> request(new GetLoginsRequest(consumer)); |
251 consumer->cancelable_task_tracker()->PostTask( | 254 consumer->cancelable_task_tracker()->PostTask( |
252 GetBackgroundTaskRunner().get(), | 255 GetBackgroundTaskRunner().get(), FROM_HERE, |
253 FROM_HERE, | 256 base::Bind(func, this, base::Passed(request.Pass()))); |
vasilii
2015/02/03 19:22:17
base::Passed(&request);
vabr (Chromium)
2015/02/04 16:13:44
Done.
| |
254 base::Bind(func, this, base::Owned(request))); | |
255 } | 257 } |
256 | 258 |
257 void PasswordStore::WrapModificationTask(ModificationTask task) { | 259 void PasswordStore::WrapModificationTask(ModificationTask task) { |
258 PasswordStoreChangeList changes = task.Run(); | 260 PasswordStoreChangeList changes = task.Run(); |
259 NotifyLoginsChanged(changes); | 261 NotifyLoginsChanged(changes); |
260 } | 262 } |
261 | 263 |
262 void PasswordStore::AddLoginInternal(const PasswordForm& form) { | 264 void PasswordStore::AddLoginInternal(const PasswordForm& form) { |
263 PasswordStoreChangeList changes = AddLoginImpl(form); | 265 PasswordStoreChangeList changes = AddLoginImpl(form); |
264 NotifyLoginsChanged(changes); | 266 NotifyLoginsChanged(changes); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 syncable_service_->InjectStartSyncFlare(flare); | 299 syncable_service_->InjectStartSyncFlare(flare); |
298 } | 300 } |
299 | 301 |
300 void PasswordStore::DestroySyncableService() { | 302 void PasswordStore::DestroySyncableService() { |
301 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | 303 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
302 syncable_service_.reset(); | 304 syncable_service_.reset(); |
303 } | 305 } |
304 #endif | 306 #endif |
305 | 307 |
306 } // namespace password_manager | 308 } // namespace password_manager |
OLD | NEW |