| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/password_manager/password_store_default.h" | |
| 6 #include "chrome/browser/webdata/web_data_service.h" | |
| 7 #include "chrome/common/chrome_constants.h" | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/task.h" | |
| 11 | |
| 12 PasswordStoreDefault::PasswordStoreDefault(WebDataService* web_data_service) | |
| 13 : web_data_service_(web_data_service) { | |
| 14 } | |
| 15 | |
| 16 PasswordStoreDefault::~PasswordStoreDefault() { | |
| 17 for (PendingRequestMap::const_iterator it = pending_requests_.begin(); | |
| 18 it != pending_requests_.end(); ++it) { | |
| 19 scoped_ptr<GetLoginsRequest> request(it->second); | |
| 20 web_data_service_->CancelRequest(it->first); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 void PasswordStoreDefault::AddLoginImpl(const PasswordForm& form) { | |
| 25 web_data_service_->AddLogin(form); | |
| 26 } | |
| 27 | |
| 28 void PasswordStoreDefault::RemoveLoginImpl(const PasswordForm& form) { | |
| 29 web_data_service_->RemoveLogin(form); | |
| 30 } | |
| 31 | |
| 32 void PasswordStoreDefault::UpdateLoginImpl(const PasswordForm& form) { | |
| 33 web_data_service_->UpdateLogin(form); | |
| 34 } | |
| 35 | |
| 36 void PasswordStoreDefault::GetLoginsImpl(GetLoginsRequest* request) { | |
| 37 int web_data_handle = web_data_service_->GetLogins(request->form, this); | |
| 38 pending_requests_.insert(PendingRequestMap::value_type( | |
| 39 web_data_handle, request)); | |
| 40 } | |
| 41 | |
| 42 void PasswordStoreDefault::OnWebDataServiceRequestDone( | |
| 43 WebDataService::Handle h, | |
| 44 const WDTypedResult *result) { | |
| 45 // Look up this handle in our request map to get the original | |
| 46 // GetLoginsRequest. | |
| 47 PendingRequestMap::iterator it(pending_requests_.find(h)); | |
| 48 DCHECK(it != pending_requests_.end()); | |
| 49 | |
| 50 GetLoginsRequest* request = it->second; | |
| 51 pending_requests_.erase(it); | |
| 52 | |
| 53 DCHECK(result); | |
| 54 if (!result) | |
| 55 return; | |
| 56 | |
| 57 const WDResult<std::vector<PasswordForm*> >* r = | |
| 58 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); | |
| 59 | |
| 60 NotifyConsumer(request, r->GetValue()); | |
| 61 } | |
| OLD | NEW |