1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/password_manager/password_store.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/task.h"
#include "chrome/browser/password_manager/password_store_consumer.h"
#include "content/browser/browser_thread.h"
#include "webkit/glue/password_form.h"
using std::vector;
using webkit_glue::PasswordForm;
PasswordStore::GetLoginsRequest::GetLoginsRequest(GetLoginsCallback* callback)
: CancelableRequest1<GetLoginsCallback,
std::vector<webkit_glue::PasswordForm*> >(callback) {
}
PasswordStore::GetLoginsRequest::~GetLoginsRequest() {
if (canceled()) {
STLDeleteElements(&value);
}
}
PasswordStore::PasswordStore() {
}
bool PasswordStore::Init() {
ReportMetrics();
return true;
}
void PasswordStore::Shutdown() {
}
void PasswordStore::AddLogin(const PasswordForm& form) {
Task* task = NewRunnableMethod(this, &PasswordStore::AddLoginImpl, form);
ScheduleTask(
NewRunnableMethod(this, &PasswordStore::WrapModificationTask, task));
}
void PasswordStore::UpdateLogin(const PasswordForm& form) {
Task* task = NewRunnableMethod(this, &PasswordStore::UpdateLoginImpl, form);
ScheduleTask(
NewRunnableMethod(this, &PasswordStore::WrapModificationTask, task));
}
void PasswordStore::RemoveLogin(const PasswordForm& form) {
Task* task = NewRunnableMethod(this, &PasswordStore::RemoveLoginImpl, form);
ScheduleTask(
NewRunnableMethod(this, &PasswordStore::WrapModificationTask, task));
}
void PasswordStore::RemoveLoginsCreatedBetween(const base::Time& delete_begin,
const base::Time& delete_end) {
Task* task = NewRunnableMethod(this,
&PasswordStore::RemoveLoginsCreatedBetweenImpl,
delete_begin, delete_end);
ScheduleTask(
NewRunnableMethod(this, &PasswordStore::WrapModificationTask, task));
}
CancelableRequestProvider::Handle PasswordStore::GetLogins(
const PasswordForm& form, PasswordStoreConsumer* consumer) {
return Schedule(&PasswordStore::GetLoginsImpl, consumer, form);
}
CancelableRequestProvider::Handle PasswordStore::GetAutofillableLogins(
PasswordStoreConsumer* consumer) {
return Schedule(&PasswordStore::GetAutofillableLoginsImpl, consumer);
}
CancelableRequestProvider::Handle PasswordStore::GetBlacklistLogins(
PasswordStoreConsumer* consumer) {
return Schedule(&PasswordStore::GetBlacklistLoginsImpl, consumer);
}
void PasswordStore::ReportMetrics() {
ScheduleTask(NewRunnableMethod(this, &PasswordStore::ReportMetricsImpl));
}
void PasswordStore::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void PasswordStore::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
PasswordStore::~PasswordStore() {}
PasswordStore::GetLoginsRequest* PasswordStore::NewGetLoginsRequest(
GetLoginsCallback* callback) {
return new GetLoginsRequest(callback);
}
void PasswordStore::ScheduleTask(Task* task) {
BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, task);
}
void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) {
request->ForwardResult(GetLoginsRequest::TupleType(request->handle(),
request->value));
}
template<typename BackendFunc>
CancelableRequestProvider::Handle PasswordStore::Schedule(
BackendFunc func, PasswordStoreConsumer* consumer) {
scoped_refptr<GetLoginsRequest> request(NewGetLoginsRequest(
NewCallback(consumer,
&PasswordStoreConsumer::OnPasswordStoreRequestDone)));
AddRequest(request, consumer->cancelable_consumer());
ScheduleTask(NewRunnableMethod(this, func, request));
return request->handle();
}
template<typename BackendFunc, typename ArgA>
CancelableRequestProvider::Handle PasswordStore::Schedule(
BackendFunc func, PasswordStoreConsumer* consumer, const ArgA& a) {
scoped_refptr<GetLoginsRequest> request(NewGetLoginsRequest(
NewCallback(consumer,
&PasswordStoreConsumer::OnPasswordStoreRequestDone)));
AddRequest(request, consumer->cancelable_consumer());
ScheduleTask(NewRunnableMethod(this, func, request, a));
return request->handle();
}
void PasswordStore::WrapModificationTask(Task* task) {
#if !defined(OS_MACOSX)
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
#endif // !defined(OS_MACOSX)
DCHECK(task);
task->Run();
delete task;
PostNotifyLoginsChanged();
}
void PasswordStore::PostNotifyLoginsChanged() {
#if !defined(OS_MACOSX)
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
#endif // !defined(OS_MACOSX)
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, &PasswordStore::NotifyLoginsChanged));
}
void PasswordStore::NotifyLoginsChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
FOR_EACH_OBSERVER(Observer, observers_, OnLoginsChanged());
}
|