| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/password_web_data_service_win.h" |
| 15 #include "components/os_crypt/ie7_password_win.h" | 15 #include "components/os_crypt/ie7_password_win.h" |
| 16 #include "components/password_manager/core/browser/password_manager.h" | 16 #include "components/password_manager/core/browser/password_manager.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 using autofill::PasswordForm; | 19 using autofill::PasswordForm; |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using password_manager::PasswordStoreDefault; | 21 using password_manager::PasswordStoreDefault; |
| 22 | 22 |
| 23 // Handles requests to WebDataService. | 23 // Handles requests to PasswordWebDataService. |
| 24 class PasswordStoreWin::DBHandler : public WebDataServiceConsumer { | 24 class PasswordStoreWin::DBHandler : public WebDataServiceConsumer { |
| 25 public: | 25 public: |
| 26 DBHandler(WebDataService* web_data_service, | 26 DBHandler(PasswordWebDataService* web_data_service, |
| 27 PasswordStoreWin* password_store) | 27 PasswordStoreWin* password_store) |
| 28 : web_data_service_(web_data_service), | 28 : web_data_service_(web_data_service), |
| 29 password_store_(password_store) { | 29 password_store_(password_store) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 ~DBHandler(); | 32 ~DBHandler(); |
| 33 | 33 |
| 34 // Requests the IE7 login for |form|. This is async. |callback_runner| will be | 34 // Requests the IE7 login for |form|. This is async. |callback_runner| will be |
| 35 // run when complete. | 35 // run when complete. |
| 36 void GetIE7Login( | 36 void GetIE7Login( |
| 37 const PasswordForm& form, | 37 const PasswordForm& form, |
| 38 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner); | 38 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner); |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 struct RequestInfo { | 41 struct RequestInfo { |
| 42 RequestInfo() {} | 42 RequestInfo() {} |
| 43 | 43 |
| 44 RequestInfo(PasswordForm* request_form, | 44 RequestInfo(PasswordForm* request_form, |
| 45 const PasswordStoreWin::ConsumerCallbackRunner& runner) | 45 const PasswordStoreWin::ConsumerCallbackRunner& runner) |
| 46 : form(request_form), | 46 : form(request_form), |
| 47 callback_runner(runner) {} | 47 callback_runner(runner) {} |
| 48 | 48 |
| 49 PasswordForm* form; | 49 PasswordForm* form; |
| 50 PasswordStoreWin::ConsumerCallbackRunner callback_runner; | 50 PasswordStoreWin::ConsumerCallbackRunner callback_runner; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Holds info associated with in-flight GetIE7Login requests. | 53 // Holds info associated with in-flight GetIE7Login requests. |
| 54 typedef std::map<WebDataService::Handle, RequestInfo> PendingRequestMap; | 54 typedef std::map<PasswordWebDataService::Handle, RequestInfo> |
| 55 PendingRequestMap; |
| 55 | 56 |
| 56 // Gets logins from IE7 if no others are found. Also copies them into | 57 // Gets logins from IE7 if no others are found. Also copies them into |
| 57 // Chrome's WebDatabase so we don't need to look next time. | 58 // Chrome's WebDatabase so we don't need to look next time. |
| 58 std::vector<autofill::PasswordForm*> GetIE7Results( | 59 std::vector<autofill::PasswordForm*> GetIE7Results( |
| 59 const WDTypedResult* result, | 60 const WDTypedResult* result, |
| 60 const PasswordForm& form); | 61 const PasswordForm& form); |
| 61 | 62 |
| 62 // WebDataServiceConsumer implementation. | 63 // WebDataServiceConsumer implementation. |
| 63 virtual void OnWebDataServiceRequestDone( | 64 virtual void OnWebDataServiceRequestDone( |
| 64 WebDataService::Handle handle, | 65 PasswordWebDataService::Handle handle, |
| 65 const WDTypedResult* result) OVERRIDE; | 66 const WDTypedResult* result) OVERRIDE; |
| 66 | 67 |
| 67 scoped_refptr<WebDataService> web_data_service_; | 68 scoped_refptr<PasswordWebDataService> web_data_service_; |
| 68 | 69 |
| 69 // This creates a cycle between us and PasswordStore. The cycle is broken | 70 // This creates a cycle between us and PasswordStore. The cycle is broken |
| 70 // from PasswordStoreWin::Shutdown, which deletes us. | 71 // from PasswordStoreWin::Shutdown, which deletes us. |
| 71 scoped_refptr<PasswordStoreWin> password_store_; | 72 scoped_refptr<PasswordStoreWin> password_store_; |
| 72 | 73 |
| 73 PendingRequestMap pending_requests_; | 74 PendingRequestMap pending_requests_; |
| 74 | 75 |
| 75 DISALLOW_COPY_AND_ASSIGN(DBHandler); | 76 DISALLOW_COPY_AND_ASSIGN(DBHandler); |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 PasswordStoreWin::DBHandler::~DBHandler() { | 79 PasswordStoreWin::DBHandler::~DBHandler() { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 80 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); | 81 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); |
| 81 i != pending_requests_.end(); | 82 i != pending_requests_.end(); |
| 82 ++i) { | 83 ++i) { |
| 83 web_data_service_->CancelRequest(i->first); | 84 web_data_service_->CancelRequest(i->first); |
| 84 delete i->second.form; | 85 delete i->second.form; |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 void PasswordStoreWin::DBHandler::GetIE7Login( | 89 void PasswordStoreWin::DBHandler::GetIE7Login( |
| 89 const PasswordForm& form, | 90 const PasswordForm& form, |
| 90 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { | 91 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 92 IE7PasswordInfo info; | 93 IE7PasswordInfo info; |
| 93 info.url_hash = | 94 info.url_hash = |
| 94 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); | 95 ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); |
| 95 WebDataService::Handle handle = web_data_service_->GetIE7Login(info, this); | 96 PasswordWebDataService::Handle handle = |
| 97 web_data_service_->GetIE7Login(info, this); |
| 96 pending_requests_[handle] = | 98 pending_requests_[handle] = |
| 97 RequestInfo(new PasswordForm(form), callback_runner); | 99 RequestInfo(new PasswordForm(form), callback_runner); |
| 98 } | 100 } |
| 99 | 101 |
| 100 std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results( | 102 std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results( |
| 101 const WDTypedResult *result, | 103 const WDTypedResult *result, |
| 102 const PasswordForm& form) { | 104 const PasswordForm& form) { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 104 std::vector<PasswordForm*> matching_forms; | 106 std::vector<PasswordForm*> matching_forms; |
| 105 | 107 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 131 // Add this PasswordForm to the saved password table. We're on the DB | 133 // Add this PasswordForm to the saved password table. We're on the DB |
| 132 // thread already, so we use AddLoginImpl. | 134 // thread already, so we use AddLoginImpl. |
| 133 password_store_->AddLoginImpl(*autofill); | 135 password_store_->AddLoginImpl(*autofill); |
| 134 } | 136 } |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 return matching_forms; | 139 return matching_forms; |
| 138 } | 140 } |
| 139 | 141 |
| 140 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( | 142 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( |
| 141 WebDataService::Handle handle, | 143 PasswordWebDataService::Handle handle, |
| 142 const WDTypedResult* result) { | 144 const WDTypedResult* result) { |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 144 | 146 |
| 145 PendingRequestMap::iterator i = pending_requests_.find(handle); | 147 PendingRequestMap::iterator i = pending_requests_.find(handle); |
| 146 DCHECK(i != pending_requests_.end()); | 148 DCHECK(i != pending_requests_.end()); |
| 147 | 149 |
| 148 scoped_ptr<PasswordForm> form(i->second.form); | 150 scoped_ptr<PasswordForm> form(i->second.form); |
| 149 PasswordStoreWin::ConsumerCallbackRunner callback_runner( | 151 PasswordStoreWin::ConsumerCallbackRunner callback_runner( |
| 150 i->second.callback_runner); | 152 i->second.callback_runner); |
| 151 pending_requests_.erase(i); | 153 pending_requests_.erase(i); |
| 152 | 154 |
| 153 if (!result) { | 155 if (!result) { |
| 154 // The WDS returns NULL if it is shutting down. Run callback with empty | 156 // The WDS returns NULL if it is shutting down. Run callback with empty |
| 155 // result. | 157 // result. |
| 156 callback_runner.Run(std::vector<autofill::PasswordForm*>()); | 158 callback_runner.Run(std::vector<autofill::PasswordForm*>()); |
| 157 return; | 159 return; |
| 158 } | 160 } |
| 159 | 161 |
| 160 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); | 162 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); |
| 161 std::vector<autofill::PasswordForm*> matched_forms = | 163 std::vector<autofill::PasswordForm*> matched_forms = |
| 162 GetIE7Results(result, *form); | 164 GetIE7Results(result, *form); |
| 163 | 165 |
| 164 callback_runner.Run(matched_forms); | 166 callback_runner.Run(matched_forms); |
| 165 } | 167 } |
| 166 | 168 |
| 167 PasswordStoreWin::PasswordStoreWin( | 169 PasswordStoreWin::PasswordStoreWin( |
| 168 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 170 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
| 169 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 171 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
| 170 password_manager::LoginDatabase* login_database, | 172 password_manager::LoginDatabase* login_database, |
| 171 WebDataService* web_data_service) | 173 PasswordWebDataService* web_data_service) |
| 172 : PasswordStoreDefault(main_thread_runner, | 174 : PasswordStoreDefault(main_thread_runner, |
| 173 db_thread_runner, | 175 db_thread_runner, |
| 174 login_database) { | 176 login_database) { |
| 175 db_handler_.reset(new DBHandler(web_data_service, this)); | 177 db_handler_.reset(new DBHandler(web_data_service, this)); |
| 176 } | 178 } |
| 177 | 179 |
| 178 PasswordStoreWin::~PasswordStoreWin() { | 180 PasswordStoreWin::~PasswordStoreWin() { |
| 179 } | 181 } |
| 180 | 182 |
| 181 void PasswordStoreWin::ShutdownOnDBThread() { | 183 void PasswordStoreWin::ShutdownOnDBThread() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 205 | 207 |
| 206 void PasswordStoreWin::GetLoginsImpl( | 208 void PasswordStoreWin::GetLoginsImpl( |
| 207 const PasswordForm& form, | 209 const PasswordForm& form, |
| 208 AuthorizationPromptPolicy prompt_policy, | 210 AuthorizationPromptPolicy prompt_policy, |
| 209 const ConsumerCallbackRunner& callback_runner) { | 211 const ConsumerCallbackRunner& callback_runner) { |
| 210 ConsumerCallbackRunner get_ie7_login = | 212 ConsumerCallbackRunner get_ie7_login = |
| 211 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, | 213 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, |
| 212 this, form, callback_runner); | 214 this, form, callback_runner); |
| 213 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); | 215 PasswordStoreDefault::GetLoginsImpl(form, prompt_policy, get_ie7_login); |
| 214 } | 216 } |
| OLD | NEW |