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

Side by Side Diff: components/password_manager/core/browser/password_store.h

Issue 866983003: GetLoginsRequest: Use ScopedVector to express ownership of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@324291_scopedvector
Patch Set: Fix Mac unittest Created 5 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
OLDNEW
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 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // should fail without side effects, return no data, and send no notifications. 59 // should fail without side effects, return no data, and send no notifications.
60 // PasswordStoreSync is a hidden base class because only PasswordSyncableService 60 // PasswordStoreSync is a hidden base class because only PasswordSyncableService
61 // needs to access these methods. 61 // needs to access these methods.
62 class PasswordStore : protected PasswordStoreSync, 62 class PasswordStore : protected PasswordStoreSync,
63 public base::RefCountedThreadSafe<PasswordStore> { 63 public base::RefCountedThreadSafe<PasswordStore> {
64 public: 64 public:
65 // Whether or not it's acceptable for Chrome to request access to locked 65 // Whether or not it's acceptable for Chrome to request access to locked
66 // passwords, which requires prompting the user for permission. 66 // passwords, which requires prompting the user for permission.
67 enum AuthorizationPromptPolicy { ALLOW_PROMPT, DISALLOW_PROMPT }; 67 enum AuthorizationPromptPolicy { ALLOW_PROMPT, DISALLOW_PROMPT };
68 68
69 // PasswordForm vector elements are meant to be owned by the
70 // PasswordStoreConsumer. However, if the request is canceled after the
71 // allocation, then the request must take care of the deletion.
72 class GetLoginsRequest {
73 public:
74 explicit GetLoginsRequest(PasswordStoreConsumer* consumer);
75 virtual ~GetLoginsRequest();
76
77 void set_ignore_logins_cutoff(base::Time cutoff) {
78 ignore_logins_cutoff_ = cutoff;
79 }
80
81 // Removes any logins in the result list that were saved before the cutoff.
82 void ApplyIgnoreLoginsCutoff();
83
84 // Forward the result to the consumer on the original message loop.
85 void ForwardResult();
86
87 std::vector<autofill::PasswordForm*>* result() const {
88 return result_.get();
89 }
90
91 private:
92 // See GetLogins(). Logins older than this will be removed from the reply.
93 base::Time ignore_logins_cutoff_;
94
95 base::WeakPtr<PasswordStoreConsumer> consumer_weak_;
96
97 // The result of the request. It is filled in on the PasswordStore's task
98 // thread and consumed on the UI thread.
99 // TODO(dubroy): Remove this, and instead pass the vector directly to the
100 // backend methods.
101 scoped_ptr<std::vector<autofill::PasswordForm*>> result_;
102
103 base::ThreadChecker thread_checker_;
104 scoped_refptr<base::MessageLoopProxy> origin_loop_;
105
106 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest);
107 };
108
109 // An interface used to notify clients (observers) of this object that data in 69 // An interface used to notify clients (observers) of this object that data in
110 // the password store has changed. Register the observer via 70 // the password store has changed. Register the observer via
111 // PasswordStore::AddObserver. 71 // PasswordStore::AddObserver.
112 class Observer { 72 class Observer {
113 public: 73 public:
114 // Notifies the observer that password data changed. Will be called from 74 // Notifies the observer that password data changed. Will be called from
115 // the UI thread. 75 // the UI thread.
116 virtual void OnLoginsChanged(const PasswordStoreChangeList& changes) = 0; 76 virtual void OnLoginsChanged(const PasswordStoreChangeList& changes) = 0;
117 77
118 protected: 78 protected:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 #if defined(PASSWORD_MANAGER_ENABLE_SYNC) 145 #if defined(PASSWORD_MANAGER_ENABLE_SYNC)
186 base::WeakPtr<syncer::SyncableService> GetPasswordSyncableService(); 146 base::WeakPtr<syncer::SyncableService> GetPasswordSyncableService();
187 #endif 147 #endif
188 148
189 protected: 149 protected:
190 friend class base::RefCountedThreadSafe<PasswordStore>; 150 friend class base::RefCountedThreadSafe<PasswordStore>;
191 FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, IgnoreOldWwwGoogleLogins); 151 FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, IgnoreOldWwwGoogleLogins);
192 152
193 typedef base::Callback<PasswordStoreChangeList(void)> ModificationTask; 153 typedef base::Callback<PasswordStoreChangeList(void)> ModificationTask;
194 154
155 // PasswordForm vector elements are meant to be owned by the
156 // PasswordStoreConsumer. However, if the request is canceled after the
157 // allocation, then the request must take care of the deletion.
158 class GetLoginsRequest {
159 public:
160 explicit GetLoginsRequest(PasswordStoreConsumer* consumer);
161 virtual ~GetLoginsRequest();
162
163 void set_ignore_logins_cutoff(base::Time cutoff) {
164 ignore_logins_cutoff_ = cutoff;
165 }
166
167 // Removes any logins in the result list that were saved before the cutoff.
168 void ApplyIgnoreLoginsCutoff();
169
170 // Forward the result to the consumer on the original message loop.
171 void ForwardResult();
172
173 ScopedVector<autofill::PasswordForm>* result() { return &result_; }
174
175 private:
176 // See GetLogins(). Logins older than this will be removed from the reply.
177 base::Time ignore_logins_cutoff_;
178
179 base::WeakPtr<PasswordStoreConsumer> consumer_weak_;
180
181 // The result of the request. It is filled in on the PasswordStore's task
182 // thread and consumed on the UI thread.
183 ScopedVector<autofill::PasswordForm> result_;
184
185 base::ThreadChecker thread_checker_;
186 scoped_refptr<base::MessageLoopProxy> origin_loop_;
187
188 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest);
189 };
190
195 ~PasswordStore() override; 191 ~PasswordStore() override;
196 192
197 // Get the TaskRunner to use for PasswordStore background tasks. 193 // Get the TaskRunner to use for PasswordStore background tasks.
198 // By default, a SingleThreadTaskRunner on the DB thread is used, but 194 // By default, a SingleThreadTaskRunner on the DB thread is used, but
199 // subclasses can override. 195 // subclasses can override.
200 virtual scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner(); 196 virtual scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner();
201 197
202 // Methods below will be run in PasswordStore's own thread. 198 // Methods below will be run in PasswordStore's own thread.
203 // Synchronous implementation that reports usage metrics. 199 // Synchronous implementation that reports usage metrics.
204 virtual void ReportMetricsImpl(const std::string& sync_username, 200 virtual void ReportMetricsImpl(const std::string& sync_username,
(...skipping 23 matching lines...) Expand all
228 ConsumerCallbackRunner; 224 ConsumerCallbackRunner;
229 225
230 // Should find all PasswordForms with the same signon_realm. The results 226 // Should find all PasswordForms with the same signon_realm. The results
231 // will then be scored by the PasswordFormManager. Once they are found 227 // will then be scored by the PasswordFormManager. Once they are found
232 // (or not), the consumer should be notified. 228 // (or not), the consumer should be notified.
233 virtual void GetLoginsImpl(const autofill::PasswordForm& form, 229 virtual void GetLoginsImpl(const autofill::PasswordForm& form,
234 AuthorizationPromptPolicy prompt_policy, 230 AuthorizationPromptPolicy prompt_policy,
235 const ConsumerCallbackRunner& callback_runner) = 0; 231 const ConsumerCallbackRunner& callback_runner) = 0;
236 232
237 // Finds all non-blacklist PasswordForms, and notifies the consumer. 233 // Finds all non-blacklist PasswordForms, and notifies the consumer.
238 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) = 0; 234 virtual void GetAutofillableLoginsImpl(
235 scoped_ptr<GetLoginsRequest> request) = 0;
239 236
240 // Finds all blacklist PasswordForms, and notifies the consumer. 237 // Finds all blacklist PasswordForms, and notifies the consumer.
241 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) = 0; 238 virtual void GetBlacklistLoginsImpl(scoped_ptr<GetLoginsRequest> request) = 0;
242 239
243 // Dispatches the result to the PasswordStoreConsumer on the original caller's 240 // Dispatches the result to the PasswordStoreConsumer on the original caller's
244 // thread so the callback can be executed there. This should be the UI thread. 241 // thread so the callback can be executed there. This should be the UI thread.
245 static void ForwardLoginsResult(GetLoginsRequest* request); 242 static void ForwardLoginsResult(scoped_ptr<GetLoginsRequest> request);
246 243
247 // Log UMA stats for number of bulk deletions. 244 // Log UMA stats for number of bulk deletions.
248 void LogStatsForBulkDeletion(int num_deletions); 245 void LogStatsForBulkDeletion(int num_deletions);
249 246
250 // Log UMA stats for password deletions happening on clear browsing data 247 // Log UMA stats for password deletions happening on clear browsing data
251 // since first sync during rollback. 248 // since first sync during rollback.
252 void LogStatsForBulkDeletionDuringRollback(int num_deletions); 249 void LogStatsForBulkDeletionDuringRollback(int num_deletions);
253 250
254 // PasswordStoreSync: 251 // PasswordStoreSync:
255 // Called by WrapModificationTask() once the underlying data-modifying 252 // Called by WrapModificationTask() once the underlying data-modifying
256 // operation has been performed. Notifies observers that password store data 253 // operation has been performed. Notifies observers that password store data
257 // may have been changed. 254 // may have been changed.
258 void NotifyLoginsChanged(const PasswordStoreChangeList& changes) override; 255 void NotifyLoginsChanged(const PasswordStoreChangeList& changes) override;
259 256
260 // TaskRunner for tasks that run on the main thread (usually the UI thread). 257 // TaskRunner for tasks that run on the main thread (usually the UI thread).
261 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; 258 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
262 259
263 // TaskRunner for the DB thread. By default, this is the task runner used for 260 // TaskRunner for the DB thread. By default, this is the task runner used for
264 // background tasks -- see |GetBackgroundTaskRunner|. 261 // background tasks -- see |GetBackgroundTaskRunner|.
265 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner_; 262 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner_;
266 263
267 private: 264 private:
268 // Schedule the given |func| to be run in the PasswordStore's own thread with 265 // Schedule the given |func| to be run in the PasswordStore's own thread with
269 // responses delivered to |consumer| on the current thread. 266 // responses delivered to |consumer| on the current thread.
270 template <typename BackendFunc> 267 void Schedule(void (PasswordStore::*func)(scoped_ptr<GetLoginsRequest>),
271 void Schedule(BackendFunc func, PasswordStoreConsumer* consumer); 268 PasswordStoreConsumer* consumer);
272 269
273 // Wrapper method called on the destination thread (DB for non-mac) that 270 // Wrapper method called on the destination thread (DB for non-mac) that
274 // invokes |task| and then calls back into the source thread to notify 271 // invokes |task| and then calls back into the source thread to notify
275 // observers that the password store may have been modified via 272 // observers that the password store may have been modified via
276 // NotifyLoginsChanged(). Note that there is no guarantee that the called 273 // NotifyLoginsChanged(). Note that there is no guarantee that the called
277 // method will actually modify the password store data. 274 // method will actually modify the password store data.
278 void WrapModificationTask(ModificationTask task); 275 void WrapModificationTask(ModificationTask task);
279 276
280 // Temporary specializations of WrapModificationTask for a better stack trace. 277 // Temporary specializations of WrapModificationTask for a better stack trace.
281 void AddLoginInternal(const autofill::PasswordForm& form); 278 void AddLoginInternal(const autofill::PasswordForm& form);
282 void UpdateLoginInternal(const autofill::PasswordForm& form); 279 void UpdateLoginInternal(const autofill::PasswordForm& form);
283 void RemoveLoginInternal(const autofill::PasswordForm& form); 280 void RemoveLoginInternal(const autofill::PasswordForm& form);
284 void RemoveLoginsCreatedBetweenInternal(base::Time delete_begin, 281 void RemoveLoginsCreatedBetweenInternal(base::Time delete_begin,
285 base::Time delete_end); 282 base::Time delete_end);
286 void RemoveLoginsSyncedBetweenInternal(base::Time delete_begin, 283 void RemoveLoginsSyncedBetweenInternal(base::Time delete_begin,
287 base::Time delete_end); 284 base::Time delete_end);
288 285
289 // Copies |matched_forms| into the request's result vector, then calls 286 // Copies |matched_forms| into the request's result vector, then calls
290 // |ForwardLoginsResult|. Temporarily used as an adapter between the API of 287 // |ForwardLoginsResult|. Temporarily used as an adapter between the API of
291 // |GetLoginsImpl| and |PasswordStoreConsumer|. 288 // |GetLoginsImpl| and |PasswordStoreConsumer|.
292 // TODO(dubroy): Get rid of this. 289 // TODO(dubroy): Get rid of this.
293 static void CopyAndForwardLoginsResult( 290 static void CopyAndForwardLoginsResult(
294 PasswordStore::GetLoginsRequest* request, 291 scoped_ptr<PasswordStore::GetLoginsRequest> request,
295 ScopedVector<autofill::PasswordForm> matched_forms); 292 ScopedVector<autofill::PasswordForm> matched_forms);
296 293
297 #if defined(PASSWORD_MANAGER_ENABLE_SYNC) 294 #if defined(PASSWORD_MANAGER_ENABLE_SYNC)
298 // Creates PasswordSyncableService instance on the background thread. 295 // Creates PasswordSyncableService instance on the background thread.
299 void InitSyncableService( 296 void InitSyncableService(
300 const syncer::SyncableService::StartSyncFlare& flare); 297 const syncer::SyncableService::StartSyncFlare& flare);
301 298
302 // Deletes PasswordSyncableService instance on the background thread. 299 // Deletes PasswordSyncableService instance on the background thread.
303 void DestroySyncableService(); 300 void DestroySyncableService();
304 #endif 301 #endif
305 302
306 // The observers. 303 // The observers.
307 scoped_refptr<ObserverListThreadSafe<Observer>> observers_; 304 scoped_refptr<ObserverListThreadSafe<Observer>> observers_;
308 305
309 scoped_ptr<PasswordSyncableService> syncable_service_; 306 scoped_ptr<PasswordSyncableService> syncable_service_;
310 307
311 bool shutdown_called_; 308 bool shutdown_called_;
312 309
313 DISALLOW_COPY_AND_ASSIGN(PasswordStore); 310 DISALLOW_COPY_AND_ASSIGN(PasswordStore);
314 }; 311 };
315 312
316 } // namespace password_manager 313 } // namespace password_manager
317 314
318 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_ 315 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698