OLD | NEW |
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/task.h" | 9 #include "base/task.h" |
10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 int PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { | 70 int PasswordStore::GetBlacklistLogins(PasswordStoreConsumer* consumer) { |
71 int handle = GetNewRequestHandle(); | 71 int handle = GetNewRequestHandle(); |
72 GetLoginsRequest* request = new GetLoginsRequest(consumer, handle); | 72 GetLoginsRequest* request = new GetLoginsRequest(consumer, handle); |
73 ScheduleTask(NewRunnableMethod(this, | 73 ScheduleTask(NewRunnableMethod(this, |
74 &PasswordStore::GetBlacklistLoginsImpl, | 74 &PasswordStore::GetBlacklistLoginsImpl, |
75 request)); | 75 request)); |
76 return handle; | 76 return handle; |
77 } | 77 } |
78 | 78 |
79 void PasswordStore::NotifyConsumer(GetLoginsRequest* request, | 79 void PasswordStore::NotifyConsumer(GetLoginsRequest* request, |
80 const vector<PasswordForm*> forms) { | 80 const vector<PasswordForm*>& forms) { |
81 scoped_ptr<GetLoginsRequest> request_ptr(request); | 81 scoped_ptr<GetLoginsRequest> request_ptr(request); |
82 | 82 |
83 #if !defined(OS_MACOSX) | 83 #if !defined(OS_MACOSX) |
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
85 #endif | 85 #endif |
86 request->message_loop->PostTask(FROM_HERE, | 86 request->message_loop->PostTask(FROM_HERE, |
87 NewRunnableMethod(this, | 87 NewRunnableMethod(this, |
88 &PasswordStore::NotifyConsumerImpl, | 88 &PasswordStore::NotifyConsumerImpl, |
89 request->consumer, request->handle, forms)); | 89 request->consumer, request->handle, forms)); |
90 } | 90 } |
91 | 91 |
92 void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer, | 92 void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer, |
93 int handle, | 93 int handle, |
94 const vector<PasswordForm*> forms) { | 94 const vector<PasswordForm*>& forms) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
96 // Don't notify the consumer if the request was canceled. | 96 // Don't notify the consumer if the request was canceled. |
97 if (pending_requests_.find(handle) == pending_requests_.end()) { | 97 if (pending_requests_.find(handle) == pending_requests_.end()) { |
98 // |forms| is const so we iterate rather than use STLDeleteElements(). | 98 // |forms| is const so we iterate rather than use STLDeleteElements(). |
99 for (size_t i = 0; i < forms.size(); ++i) | 99 for (size_t i = 0; i < forms.size(); ++i) |
100 delete forms[i]; | 100 delete forms[i]; |
101 return; | 101 return; |
102 } | 102 } |
103 pending_requests_.erase(handle); | 103 pending_requests_.erase(handle); |
104 | 104 |
105 consumer->OnPasswordStoreRequestDone(handle, forms); | 105 consumer->OnPasswordStoreRequestDone(handle, forms); |
106 } | 106 } |
107 | 107 |
108 int PasswordStore::GetNewRequestHandle() { | 108 int PasswordStore::GetNewRequestHandle() { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 int handle = handle_++; | 110 int handle = handle_++; |
111 pending_requests_.insert(handle); | 111 pending_requests_.insert(handle); |
112 return handle; | 112 return handle; |
113 } | 113 } |
114 | 114 |
115 void PasswordStore::CancelLoginsQuery(int handle) { | 115 void PasswordStore::CancelLoginsQuery(int handle) { |
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
117 pending_requests_.erase(handle); | 117 pending_requests_.erase(handle); |
118 } | 118 } |
119 | 119 |
120 PasswordStore::GetLoginsRequest::GetLoginsRequest( | 120 PasswordStore::GetLoginsRequest::GetLoginsRequest( |
121 PasswordStoreConsumer* consumer, int handle) | 121 PasswordStoreConsumer* consumer, int handle) |
122 : consumer(consumer), handle(handle), message_loop(MessageLoop::current()) { | 122 : consumer(consumer), handle(handle), message_loop(MessageLoop::current()) { |
123 } | 123 } |
OLD | NEW |