| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/profiler/scoped_tracker.h" | 18 #include "base/profiler/scoped_tracker.h" |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "components/os_crypt/ie7_password_win.h" | 21 #include "components/os_crypt/ie7_password_win.h" |
| 21 #include "components/password_manager/core/browser/password_manager.h" | 22 #include "components/password_manager/core/browser/password_manager.h" |
| 22 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" | 23 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 | 25 |
| 25 using autofill::PasswordForm; | 26 using autofill::PasswordForm; |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using password_manager::PasswordStore; |
| 27 using password_manager::PasswordStoreDefault; | 29 using password_manager::PasswordStoreDefault; |
| 28 | 30 |
| 29 // Handles requests to PasswordWebDataService. | 31 // Handles requests to PasswordWebDataService. |
| 30 class PasswordStoreWin::DBHandler : public WebDataServiceConsumer { | 32 class PasswordStoreWin::DBHandler : public WebDataServiceConsumer { |
| 31 public: | 33 public: |
| 32 typedef base::Callback<void(ScopedVector<PasswordForm>)> ResultCallback; | 34 typedef base::Callback<void(ScopedVector<PasswordForm>)> ResultCallback; |
| 33 | 35 |
| 34 DBHandler(const scoped_refptr<PasswordWebDataService>& web_data_service, | 36 DBHandler(const scoped_refptr<PasswordWebDataService>& web_data_service, |
| 35 PasswordStoreWin* password_store) | 37 PasswordStoreWin* password_store) |
| 36 : web_data_service_(web_data_service), password_store_(password_store) {} | 38 : web_data_service_(web_data_service), password_store_(password_store) {} |
| 37 | 39 |
| 38 ~DBHandler() override; | 40 ~DBHandler() override; |
| 39 | 41 |
| 40 // Requests the IE7 login for |form|. This is async. |result_callback| will be | 42 // Requests the IE7 login for |form|. This is async. |result_callback| will be |
| 41 // run when complete. | 43 // run when complete. |
| 42 void GetIE7Login(const PasswordForm& form, | 44 void GetIE7Login(const PasswordStore::FormDigest& form, |
| 43 const ResultCallback& result_callback); | 45 const ResultCallback& result_callback); |
| 44 | 46 |
| 45 private: | 47 private: |
| 46 struct RequestInfo { | 48 struct RequestInfo { |
| 47 RequestInfo() {} | 49 RequestInfo() {} |
| 48 | 50 |
| 49 RequestInfo(PasswordForm* request_form, | 51 RequestInfo(std::unique_ptr<PasswordStore::FormDigest> request_form, |
| 50 const ResultCallback& result_callback) | 52 const ResultCallback& result_callback) |
| 51 : form(request_form), result_callback(result_callback) {} | 53 : form(std::move(request_form)), result_callback(result_callback) {} |
| 52 | 54 |
| 53 PasswordForm* form; | 55 std::unique_ptr<PasswordStore::FormDigest> form; |
| 54 ResultCallback result_callback; | 56 ResultCallback result_callback; |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 // Holds info associated with in-flight GetIE7Login requests. | 59 // Holds info associated with in-flight GetIE7Login requests. |
| 58 typedef std::map<PasswordWebDataService::Handle, RequestInfo> | 60 typedef std::map<PasswordWebDataService::Handle, RequestInfo> |
| 59 PendingRequestMap; | 61 PendingRequestMap; |
| 60 | 62 |
| 61 // Gets logins from IE7 if no others are found. Also copies them into | 63 // Gets logins from IE7 if no others are found. Also copies them into |
| 62 // Chrome's WebDatabase so we don't need to look next time. | 64 // Chrome's WebDatabase so we don't need to look next time. |
| 63 ScopedVector<autofill::PasswordForm> GetIE7Results( | 65 ScopedVector<autofill::PasswordForm> GetIE7Results( |
| 64 const WDTypedResult* result, | 66 const WDTypedResult* result, |
| 65 const PasswordForm& form); | 67 const PasswordStore::FormDigest& form); |
| 66 | 68 |
| 67 // WebDataServiceConsumer implementation. | 69 // WebDataServiceConsumer implementation. |
| 68 void OnWebDataServiceRequestDone( | 70 void OnWebDataServiceRequestDone( |
| 69 PasswordWebDataService::Handle handle, | 71 PasswordWebDataService::Handle handle, |
| 70 const WDTypedResult* result) override; | 72 const WDTypedResult* result) override; |
| 71 | 73 |
| 72 scoped_refptr<PasswordWebDataService> web_data_service_; | 74 scoped_refptr<PasswordWebDataService> web_data_service_; |
| 73 | 75 |
| 74 // This creates a cycle between us and PasswordStore. The cycle is broken | 76 // This creates a cycle between us and PasswordStore. The cycle is broken |
| 75 // from PasswordStoreWin::ShutdownOnUIThread, which deletes us. | 77 // from PasswordStoreWin::ShutdownOnUIThread, which deletes us. |
| 76 scoped_refptr<PasswordStoreWin> password_store_; | 78 scoped_refptr<PasswordStoreWin> password_store_; |
| 77 | 79 |
| 78 PendingRequestMap pending_requests_; | 80 PendingRequestMap pending_requests_; |
| 79 | 81 |
| 80 DISALLOW_COPY_AND_ASSIGN(DBHandler); | 82 DISALLOW_COPY_AND_ASSIGN(DBHandler); |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 PasswordStoreWin::DBHandler::~DBHandler() { | 85 PasswordStoreWin::DBHandler::~DBHandler() { |
| 84 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 86 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 85 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); | 87 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); |
| 86 i != pending_requests_.end(); | 88 i != pending_requests_.end(); |
| 87 ++i) { | 89 ++i) { |
| 88 web_data_service_->CancelRequest(i->first); | 90 web_data_service_->CancelRequest(i->first); |
| 89 delete i->second.form; | |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 void PasswordStoreWin::DBHandler::GetIE7Login( | 94 void PasswordStoreWin::DBHandler::GetIE7Login( |
| 94 const PasswordForm& form, | 95 const PasswordStore::FormDigest& form, |
| 95 const ResultCallback& result_callback) { | 96 const ResultCallback& result_callback) { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 97 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 97 IE7PasswordInfo info; | 98 IE7PasswordInfo info; |
| 98 info.url_hash = | 99 info.url_hash = |
| 99 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); | 100 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); |
| 100 PasswordWebDataService::Handle handle = | 101 PasswordWebDataService::Handle handle = |
| 101 web_data_service_->GetIE7Login(info, this); | 102 web_data_service_->GetIE7Login(info, this); |
| 102 pending_requests_[handle] = | 103 pending_requests_[handle] = { |
| 103 RequestInfo(new PasswordForm(form), result_callback); | 104 base::WrapUnique(new PasswordStore::FormDigest(form)), result_callback}; |
| 104 } | 105 } |
| 105 | 106 |
| 106 ScopedVector<autofill::PasswordForm> PasswordStoreWin::DBHandler::GetIE7Results( | 107 ScopedVector<autofill::PasswordForm> PasswordStoreWin::DBHandler::GetIE7Results( |
| 107 const WDTypedResult* result, | 108 const WDTypedResult* result, |
| 108 const PasswordForm& form) { | 109 const PasswordStore::FormDigest& form) { |
| 109 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 110 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 110 ScopedVector<autofill::PasswordForm> matched_forms; | 111 ScopedVector<autofill::PasswordForm> matched_forms; |
| 111 const WDResult<IE7PasswordInfo>* r = | 112 const WDResult<IE7PasswordInfo>* r = |
| 112 static_cast<const WDResult<IE7PasswordInfo>*>(result); | 113 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
| 113 IE7PasswordInfo info = r->GetValue(); | 114 IE7PasswordInfo info = r->GetValue(); |
| 114 | 115 |
| 115 if (!info.encrypted_data.empty()) { | 116 if (!info.encrypted_data.empty()) { |
| 116 // We got a result. | 117 // We got a result. |
| 117 // Delete the entry. If it's good we will add it to the real saved password | 118 // Delete the entry. If it's good we will add it to the real saved password |
| 118 // table. | 119 // table. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 148 // fixed. | 149 // fixed. |
| 149 tracked_objects::ScopedTracker tracking_profile( | 150 tracked_objects::ScopedTracker tracking_profile( |
| 150 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 151 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 151 "422460 PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone")); | 152 "422460 PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone")); |
| 152 | 153 |
| 153 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 154 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 154 | 155 |
| 155 PendingRequestMap::iterator i = pending_requests_.find(handle); | 156 PendingRequestMap::iterator i = pending_requests_.find(handle); |
| 156 DCHECK(i != pending_requests_.end()); | 157 DCHECK(i != pending_requests_.end()); |
| 157 | 158 |
| 158 std::unique_ptr<PasswordForm> form(i->second.form); | |
| 159 ResultCallback result_callback(i->second.result_callback); | 159 ResultCallback result_callback(i->second.result_callback); |
| 160 std::unique_ptr<PasswordStore::FormDigest> form = std::move(i->second.form); |
| 160 pending_requests_.erase(i); | 161 pending_requests_.erase(i); |
| 161 | 162 |
| 162 if (!result) { | 163 if (!result) { |
| 163 // The WDS returns NULL if it is shutting down. Run callback with empty | 164 // The WDS returns NULL if it is shutting down. Run callback with empty |
| 164 // result. | 165 // result. |
| 165 result_callback.Run(ScopedVector<autofill::PasswordForm>()); | 166 result_callback.Run(ScopedVector<autofill::PasswordForm>()); |
| 166 return; | 167 return; |
| 167 } | 168 } |
| 168 | 169 |
| 169 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); | 170 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 190 } | 191 } |
| 191 | 192 |
| 192 void PasswordStoreWin::ShutdownOnUIThread() { | 193 void PasswordStoreWin::ShutdownOnUIThread() { |
| 193 BrowserThread::PostTask( | 194 BrowserThread::PostTask( |
| 194 BrowserThread::DB, FROM_HERE, | 195 BrowserThread::DB, FROM_HERE, |
| 195 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); | 196 base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this)); |
| 196 PasswordStoreDefault::ShutdownOnUIThread(); | 197 PasswordStoreDefault::ShutdownOnUIThread(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void PasswordStoreWin::GetLoginsImpl( | 200 void PasswordStoreWin::GetLoginsImpl( |
| 200 const PasswordForm& form, | 201 const PasswordStore::FormDigest& form, |
| 201 std::unique_ptr<GetLoginsRequest> request) { | 202 std::unique_ptr<GetLoginsRequest> request) { |
| 202 // When importing from IE7, the credentials are first stored into a temporary | 203 // When importing from IE7, the credentials are first stored into a temporary |
| 203 // Web SQL database. Then, after each GetLogins() request that does not yield | 204 // Web SQL database. Then, after each GetLogins() request that does not yield |
| 204 // any matches from the LoginDatabase, the matching credentials in the Web SQL | 205 // any matches from the LoginDatabase, the matching credentials in the Web SQL |
| 205 // database, if any, are returned as results instead, and simultaneously get | 206 // database, if any, are returned as results instead, and simultaneously get |
| 206 // moved to the LoginDatabase, so next time they will be found immediately. | 207 // moved to the LoginDatabase, so next time they will be found immediately. |
| 207 // TODO(engedy): Make the IE7-specific code synchronous, so FillMatchingLogins | 208 // TODO(engedy): Make the IE7-specific code synchronous, so FillMatchingLogins |
| 208 // can be overridden instead. See: https://crbug.com/78830. | 209 // can be overridden instead. See: https://crbug.com/78830. |
| 209 // TODO(engedy): Credentials should be imported into the LoginDatabase in the | 210 // TODO(engedy): Credentials should be imported into the LoginDatabase in the |
| 210 // first place. See: https://crbug.com/456119. | 211 // first place. See: https://crbug.com/456119. |
| 211 ScopedVector<autofill::PasswordForm> matched_forms(FillMatchingLogins(form)); | 212 ScopedVector<autofill::PasswordForm> matched_forms(FillMatchingLogins(form)); |
| 212 if (matched_forms.empty() && db_handler_) { | 213 if (matched_forms.empty() && db_handler_) { |
| 213 db_handler_->GetIE7Login( | 214 db_handler_->GetIE7Login( |
| 214 form, base::Bind(&GetLoginsRequest::NotifyConsumerWithResults, | 215 form, base::Bind(&GetLoginsRequest::NotifyConsumerWithResults, |
| 215 base::Owned(request.release()))); | 216 base::Owned(request.release()))); |
| 216 } else { | 217 } else { |
| 217 request->NotifyConsumerWithResults(std::move(matched_forms)); | 218 request->NotifyConsumerWithResults(std::move(matched_forms)); |
| 218 } | 219 } |
| 219 } | 220 } |
| OLD | NEW |