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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 : public RefcountedProfileKeyedService, | 45 : public RefcountedProfileKeyedService, |
46 public CancelableRequestProvider { | 46 public CancelableRequestProvider { |
47 public: | 47 public: |
48 typedef base::Callback< | 48 typedef base::Callback< |
49 void(Handle, const std::vector<webkit::forms::PasswordForm*>&)> | 49 void(Handle, const std::vector<webkit::forms::PasswordForm*>&)> |
50 GetLoginsCallback; | 50 GetLoginsCallback; |
51 | 51 |
52 // PasswordForm vector elements are meant to be owned by the | 52 // PasswordForm vector elements are meant to be owned by the |
53 // PasswordStoreConsumer. However, if the request is canceled after the | 53 // PasswordStoreConsumer. However, if the request is canceled after the |
54 // allocation, then the request must take care of the deletion. | 54 // allocation, then the request must take care of the deletion. |
55 // TODO(scr) If we can convert vector<PasswordForm*> to | |
56 // ScopedVector<PasswordForm>, then we can move the following class to merely | |
57 // a typedef. At the moment, a subclass of CancelableRequest1 is required to | |
58 // provide a destructor, which cleans up after canceled requests by deleting | |
59 // vector elements. | |
60 class GetLoginsRequest | 55 class GetLoginsRequest |
61 : public CancelableRequest1<GetLoginsCallback, | 56 : public CancelableRequest1<GetLoginsCallback, |
62 std::vector<webkit::forms::PasswordForm*> > { | 57 std::vector<webkit::forms::PasswordForm*> > { |
63 public: | 58 public: |
64 explicit GetLoginsRequest(const GetLoginsCallback& callback); | 59 explicit GetLoginsRequest(const GetLoginsCallback& callback); |
65 | 60 |
61 void set_ignore_logins_cutoff(time_t cutoff) { | |
62 ignore_logins_cutoff_ = cutoff; | |
63 } | |
64 | |
65 // Removes any logins in the result list that were saved before the cutoff. | |
66 void ApplyIgnoreLoginsCutoff(); | |
67 | |
66 protected: | 68 protected: |
67 virtual ~GetLoginsRequest(); | 69 virtual ~GetLoginsRequest(); |
68 | 70 |
69 private: | 71 private: |
72 // See GetLogins(). Logins older than this will be removed from the reply. | |
73 time_t ignore_logins_cutoff_; | |
Ilya Sherman
2012/05/02 22:10:17
nit: Please use base::Time for this, unless there'
Mike Mammarella
2012/05/07 00:14:36
Done.
| |
74 | |
70 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); | 75 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); |
71 }; | 76 }; |
72 | 77 |
73 // An interface used to notify clients (observers) of this object that data in | 78 // An interface used to notify clients (observers) of this object that data in |
74 // the password store has changed. Register the observer via | 79 // the password store has changed. Register the observer via |
75 // PasswordStore::SetObserver. | 80 // PasswordStore::SetObserver. |
76 class Observer { | 81 class Observer { |
77 public: | 82 public: |
78 // Notifies the observer that password data changed in some way. | 83 // Notifies the observer that password data changed in some way. |
79 virtual void OnLoginsChanged() = 0; | 84 virtual void OnLoginsChanged() = 0; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; | 176 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; |
172 | 177 |
173 // Finds all non-blacklist PasswordForms, and fills the vector. | 178 // Finds all non-blacklist PasswordForms, and fills the vector. |
174 virtual bool FillAutofillableLogins( | 179 virtual bool FillAutofillableLogins( |
175 std::vector<webkit::forms::PasswordForm*>* forms) = 0; | 180 std::vector<webkit::forms::PasswordForm*>* forms) = 0; |
176 // Finds all blacklist PasswordForms, and fills the vector. | 181 // Finds all blacklist PasswordForms, and fills the vector. |
177 virtual bool FillBlacklistLogins( | 182 virtual bool FillBlacklistLogins( |
178 std::vector<webkit::forms::PasswordForm*>* forms) = 0; | 183 std::vector<webkit::forms::PasswordForm*>* forms) = 0; |
179 | 184 |
180 // Dispatches the result to the PasswordStoreConsumer on the original caller's | 185 // Dispatches the result to the PasswordStoreConsumer on the original caller's |
181 // thread so the callback can be executed there. This should be the UI | 186 // thread so the callback can be executed there. This should be the UI thread. |
182 // thread. | |
183 virtual void ForwardLoginsResult(GetLoginsRequest* request); | 187 virtual void ForwardLoginsResult(GetLoginsRequest* request); |
184 | 188 |
189 private: | |
185 // Schedule the given |func| to be run in the PasswordStore's own thread with | 190 // Schedule the given |func| to be run in the PasswordStore's own thread with |
186 // responses delivered to |consumer| on the current thread. | 191 // responses delivered to |consumer| on the current thread. |
187 template<typename BackendFunc> | 192 template<typename BackendFunc> |
188 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer); | 193 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer); |
189 | 194 |
190 // Schedule the given |func| to be run in the PasswordStore's own thread with | 195 // Schedule the given |func| to be run in the PasswordStore's own thread with |
191 // argument |a| and responses delivered to |consumer| on the current thread. | 196 // form |form| and responses delivered to |consumer| on the current thread. |
192 template<typename BackendFunc, typename ArgA> | 197 // See GetLogins() for more information on |ignore_logins_cutoff|. |
198 template<typename BackendFunc> | |
193 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer, | 199 Handle Schedule(BackendFunc func, PasswordStoreConsumer* consumer, |
194 const ArgA& a); | 200 const webkit::forms::PasswordForm& form, |
201 time_t ignore_logins_cutoff); | |
195 | 202 |
196 private: | |
197 // Wrapper method called on the destination thread (DB for non-mac) that | 203 // Wrapper method called on the destination thread (DB for non-mac) that |
198 // invokes |task| and then calls back into the source thread to notify | 204 // invokes |task| and then calls back into the source thread to notify |
199 // observers that the password store may have been modified via | 205 // observers that the password store may have been modified via |
200 // NotifyLoginsChanged(). Note that there is no guarantee that the called | 206 // NotifyLoginsChanged(). Note that there is no guarantee that the called |
201 // method will actually modify the password store data. | 207 // method will actually modify the password store data. |
202 void WrapModificationTask(base::Closure task); | 208 void WrapModificationTask(base::Closure task); |
203 | 209 |
204 // Post a message to the UI thread to run NotifyLoginsChanged(). Called by | 210 // Post a message to the UI thread to run NotifyLoginsChanged(). Called by |
205 // WrapModificationTask() above, and split out as a separate method so that | 211 // WrapModificationTask() above, and split out as a separate method so that |
206 // password sync can call it as well after synchronously updating the password | 212 // password sync can call it as well after synchronously updating the password |
207 // store. | 213 // store. |
208 void PostNotifyLoginsChanged(); | 214 void PostNotifyLoginsChanged(); |
209 | 215 |
210 // Called by WrapModificationTask() once the underlying data-modifying | 216 // Called by WrapModificationTask() once the underlying data-modifying |
211 // operation has been performed. Notifies observers that password store data | 217 // operation has been performed. Notifies observers that password store data |
212 // may have been changed. | 218 // may have been changed. |
213 void NotifyLoginsChanged(); | 219 void NotifyLoginsChanged(); |
214 | 220 |
215 // The observers. | 221 // The observers. |
216 ObserverList<Observer> observers_; | 222 ObserverList<Observer> observers_; |
217 | 223 |
218 DISALLOW_COPY_AND_ASSIGN(PasswordStore); | 224 DISALLOW_COPY_AND_ASSIGN(PasswordStore); |
219 }; | 225 }; |
220 | 226 |
221 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ | 227 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_H_ |
OLD | NEW |