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

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

Issue 114057: Re-land the password store work from bug 8205, with changes that should fix b... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
(Empty)
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/password_manager/password_store.h"
6
7 #include "base/scoped_ptr.h"
8 #include "base/task.h"
9
10 using std::vector;
11
12 PasswordStore::PasswordStore() : handle_(0) {
13 }
14
15 bool PasswordStore::Init() {
16 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread"));
17
18 if (!thread_->Start()) {
19 thread_.reset(NULL);
20 return false;
21 }
22
23 return true;
24 }
25
26 void PasswordStore::ScheduleTask(Task* task) {
27 if (thread_.get()) {
28 thread_->message_loop()->PostTask(FROM_HERE, task);
29 }
30 }
31
32 void PasswordStore::AddLogin(const PasswordForm& form) {
33 ScheduleTask(NewRunnableMethod(
34 this, &PasswordStore::AddLoginImpl, form));
35 }
36
37 void PasswordStore::UpdateLogin(const PasswordForm& form) {
38 ScheduleTask(NewRunnableMethod(
39 this, &PasswordStore::UpdateLoginImpl, form));
40 }
41
42 void PasswordStore::RemoveLogin(const PasswordForm& form) {
43 ScheduleTask(NewRunnableMethod(
44 this, &PasswordStore::RemoveLoginImpl, form));
45 }
46
47 int PasswordStore::GetLogins(const PasswordForm& form,
48 PasswordStoreConsumer* consumer) {
49 int handle = handle_++;
50 GetLoginsRequest* request = new GetLoginsRequest(form, consumer, handle);
51
52 pending_requests_.insert(handle);
53
54 ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetLoginsImpl, request));
55 return handle;
56 }
57
58 void PasswordStore::NotifyConsumer(GetLoginsRequest* request,
59 const vector<PasswordForm*> forms) {
60 scoped_ptr<GetLoginsRequest> request_ptr(request);
61
62 DCHECK(MessageLoop::current() == thread_->message_loop());
63 request->message_loop->PostTask(FROM_HERE,
64 NewRunnableMethod(this,
65 &PasswordStore::NotifyConsumerImpl,
66 request->consumer, request->handle, forms));
67 }
68
69 void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer,
70 int handle,
71 const vector<PasswordForm*> forms) {
72 // Don't notify the consumer if the request was canceled.
73 if (pending_requests_.find(handle) == pending_requests_.end())
74 return;
75 pending_requests_.erase(handle);
76
77 consumer->OnPasswordStoreRequestDone(handle, forms);
78 }
79
80 void PasswordStore::CancelLoginsQuery(int handle) {
81 pending_requests_.erase(handle);
82 }
83
84 PasswordStore::GetLoginsRequest::GetLoginsRequest(
85 const PasswordForm& form,
86 PasswordStoreConsumer* consumer,
87 int handle)
88 : form(form),
89 consumer(consumer),
90 handle(handle),
91 message_loop(MessageLoop::current()) {
92 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store.h ('k') | chrome/browser/password_manager/password_store_default.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698