Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/password_manager/password_store.cc

Issue 152683002: Passwords: Remove references to BrowserThread from PasswordStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more tests. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "chrome/browser/password_manager/password_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "chrome/browser/password_manager/password_store_consumer.h" 13 #include "chrome/browser/password_manager/password_store_consumer.h"
14 #include "components/autofill/core/common/password_form.h" 14 #include "components/autofill/core/common/password_form.h"
15 #include "content/public/browser/browser_thread.h"
16 15
17 using autofill::PasswordForm; 16 using autofill::PasswordForm;
18 using content::BrowserThread;
19 using std::vector; 17 using std::vector;
20 18
21 namespace { 19 namespace {
22 20
23 // Calls |consumer| back with the request result, if |consumer| is still alive. 21 // Calls |consumer| back with the request result, if |consumer| is still alive.
24 // Takes ownership of the elements in |result|, passing ownership to |consumer| 22 // Takes ownership of the elements in |result|, passing ownership to |consumer|
25 // if it is still alive. 23 // if it is still alive.
26 void MaybeCallConsumerCallback(base::WeakPtr<PasswordStoreConsumer> consumer, 24 void MaybeCallConsumerCallback(base::WeakPtr<PasswordStoreConsumer> consumer,
27 scoped_ptr<vector<PasswordForm*> > result) { 25 scoped_ptr<vector<PasswordForm*> > result) {
28 if (consumer.get()) 26 if (consumer.get())
(...skipping 30 matching lines...) Expand all
59 } 57 }
60 } 58 }
61 59
62 void PasswordStore::GetLoginsRequest::ForwardResult() { 60 void PasswordStore::GetLoginsRequest::ForwardResult() {
63 origin_loop_->PostTask(FROM_HERE, 61 origin_loop_->PostTask(FROM_HERE,
64 base::Bind(&MaybeCallConsumerCallback, 62 base::Bind(&MaybeCallConsumerCallback,
65 consumer_weak_, 63 consumer_weak_,
66 base::Passed(result_.Pass()))); 64 base::Passed(result_.Pass())));
67 } 65 }
68 66
69 PasswordStore::PasswordStore() { 67 PasswordStore::PasswordStore(
68 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
69 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner)
70 : main_task_runner_(main_task_runner), db_thread_runner_(db_thread_runner)
Garrett Casto 2014/02/03 15:56:46 Newline after main_task_runner_ and bring the pare
Patrick Dubroy 2014/02/03 17:43:25 Done.
71 {
70 } 72 }
71 73
72 bool PasswordStore::Init() { 74 bool PasswordStore::Init() {
73 ReportMetrics(); 75 ReportMetrics();
74 return true; 76 return true;
75 } 77 }
76 78
77 void PasswordStore::AddLogin(const PasswordForm& form) { 79 void PasswordStore::AddLogin(const PasswordForm& form) {
78 ScheduleTask(base::Bind(&PasswordStore::WrapModificationTask, this, 80 ScheduleTask(base::Bind(&PasswordStore::WrapModificationTask, this,
79 base::Closure(base::Bind(&PasswordStore::AddLoginImpl, this, form)))); 81 base::Closure(base::Bind(&PasswordStore::AddLoginImpl, this, form))));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 147 }
146 148
147 void PasswordStore::RemoveObserver(Observer* observer) { 149 void PasswordStore::RemoveObserver(Observer* observer) {
148 observers_.RemoveObserver(observer); 150 observers_.RemoveObserver(observer);
149 } 151 }
150 152
151 PasswordStore::~PasswordStore() {} 153 PasswordStore::~PasswordStore() {}
152 154
153 bool PasswordStore::ScheduleTask(const base::Closure& task) { 155 bool PasswordStore::ScheduleTask(const base::Closure& task) {
154 scoped_refptr<base::SequencedTaskRunner> task_runner( 156 scoped_refptr<base::SequencedTaskRunner> task_runner(
155 GetTaskRunner()); 157 GetBackgroundTaskRunner());
156 if (task_runner.get()) 158 if (task_runner.get())
157 return task_runner->PostTask(FROM_HERE, task); 159 return task_runner->PostTask(FROM_HERE, task);
158 return false; 160 return false;
159 } 161 }
160 162
161 scoped_refptr<base::SequencedTaskRunner> PasswordStore::GetTaskRunner() { 163 scoped_refptr<base::SequencedTaskRunner>
162 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB); 164 PasswordStore::GetBackgroundTaskRunner() {
165 return db_thread_runner_;
163 } 166 }
164 167
165 void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) { 168 void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) {
166 request->ApplyIgnoreLoginsCutoff(); 169 request->ApplyIgnoreLoginsCutoff();
167 request->ForwardResult(); 170 request->ForwardResult();
168 } 171 }
169 172
170 void PasswordStore::CopyAndForwardLoginsResult( 173 void PasswordStore::CopyAndForwardLoginsResult(
171 PasswordStore::GetLoginsRequest* request, 174 PasswordStore::GetLoginsRequest* request,
172 const vector<PasswordForm*>& matched_forms) { 175 const vector<PasswordForm*>& matched_forms) {
173 // Copy the contents of |matched_forms| into the request. The request takes 176 // Copy the contents of |matched_forms| into the request. The request takes
174 // ownership of the PasswordForm elements. 177 // ownership of the PasswordForm elements.
175 *(request->result()) = matched_forms; 178 *(request->result()) = matched_forms;
176 ForwardLoginsResult(request); 179 ForwardLoginsResult(request);
177 } 180 }
178 181
179 void PasswordStore::LogStatsForBulkDeletion(int num_deletions) { 182 void PasswordStore::LogStatsForBulkDeletion(int num_deletions) {
180 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedByBulkDelete", 183 UMA_HISTOGRAM_COUNTS("PasswordManager.NumPasswordsDeletedByBulkDelete",
181 num_deletions); 184 num_deletions);
182 } 185 }
183 186
184 template<typename BackendFunc> 187 template<typename BackendFunc>
185 void PasswordStore::Schedule( 188 void PasswordStore::Schedule(
186 BackendFunc func, 189 BackendFunc func,
187 PasswordStoreConsumer* consumer) { 190 PasswordStoreConsumer* consumer) {
188 GetLoginsRequest* request = new GetLoginsRequest(consumer); 191 GetLoginsRequest* request = new GetLoginsRequest(consumer);
189 consumer->cancelable_task_tracker()->PostTask( 192 consumer->cancelable_task_tracker()->PostTask(
190 GetTaskRunner(), 193 GetBackgroundTaskRunner(),
191 FROM_HERE, 194 FROM_HERE,
192 base::Bind(func, this, base::Owned(request))); 195 base::Bind(func, this, base::Owned(request)));
193 } 196 }
194 197
195 void PasswordStore::WrapModificationTask(base::Closure task) { 198 void PasswordStore::WrapModificationTask(base::Closure task) {
196 #if !defined(OS_MACOSX) 199 DCHECK(!main_task_runner_->BelongsToCurrentThread());
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
198 #endif // !defined(OS_MACOSX)
199 task.Run(); 200 task.Run();
200 PostNotifyLoginsChanged(); 201 PostNotifyLoginsChanged();
201 } 202 }
202 203
203 void PasswordStore::PostNotifyLoginsChanged() { 204 void PasswordStore::PostNotifyLoginsChanged() {
204 #if !defined(OS_MACOSX) 205 DCHECK(!main_task_runner_->BelongsToCurrentThread());
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 206 main_task_runner_->PostTask(
206 #endif // !defined(OS_MACOSX) 207 FROM_HERE,
207 BrowserThread::PostTask(
208 BrowserThread::UI, FROM_HERE,
209 base::Bind(&PasswordStore::NotifyLoginsChanged, this)); 208 base::Bind(&PasswordStore::NotifyLoginsChanged, this));
210 } 209 }
211 210
212 void PasswordStore::NotifyLoginsChanged() { 211 void PasswordStore::NotifyLoginsChanged() {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 212 DCHECK(main_task_runner_->BelongsToCurrentThread());
214 FOR_EACH_OBSERVER(Observer, observers_, OnLoginsChanged()); 213 FOR_EACH_OBSERVER(Observer, observers_, OnLoginsChanged());
215 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698