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

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

Issue 6646051: Fix DCHECK, memory leak, and refactor PasswordStore to use CancelableRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try works all platforms now. Created 9 years, 9 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h"
9 #include "base/task.h" 10 #include "base/task.h"
10 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
11 12
12 using std::vector; 13 using std::vector;
13 using webkit_glue::PasswordForm; 14 using webkit_glue::PasswordForm;
14 15
15 PasswordStore::PasswordStore() : handle_(0) { 16 PasswordStore::PasswordStore() {
16 } 17 }
17 18
18 bool PasswordStore::Init() { 19 bool PasswordStore::Init() {
19 ReportMetrics(); 20 ReportMetrics();
20 return true; 21 return true;
21 } 22 }
22 23
23 void PasswordStore::ScheduleTask(Task* task) { 24 void PasswordStore::ScheduleTask(Task* task) {
24 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, task); 25 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, task);
25 } 26 }
(...skipping 16 matching lines...) Expand all
42 ScheduleTask(NewRunnableMethod(this, &PasswordStore::RemoveLoginImpl, form)); 43 ScheduleTask(NewRunnableMethod(this, &PasswordStore::RemoveLoginImpl, form));
43 } 44 }
44 45
45 void PasswordStore::RemoveLoginsCreatedBetween(const base::Time& delete_begin, 46 void PasswordStore::RemoveLoginsCreatedBetween(const base::Time& delete_begin,
46 const base::Time& delete_end) { 47 const base::Time& delete_end) {
47 ScheduleTask(NewRunnableMethod(this, 48 ScheduleTask(NewRunnableMethod(this,
48 &PasswordStore::RemoveLoginsCreatedBetweenImpl, 49 &PasswordStore::RemoveLoginsCreatedBetweenImpl,
49 delete_begin, delete_end)); 50 delete_begin, delete_end));
50 } 51 }
51 52
52 int PasswordStore::GetLogins(const PasswordForm& form, 53 PasswordStore::Handle PasswordStore::GetLogins(
53 PasswordStoreConsumer* consumer) { 54 const PasswordForm& form, PasswordStoreConsumer* consumer) {
54 int handle = GetNewRequestHandle(); 55 return Schedule(&PasswordStore::GetLoginsImpl, consumer, form);
55 GetLoginsRequest* request = new GetLoginsRequest(consumer, handle);
56 ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetLoginsImpl, request,
57 form));
58 return handle;
59 } 56 }
60 57
61 int PasswordStore::GetAutofillableLogins(PasswordStoreConsumer* consumer) { 58 PasswordStore::Handle PasswordStore::GetAutofillableLogins(
62 int handle = GetNewRequestHandle(); 59 PasswordStoreConsumer* consumer) {
63 GetLoginsRequest* request = new GetLoginsRequest(consumer, handle); 60 return Schedule(&PasswordStore::GetAutofillableLoginsImpl, consumer);
64 ScheduleTask(NewRunnableMethod(this,
65 &PasswordStore::GetAutofillableLoginsImpl,
66 request));
67 return handle;
68 } 61 }
69 62
70 int PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { 63 PasswordStore::Handle PasswordStore::GetBlacklistLogins(
71 int handle = GetNewRequestHandle(); 64 PasswordStoreConsumer* consumer) {
72 GetLoginsRequest* request = new GetLoginsRequest(consumer, handle); 65 return Schedule(&PasswordStore::GetBlacklistLoginsImpl, consumer);
73 ScheduleTask(NewRunnableMethod(this,
74 &PasswordStore::GetBlacklistLoginsImpl,
75 request));
76 return handle;
77 } 66 }
78 67
79 void PasswordStore::NotifyConsumer(GetLoginsRequest* request, 68 void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) {
80 const vector<PasswordForm*>& forms) { 69 request->ForwardResult(GetLoginsRequest::TupleType(request->handle(),
81 scoped_ptr<GetLoginsRequest> request_ptr(request); 70 request->value));
82
83 #if !defined(OS_MACOSX)
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
85 #endif
86 request->message_loop->PostTask(FROM_HERE,
87 NewRunnableMethod(this,
88 &PasswordStore::NotifyConsumerImpl,
89 request->consumer, request->handle, forms));
90 } 71 }
91 72
92 void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer, 73 PasswordStore::GetLoginsRequest::~GetLoginsRequest() {
93 int handle, 74 if (canceled()) {
94 const vector<PasswordForm*>& forms) { 75 STLDeleteElements(&value);
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96 // Don't notify the consumer if the request was canceled.
97 if (pending_requests_.find(handle) == pending_requests_.end()) {
98 // |forms| is const so we iterate rather than use STLDeleteElements().
99 for (size_t i = 0; i < forms.size(); ++i)
100 delete forms[i];
101 return;
102 } 76 }
103 pending_requests_.erase(handle);
104
105 consumer->OnPasswordStoreRequestDone(handle, forms);
106 } 77 }
107
108 int PasswordStore::GetNewRequestHandle() {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 int handle = handle_++;
111 pending_requests_.insert(handle);
112 return handle;
113 }
114
115 void PasswordStore::CancelLoginsQuery(int handle) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 pending_requests_.erase(handle);
118 }
119
120 PasswordStore::GetLoginsRequest::GetLoginsRequest(
121 PasswordStoreConsumer* consumer, int handle)
122 : consumer(consumer), handle(handle), message_loop(MessageLoop::current()) {
123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698