Chromium Code Reviews| 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 | 47 |
| 48 PasswordForm* form; | 48 PasswordForm* form; |
| 49 PasswordStoreWin::ConsumerCallbackRunner callback_runner; | 49 PasswordStoreWin::ConsumerCallbackRunner callback_runner; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // Holds info associated with in-flight GetIE7Login requests. | 52 // Holds info associated with in-flight GetIE7Login requests. |
| 53 typedef std::map<WebDataService::Handle, RequestInfo> PendingRequestMap; | 53 typedef std::map<WebDataService::Handle, RequestInfo> 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 PasswordForm* GetIE7Result(const WDTypedResult* result, | 57 void GetIE7Results(const WDTypedResult* result, |
| 58 const PasswordForm& form); | 58 const PasswordForm& form, |
| 59 std::vector<autofill::PasswordForm*>* matching_forms); | |
| 59 | 60 |
| 60 // WebDataServiceConsumer implementation. | 61 // WebDataServiceConsumer implementation. |
| 61 virtual void OnWebDataServiceRequestDone( | 62 virtual void OnWebDataServiceRequestDone( |
| 62 WebDataService::Handle handle, | 63 WebDataService::Handle handle, |
| 63 const WDTypedResult* result) OVERRIDE; | 64 const WDTypedResult* result) OVERRIDE; |
| 64 | 65 |
| 65 scoped_refptr<WebDataService> web_data_service_; | 66 scoped_refptr<WebDataService> web_data_service_; |
| 66 | 67 |
| 67 // 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 |
| 68 // from PasswordStoreWin::Shutdown, which deletes us. | 69 // from PasswordStoreWin::Shutdown, which deletes us. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 87 const PasswordForm& form, | 88 const PasswordForm& form, |
| 88 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { | 89 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 90 IE7PasswordInfo info; | 91 IE7PasswordInfo info; |
| 91 info.url_hash = ie7_password::GetUrlHash(UTF8ToWide(form.origin.spec())); | 92 info.url_hash = ie7_password::GetUrlHash(UTF8ToWide(form.origin.spec())); |
| 92 WebDataService::Handle handle = web_data_service_->GetIE7Login(info, this); | 93 WebDataService::Handle handle = web_data_service_->GetIE7Login(info, this); |
| 93 pending_requests_[handle] = | 94 pending_requests_[handle] = |
| 94 RequestInfo(new PasswordForm(form), callback_runner); | 95 RequestInfo(new PasswordForm(form), callback_runner); |
| 95 } | 96 } |
| 96 | 97 |
| 97 PasswordForm* PasswordStoreWin::DBHandler::GetIE7Result( | 98 void PasswordStoreWin::DBHandler::GetIE7Results( |
|
Lei Zhang
2013/10/08 17:49:46
Just return a std::vector<PasswordForm*>, but writ
| |
| 98 const WDTypedResult *result, | 99 const WDTypedResult *result, |
| 99 const PasswordForm& form) { | 100 const PasswordForm& form, |
| 101 std::vector<PasswordForm*>* matching_forms) { | |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 101 | 103 |
| 102 const WDResult<IE7PasswordInfo>* r = | 104 const WDResult<IE7PasswordInfo>* r = |
| 103 static_cast<const WDResult<IE7PasswordInfo>*>(result); | 105 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
| 104 IE7PasswordInfo info = r->GetValue(); | 106 IE7PasswordInfo info = r->GetValue(); |
| 105 | 107 |
| 106 if (!info.encrypted_data.empty()) { | 108 if (!info.encrypted_data.empty()) { |
| 107 // We got a result. | 109 // We got a result. |
| 108 // Delete the entry. If it's good we will add it to the real saved password | 110 // Delete the entry. If it's good we will add it to the real saved password |
| 109 // table. | 111 // table. |
| 110 web_data_service_->RemoveIE7Login(info); | 112 web_data_service_->RemoveIE7Login(info); |
| 111 std::wstring username; | 113 std::vector<ie7_password::DecryptedCredentials> credentials; |
| 112 std::wstring password; | |
| 113 std::wstring url = ASCIIToWide(form.origin.spec()); | 114 std::wstring url = ASCIIToWide(form.origin.spec()); |
| 114 if (!ie7_password::DecryptPassword(url, info.encrypted_data, | 115 if (!ie7_password::DecryptPasswords(url, |
| 115 &username, &password)) { | 116 info.encrypted_data, |
| 116 return NULL; | 117 &credentials)) { |
| 118 return; | |
| 117 } | 119 } |
| 118 | 120 |
| 119 PasswordForm* autofill = new PasswordForm(form); | 121 for (size_t i = 0; i < credentials.size(); ++i) { |
| 120 autofill->username_value = username; | 122 PasswordForm* autofill = new PasswordForm(form); |
| 121 autofill->password_value = password; | 123 autofill->username_value = credentials[i].username; |
| 122 autofill->preferred = true; | 124 autofill->password_value = credentials[i].password; |
| 123 autofill->ssl_valid = form.origin.SchemeIsSecure(); | 125 autofill->preferred = true; |
| 124 autofill->date_created = info.date_created; | 126 autofill->ssl_valid = form.origin.SchemeIsSecure(); |
| 125 // Add this PasswordForm to the saved password table. We're on the DB thread | 127 autofill->date_created = info.date_created; |
| 126 // already, so we use AddLoginImpl. | 128 matching_forms->push_back(autofill); |
| 127 password_store_->AddLoginImpl(*autofill); | 129 // Add this PasswordForm to the saved password table. We're on the DB |
| 128 return autofill; | 130 // thread already, so we use AddLoginImpl. |
| 131 password_store_->AddLoginImpl(*autofill); | |
| 132 } | |
| 129 } | 133 } |
| 130 return NULL; | |
| 131 } | 134 } |
| 132 | 135 |
| 133 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( | 136 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( |
| 134 WebDataService::Handle handle, | 137 WebDataService::Handle handle, |
| 135 const WDTypedResult* result) { | 138 const WDTypedResult* result) { |
| 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 137 | 140 |
| 138 PendingRequestMap::iterator i = pending_requests_.find(handle); | 141 PendingRequestMap::iterator i = pending_requests_.find(handle); |
| 139 DCHECK(i != pending_requests_.end()); | 142 DCHECK(i != pending_requests_.end()); |
| 140 | 143 |
| 141 scoped_ptr<PasswordForm> form(i->second.form); | 144 scoped_ptr<PasswordForm> form(i->second.form); |
| 142 PasswordStoreWin::ConsumerCallbackRunner callback_runner( | 145 PasswordStoreWin::ConsumerCallbackRunner callback_runner( |
| 143 i->second.callback_runner); | 146 i->second.callback_runner); |
| 144 pending_requests_.erase(i); | 147 pending_requests_.erase(i); |
| 145 | 148 |
| 146 std::vector<autofill::PasswordForm*> matched_forms; | 149 std::vector<autofill::PasswordForm*> matched_forms; |
| 147 | 150 |
| 148 if (!result) { | 151 if (!result) { |
| 149 // 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 |
| 150 // result. | 153 // result. |
| 151 callback_runner.Run(matched_forms); | 154 callback_runner.Run(matched_forms); |
| 152 return; | 155 return; |
| 153 } | 156 } |
| 154 | 157 |
| 155 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); | 158 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); |
| 156 PasswordForm* ie7_form = GetIE7Result(result, *form); | 159 GetIE7Results(result, *form, &matched_forms); |
| 157 | |
| 158 if (ie7_form) | |
| 159 matched_forms.push_back(ie7_form); | |
| 160 | 160 |
| 161 callback_runner.Run(matched_forms); | 161 callback_runner.Run(matched_forms); |
| 162 } | 162 } |
| 163 | 163 |
| 164 PasswordStoreWin::PasswordStoreWin(LoginDatabase* login_database, | 164 PasswordStoreWin::PasswordStoreWin(LoginDatabase* login_database, |
| 165 Profile* profile, | 165 Profile* profile, |
| 166 WebDataService* web_data_service) | 166 WebDataService* web_data_service) |
| 167 : PasswordStoreDefault(login_database, profile) { | 167 : PasswordStoreDefault(login_database, profile) { |
| 168 db_handler_.reset(new DBHandler(web_data_service, this)); | 168 db_handler_.reset(new DBHandler(web_data_service, this)); |
| 169 } | 169 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 197 } | 197 } |
| 198 | 198 |
| 199 void PasswordStoreWin::GetLoginsImpl( | 199 void PasswordStoreWin::GetLoginsImpl( |
| 200 const PasswordForm& form, | 200 const PasswordForm& form, |
| 201 const ConsumerCallbackRunner& callback_runner) { | 201 const ConsumerCallbackRunner& callback_runner) { |
| 202 ConsumerCallbackRunner get_ie7_login = | 202 ConsumerCallbackRunner get_ie7_login = |
| 203 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, | 203 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, |
| 204 this, form, callback_runner); | 204 this, form, callback_runner); |
| 205 PasswordStoreDefault::GetLoginsImpl(form, get_ie7_login); | 205 PasswordStoreDefault::GetLoginsImpl(form, get_ie7_login); |
| 206 } | 206 } |
| OLD | NEW |