OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/password_manager/ie7_password.h" | 9 #include "chrome/browser/password_manager/ie7_password.h" |
10 #include "chrome/browser/password_manager/password_manager.h" | 10 #include "chrome/browser/password_manager/password_manager.h" |
11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
12 | 12 |
13 using std::map; | 13 using std::map; |
14 using std::vector; | 14 using std::vector; |
15 | 15 |
16 PasswordStoreWin::PasswordStoreWin(WebDataService* web_data_service) | 16 PasswordStoreWin::PasswordStoreWin(WebDataService* web_data_service) |
17 : PasswordStoreDefault(web_data_service) { | 17 : PasswordStoreDefault(web_data_service) { |
18 } | 18 } |
19 | 19 |
20 void PasswordStoreWin::OnWebDataServiceRequestDone( | 20 void PasswordStoreWin::OnWebDataServiceRequestDone( |
21 WebDataService::Handle h, const WDTypedResult *result) { | 21 WebDataService::Handle h, const WDTypedResult *result) { |
22 // Look up this handle in our request map to get the original | 22 // Look up this handle in our request map to get the original |
23 // GetLoginsRequest. | 23 // GetLoginsRequest. |
24 GetLoginsRequest* request = GetLoginsRequestForWebDataServiceRequest(h); | 24 PendingRequestMap::iterator it(pending_requests_.find(h)); |
25 DCHECK(request); | 25 // If the request was cancelled, we are done. |
26 // Remove our pending request, but make sure that we won't be destroyed until | 26 if (it == pending_requests_.end()) |
27 // we're done with this function. | 27 return; |
28 scoped_refptr<PasswordStoreWin> life_preserver(this); | 28 |
29 RemovePendingWebDataServiceRequest(h); | 29 scoped_ptr<GetLoginsRequest> request(it->second); |
| 30 pending_requests_.erase(it); |
30 | 31 |
31 DCHECK(result); | 32 DCHECK(result); |
32 if (!result) | 33 if (!result) |
33 return; | 34 return; |
34 | 35 |
35 switch (result->GetType()) { | 36 switch (result->GetType()) { |
36 case PASSWORD_RESULT: { | 37 case PASSWORD_RESULT: { |
37 // This is a response from WebDataService::GetLogins. | 38 // This is a response from WebDataService::GetLogins. |
38 const WDResult<std::vector<PasswordForm*> >* r = | 39 const WDResult<std::vector<PasswordForm*> >* r = |
39 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); | 40 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); |
40 std::vector<PasswordForm*> result_value = r->GetValue(); | 41 std::vector<PasswordForm*> result_value = r->GetValue(); |
41 | 42 |
42 if (result_value.size()) { | 43 if (result_value.size()) { |
43 // If we found some results then return them now. | 44 // If we found some results then return them now. |
44 NotifyConsumer(request, result_value); | 45 request->consumer->OnPasswordStoreRequestDone(request->handle, |
| 46 result_value); |
45 return; | 47 return; |
46 } else { | 48 } else { |
47 // Otherwise try finding IE7 logins. | 49 // Otherwise try finding IE7 logins. |
48 IE7PasswordInfo info; | 50 IE7PasswordInfo info; |
49 std::wstring url = ASCIIToWide(request->form.origin.spec()); | 51 std::wstring url = ASCIIToWide(request->form.origin.spec()); |
50 info.url_hash = ie7_password::GetUrlHash(url); | 52 info.url_hash = ie7_password::GetUrlHash(url); |
51 | 53 |
52 if (web_data_service_->IsRunning()) { | 54 if (web_data_service_->IsRunning()) { |
53 WebDataService::Handle web_data_handle = | 55 WebDataService::Handle web_data_handle = |
54 web_data_service_->GetIE7Login(info, this); | 56 web_data_service_->GetIE7Login(info, this); |
55 AddPendingWebDataServiceRequest(web_data_handle, request); | 57 pending_requests_.insert(PendingRequestMap::value_type( |
| 58 web_data_handle, request.release())); |
56 } | 59 } |
57 } | 60 } |
58 break; | 61 break; |
59 } | 62 } |
60 | 63 |
61 case PASSWORD_IE7_RESULT: { | 64 case PASSWORD_IE7_RESULT: { |
62 // This is a response from WebDataService::GetIE7Login. | 65 // This is a response from WebDataService::GetIE7Login. |
63 PasswordForm* ie7_form = GetIE7Result(result, request->form); | 66 PasswordForm* ie7_form = GetIE7Result(result, request->form); |
64 | 67 |
65 std::vector<PasswordForm*> forms; | 68 std::vector<PasswordForm*> forms; |
66 if (ie7_form) | 69 if (ie7_form) |
67 forms.push_back(ie7_form); | 70 forms.push_back(ie7_form); |
68 | 71 |
69 NotifyConsumer(request, forms); | 72 request->consumer->OnPasswordStoreRequestDone(request->handle, |
| 73 forms); |
70 break; | 74 break; |
71 } | 75 } |
72 } | 76 } |
73 } | 77 } |
74 | 78 |
75 PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result, | 79 PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result, |
76 const PasswordForm& form) { | 80 const PasswordForm& form) { |
77 const WDResult<IE7PasswordInfo>* r = | 81 const WDResult<IE7PasswordInfo>* r = |
78 static_cast<const WDResult<IE7PasswordInfo>*>(result); | 82 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
79 IE7PasswordInfo info = r->GetValue(); | 83 IE7PasswordInfo info = r->GetValue(); |
(...skipping 16 matching lines...) Expand all Loading... |
96 auto_fill->password_value = password; | 100 auto_fill->password_value = password; |
97 auto_fill->preferred = true; | 101 auto_fill->preferred = true; |
98 auto_fill->ssl_valid = form.origin.SchemeIsSecure(); | 102 auto_fill->ssl_valid = form.origin.SchemeIsSecure(); |
99 auto_fill->date_created = info.date_created; | 103 auto_fill->date_created = info.date_created; |
100 // Add this PasswordForm to the saved password table. | 104 // Add this PasswordForm to the saved password table. |
101 AddLogin(*auto_fill); | 105 AddLogin(*auto_fill); |
102 return auto_fill; | 106 return auto_fill; |
103 } | 107 } |
104 return NULL; | 108 return NULL; |
105 } | 109 } |
OLD | NEW |