Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/password_manager/password_store_default.cc

Issue 114057: Re-land the password store work from bug 8205, with changes that should fix b... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 void PasswordStoreDefault::AddLoginImpl(const PasswordForm& form) {
17 web_data_service_->AddLogin(form);
18 }
19
20 void PasswordStoreDefault::RemoveLoginImpl(const PasswordForm& form) {
21 web_data_service_->RemoveLogin(form);
22 }
23
24 void PasswordStoreDefault::UpdateLoginImpl(const PasswordForm& form) {
25 web_data_service_->UpdateLogin(form);
26 }
27
28 void PasswordStoreDefault::GetLoginsImpl(GetLoginsRequest* request) {
29 int web_data_handle = web_data_service_->GetLogins(request->form, this);
30 AddPendingWebDataServiceRequest(web_data_handle, request);
31 }
32
33 void PasswordStoreDefault::OnWebDataServiceRequestDone(
34 WebDataService::Handle h,
35 const WDTypedResult *result) {
36 // Look up this handle in our request map to get the original
37 // GetLoginsRequest.
38 PendingRequestMap::iterator it(pending_requests_.find(h));
39 DCHECK(it != pending_requests_.end());
40
41 GetLoginsRequest* request = it->second;
42 pending_requests_.erase(it);
43
44 DCHECK(result);
45 if (!result)
46 return;
47
48 const WDResult<std::vector<PasswordForm*> >* r =
49 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result);
50
51 NotifyConsumer(request, r->GetValue());
52
53 RemovePendingWebDataServiceRequest(h);
54 }
55
56 void PasswordStoreDefault::AddPendingWebDataServiceRequest(
57 WebDataService::Handle handle, GetLoginsRequest* request) {
58 pending_requests_.insert(PendingRequestMap::value_type(handle, request));
59
60 // WebDataService callbacks are non-retaining. Since there would be a race
61 // around cancelling the requests in the desctructor vs. getting a callback
62 // in this worker thread, just make sure that we stick around instead.
63 this->AddRef();
64 }
65
66 void PasswordStoreDefault::RemovePendingWebDataServiceRequest(
67 WebDataService::Handle handle) {
68 PendingRequestMap::iterator it(pending_requests_.find(handle));
69 DCHECK(it != pending_requests_.end());
70 pending_requests_.erase(it);
71
72 // Balance the AddRef in AddPendingWebDataServiceRequest.
73 this->Release();
74 }
75
76 PasswordStore::GetLoginsRequest*
77 PasswordStoreDefault::GetLoginsRequestForWebDataServiceRequest(
78 WebDataService::Handle handle) {
79 PendingRequestMap::iterator it(pending_requests_.find(handle));
80 if (it == pending_requests_.end())
81 return NULL;
82 return it->second;
83 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_default.h ('k') | chrome/browser/password_manager/password_store_gnome.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698