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 void GetIE7Results(const WDTypedResult* result, |
58 const WDTypedResult* result, | 58 const PasswordForm& form, |
59 const PasswordForm& form); | 59 ScopedVector<autofill::PasswordForm>* matched_forms); |
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 |
68 // This creates a cycle between us and PasswordStore. The cycle is broken | 68 // This creates a cycle between us and PasswordStore. The cycle is broken |
69 // from PasswordStoreWin::Shutdown, which deletes us. | 69 // from PasswordStoreWin::Shutdown, which deletes us. |
(...skipping 20 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 void PasswordStoreWin::DBHandler::GetIE7Results( |
vasilii
2015/01/27 20:45:51
I think it's cleaner to return ScopedVector<autofi
vabr (Chromium)
2015/01/28 13:27:36
Done.
| |
101 const WDTypedResult *result, | 101 const WDTypedResult* result, |
102 const PasswordForm& form) { | 102 const PasswordForm& form, |
103 ScopedVector<autofill::PasswordForm>* matched_forms) { | |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
104 std::vector<PasswordForm*> matching_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; | |
138 } | 136 } |
139 | 137 |
140 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( | 138 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( |
141 PasswordWebDataService::Handle handle, | 139 PasswordWebDataService::Handle handle, |
142 const WDTypedResult* result) { | 140 const WDTypedResult* result) { |
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
144 | 142 |
145 PendingRequestMap::iterator i = pending_requests_.find(handle); | 143 PendingRequestMap::iterator i = pending_requests_.find(handle); |
146 DCHECK(i != pending_requests_.end()); | 144 DCHECK(i != pending_requests_.end()); |
147 | 145 |
148 scoped_ptr<PasswordForm> form(i->second.form); | 146 scoped_ptr<PasswordForm> form(i->second.form); |
149 PasswordStoreWin::ConsumerCallbackRunner callback_runner( | 147 PasswordStoreWin::ConsumerCallbackRunner callback_runner( |
150 i->second.callback_runner); | 148 i->second.callback_runner); |
151 pending_requests_.erase(i); | 149 pending_requests_.erase(i); |
152 | 150 |
153 if (!result) { | 151 if (!result) { |
154 // The WDS returns NULL if it is shutting down. Run callback with empty | 152 // The WDS returns NULL if it is shutting down. Run callback with empty |
155 // result. | 153 // result. |
156 callback_runner.Run(std::vector<autofill::PasswordForm*>()); | 154 ScopedVector<autofill::PasswordForm> dummy; |
155 callback_runner.Run(&dummy); | |
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 ScopedVector<autofill::PasswordForm> matched_forms; |
162 GetIE7Results(result, *form); | 161 GetIE7Results(result, *form, &matched_forms); |
163 | 162 |
164 callback_runner.Run(matched_forms); | 163 callback_runner.Run(&matched_forms); |
165 } | 164 } |
166 | 165 |
167 PasswordStoreWin::PasswordStoreWin( | 166 PasswordStoreWin::PasswordStoreWin( |
168 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 167 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
169 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 168 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
170 scoped_ptr<password_manager::LoginDatabase> login_db, | 169 scoped_ptr<password_manager::LoginDatabase> login_db, |
171 const scoped_refptr<PasswordWebDataService>& web_data_service) | 170 const scoped_refptr<PasswordWebDataService>& web_data_service) |
172 : PasswordStoreDefault(main_thread_runner, | 171 : PasswordStoreDefault(main_thread_runner, |
173 db_thread_runner, | 172 db_thread_runner, |
174 login_db.Pass()) { | 173 login_db.Pass()) { |
(...skipping 11 matching lines...) Expand all Loading... | |
186 void PasswordStoreWin::Shutdown() { | 185 void PasswordStoreWin::Shutdown() { |
187 BrowserThread::PostTask( | 186 BrowserThread::PostTask( |
188 BrowserThread::DB, FROM_HERE, | 187 BrowserThread::DB, FROM_HERE, |
189 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); | 188 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); |
190 PasswordStoreDefault::Shutdown(); | 189 PasswordStoreDefault::Shutdown(); |
191 } | 190 } |
192 | 191 |
193 void PasswordStoreWin::GetIE7LoginIfNecessary( | 192 void PasswordStoreWin::GetIE7LoginIfNecessary( |
194 const PasswordForm& form, | 193 const PasswordForm& form, |
195 const ConsumerCallbackRunner& callback_runner, | 194 const ConsumerCallbackRunner& callback_runner, |
196 const std::vector<autofill::PasswordForm*>& matched_forms) { | 195 ScopedVector<autofill::PasswordForm>* matched_forms) { |
vasilii
2015/01/27 20:45:51
If you change the type of ConsumerCallbackRunner t
vabr (Chromium)
2015/01/28 13:27:36
Done.
| |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
198 if (matched_forms.empty() && db_handler_.get()) { | 197 if (matched_forms->empty() && db_handler_) { |
199 db_handler_->GetIE7Login(form, callback_runner); | 198 db_handler_->GetIE7Login(form, callback_runner); |
200 } else { | 199 } else { |
201 // No need to get IE7 login. | 200 // No need to get IE7 login. |
202 callback_runner.Run(matched_forms); | 201 callback_runner.Run(matched_forms); |
203 } | 202 } |
204 } | 203 } |
205 | 204 |
206 void PasswordStoreWin::GetLoginsImpl( | 205 void PasswordStoreWin::GetLoginsImpl( |
207 const PasswordForm& form, | 206 const PasswordForm& form, |
208 AuthorizationPromptPolicy prompt_policy, | 207 AuthorizationPromptPolicy prompt_policy, |
209 const ConsumerCallbackRunner& callback_runner) { | 208 const ConsumerCallbackRunner& callback_runner) { |
210 ConsumerCallbackRunner get_ie7_login = | 209 ConsumerCallbackRunner get_ie7_login = |
211 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, | 210 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, |
212 this, form, callback_runner); | 211 this, form, callback_runner); |
213 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); | 212 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); |
214 } | 213 } |
OLD | NEW |