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 #include "chrome/browser/password_manager/password_store_win.h" | 5 #include "chrome/browser/password_manager/password_store_win.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 PasswordForm* form; | 47 PasswordForm* form; |
48 PasswordStoreWin::ConsumerCallbackRunner callback_runner; | 48 PasswordStoreWin::ConsumerCallbackRunner callback_runner; |
49 }; | 49 }; |
50 | 50 |
51 // Holds info associated with in-flight GetIE7Login requests. | 51 // Holds info associated with in-flight GetIE7Login requests. |
52 typedef std::map<PasswordWebDataService::Handle, RequestInfo> | 52 typedef std::map<PasswordWebDataService::Handle, RequestInfo> |
53 PendingRequestMap; | 53 PendingRequestMap; |
54 | 54 |
55 // Gets logins from IE7 if no others are found. Also copies them into | 55 // Gets logins from IE7 if no others are found. Also copies them into |
56 // Chrome's WebDatabase so we don't need to look next time. | 56 // Chrome's WebDatabase so we don't need to look next time. |
57 std::vector<autofill::PasswordForm*> GetIE7Results( | 57 ScopedVector<autofill::PasswordForm> GetIE7Results( |
58 const WDTypedResult* result, | 58 const WDTypedResult* result, |
59 const PasswordForm& form); | 59 const PasswordForm& form); |
60 | 60 |
61 // WebDataServiceConsumer implementation. | 61 // WebDataServiceConsumer implementation. |
62 virtual void OnWebDataServiceRequestDone( | 62 virtual void OnWebDataServiceRequestDone( |
63 PasswordWebDataService::Handle handle, | 63 PasswordWebDataService::Handle handle, |
64 const WDTypedResult* result) override; | 64 const WDTypedResult* result) override; |
65 | 65 |
66 scoped_refptr<PasswordWebDataService> web_data_service_; | 66 scoped_refptr<PasswordWebDataService> web_data_service_; |
67 | 67 |
(...skipping 22 matching lines...) Expand all Loading... |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
91 IE7PasswordInfo info; | 91 IE7PasswordInfo info; |
92 info.url_hash = | 92 info.url_hash = |
93 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); | 93 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); |
94 PasswordWebDataService::Handle handle = | 94 PasswordWebDataService::Handle handle = |
95 web_data_service_->GetIE7Login(info, this); | 95 web_data_service_->GetIE7Login(info, this); |
96 pending_requests_[handle] = | 96 pending_requests_[handle] = |
97 RequestInfo(new PasswordForm(form), callback_runner); | 97 RequestInfo(new PasswordForm(form), callback_runner); |
98 } | 98 } |
99 | 99 |
100 std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results( | 100 ScopedVector<autofill::PasswordForm> PasswordStoreWin::DBHandler::GetIE7Results( |
101 const WDTypedResult *result, | 101 const WDTypedResult* result, |
102 const PasswordForm& form) { | 102 const PasswordForm& form) { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
104 std::vector<PasswordForm*> matching_forms; | 104 ScopedVector<autofill::PasswordForm> matched_forms; |
105 | |
106 const WDResult<IE7PasswordInfo>* r = | 105 const WDResult<IE7PasswordInfo>* r = |
107 static_cast<const WDResult<IE7PasswordInfo>*>(result); | 106 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
108 IE7PasswordInfo info = r->GetValue(); | 107 IE7PasswordInfo info = r->GetValue(); |
109 | 108 |
110 if (!info.encrypted_data.empty()) { | 109 if (!info.encrypted_data.empty()) { |
111 // We got a result. | 110 // We got a result. |
112 // Delete the entry. If it's good we will add it to the real saved password | 111 // Delete the entry. If it's good we will add it to the real saved password |
113 // table. | 112 // table. |
114 web_data_service_->RemoveIE7Login(info); | 113 web_data_service_->RemoveIE7Login(info); |
115 std::vector<ie7_password::DecryptedCredentials> credentials; | 114 std::vector<ie7_password::DecryptedCredentials> credentials; |
116 base::string16 url = base::ASCIIToUTF16(form.origin.spec()); | 115 base::string16 url = base::ASCIIToUTF16(form.origin.spec()); |
117 if (ie7_password::DecryptPasswords(url, | 116 if (ie7_password::DecryptPasswords(url, |
118 info.encrypted_data, | 117 info.encrypted_data, |
119 &credentials)) { | 118 &credentials)) { |
120 for (size_t i = 0; i < credentials.size(); ++i) { | 119 for (size_t i = 0; i < credentials.size(); ++i) { |
121 PasswordForm* autofill = new PasswordForm(); | 120 PasswordForm* autofill = new PasswordForm(); |
122 autofill->username_value = credentials[i].username; | 121 autofill->username_value = credentials[i].username; |
123 autofill->password_value = credentials[i].password; | 122 autofill->password_value = credentials[i].password; |
124 autofill->signon_realm = form.signon_realm; | 123 autofill->signon_realm = form.signon_realm; |
125 autofill->origin = form.origin; | 124 autofill->origin = form.origin; |
126 autofill->preferred = true; | 125 autofill->preferred = true; |
127 autofill->ssl_valid = form.origin.SchemeIsSecure(); | 126 autofill->ssl_valid = form.origin.SchemeIsSecure(); |
128 autofill->date_created = info.date_created; | 127 autofill->date_created = info.date_created; |
129 | 128 |
130 matching_forms.push_back(autofill); | 129 matched_forms.push_back(autofill); |
131 // Add this PasswordForm to the saved password table. We're on the DB | 130 // Add this PasswordForm to the saved password table. We're on the DB |
132 // thread already, so we use AddLoginImpl. | 131 // thread already, so we use AddLoginImpl. |
133 password_store_->AddLoginImpl(*autofill); | 132 password_store_->AddLoginImpl(*autofill); |
134 } | 133 } |
135 } | 134 } |
136 } | 135 } |
137 return matching_forms; | 136 return matched_forms.Pass(); |
138 } | 137 } |
139 | 138 |
140 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( | 139 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( |
141 PasswordWebDataService::Handle handle, | 140 PasswordWebDataService::Handle handle, |
142 const WDTypedResult* result) { | 141 const WDTypedResult* result) { |
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
144 | 143 |
145 PendingRequestMap::iterator i = pending_requests_.find(handle); | 144 PendingRequestMap::iterator i = pending_requests_.find(handle); |
146 DCHECK(i != pending_requests_.end()); | 145 DCHECK(i != pending_requests_.end()); |
147 | 146 |
148 scoped_ptr<PasswordForm> form(i->second.form); | 147 scoped_ptr<PasswordForm> form(i->second.form); |
149 PasswordStoreWin::ConsumerCallbackRunner callback_runner( | 148 PasswordStoreWin::ConsumerCallbackRunner callback_runner( |
150 i->second.callback_runner); | 149 i->second.callback_runner); |
151 pending_requests_.erase(i); | 150 pending_requests_.erase(i); |
152 | 151 |
153 if (!result) { | 152 if (!result) { |
154 // The WDS returns NULL if it is shutting down. Run callback with empty | 153 // The WDS returns NULL if it is shutting down. Run callback with empty |
155 // result. | 154 // result. |
156 callback_runner.Run(std::vector<autofill::PasswordForm*>()); | 155 callback_runner.Run(ScopedVector<autofill::PasswordForm>()); |
157 return; | 156 return; |
158 } | 157 } |
159 | 158 |
160 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); | 159 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); |
161 std::vector<autofill::PasswordForm*> matched_forms = | 160 callback_runner.Run(GetIE7Results(result, *form)); |
162 GetIE7Results(result, *form); | |
163 | |
164 callback_runner.Run(matched_forms); | |
165 } | 161 } |
166 | 162 |
167 PasswordStoreWin::PasswordStoreWin( | 163 PasswordStoreWin::PasswordStoreWin( |
168 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 164 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
169 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 165 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
170 scoped_ptr<password_manager::LoginDatabase> login_db, | 166 scoped_ptr<password_manager::LoginDatabase> login_db, |
171 const scoped_refptr<PasswordWebDataService>& web_data_service) | 167 const scoped_refptr<PasswordWebDataService>& web_data_service) |
172 : PasswordStoreDefault(main_thread_runner, | 168 : PasswordStoreDefault(main_thread_runner, |
173 db_thread_runner, | 169 db_thread_runner, |
174 login_db.Pass()) { | 170 login_db.Pass()) { |
(...skipping 11 matching lines...) Expand all Loading... |
186 void PasswordStoreWin::Shutdown() { | 182 void PasswordStoreWin::Shutdown() { |
187 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
188 BrowserThread::DB, FROM_HERE, | 184 BrowserThread::DB, FROM_HERE, |
189 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); | 185 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); |
190 PasswordStoreDefault::Shutdown(); | 186 PasswordStoreDefault::Shutdown(); |
191 } | 187 } |
192 | 188 |
193 void PasswordStoreWin::GetIE7LoginIfNecessary( | 189 void PasswordStoreWin::GetIE7LoginIfNecessary( |
194 const PasswordForm& form, | 190 const PasswordForm& form, |
195 const ConsumerCallbackRunner& callback_runner, | 191 const ConsumerCallbackRunner& callback_runner, |
196 const std::vector<autofill::PasswordForm*>& matched_forms) { | 192 ScopedVector<autofill::PasswordForm> matched_forms) { |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
198 if (matched_forms.empty() && db_handler_.get()) { | 194 if (matched_forms.empty() && db_handler_) { |
199 db_handler_->GetIE7Login(form, callback_runner); | 195 db_handler_->GetIE7Login(form, callback_runner); |
200 } else { | 196 } else { |
201 // No need to get IE7 login. | 197 // No need to get IE7 login. |
202 callback_runner.Run(matched_forms); | 198 callback_runner.Run(matched_forms.Pass()); |
203 } | 199 } |
204 } | 200 } |
205 | 201 |
206 void PasswordStoreWin::GetLoginsImpl( | 202 void PasswordStoreWin::GetLoginsImpl( |
207 const PasswordForm& form, | 203 const PasswordForm& form, |
208 AuthorizationPromptPolicy prompt_policy, | 204 AuthorizationPromptPolicy prompt_policy, |
209 const ConsumerCallbackRunner& callback_runner) { | 205 const ConsumerCallbackRunner& callback_runner) { |
210 ConsumerCallbackRunner get_ie7_login = | 206 ConsumerCallbackRunner get_ie7_login = |
211 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, | 207 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, |
212 this, form, callback_runner); | 208 this, form, callback_runner); |
213 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); | 209 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); |
214 } | 210 } |
OLD | NEW |