summaryrefslogtreecommitdiffstats
path: root/chrome/browser/password_manager
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/password_manager')
-rw-r--r--chrome/browser/password_manager/password_form_manager.cc8
-rw-r--r--chrome/browser/password_manager/password_form_manager.h4
-rw-r--r--chrome/browser/password_manager/password_store.cc54
-rw-r--r--chrome/browser/password_manager/password_store.h63
-rw-r--r--chrome/browser/password_manager/password_store_default.cc80
-rw-r--r--chrome/browser/password_manager/password_store_default.h32
-rw-r--r--chrome/browser/password_manager/password_store_mac.cc21
-rw-r--r--chrome/browser/password_manager/password_store_mac.h7
-rw-r--r--chrome/browser/password_manager/password_store_win.cc72
-rw-r--r--chrome/browser/password_manager/password_store_win.h17
10 files changed, 271 insertions, 87 deletions
diff --git a/chrome/browser/password_manager/password_form_manager.cc b/chrome/browser/password_manager/password_form_manager.cc
index 94d0c93..de6dff6 100644
--- a/chrome/browser/password_manager/password_form_manager.cc
+++ b/chrome/browser/password_manager/password_form_manager.cc
@@ -101,9 +101,9 @@ void PasswordFormManager::PermanentlyBlacklist() {
// autofill it again.
if (!best_matches_.empty()) {
PasswordFormMap::const_iterator iter;
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ PasswordStore* password_store =
+ profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
+ if (!password_store) {
NOTREACHED();
return;
}
@@ -115,7 +115,7 @@ void PasswordFormManager::PermanentlyBlacklist() {
// different origin URL) and just happened to match this form because of
// the scoring algorithm. See bug 1204493.
if (iter->second->origin == observed_form_.origin)
- web_data_service->RemoveLogin(*iter->second);
+ password_store->RemoveLogin(*iter->second);
}
}
diff --git a/chrome/browser/password_manager/password_form_manager.h b/chrome/browser/password_manager/password_form_manager.h
index 78229de..058d4d6 100644
--- a/chrome/browser/password_manager/password_form_manager.h
+++ b/chrome/browser/password_manager/password_form_manager.h
@@ -132,7 +132,7 @@ class PasswordFormManager : public PasswordStoreConsumer {
// PasswordManager owning this.
const PasswordManager* const password_manager_;
- // Handle to any pending WebDataService::GetLogins query.
+ // Handle to any pending PasswordStore::GetLogins query.
int pending_login_query_;
// Convenience pointer to entry in best_matches_ that is marked
@@ -143,7 +143,7 @@ class PasswordFormManager : public PasswordStoreConsumer {
typedef enum {
PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find
- // matching login information from DB.
+ // matching login information from password store.
MATCHING_PHASE, // We've made a GetLogins request, but
// haven't received or finished processing result.
POST_MATCHING_PHASE // We've queried the DB and processed matching
diff --git a/chrome/browser/password_manager/password_store.cc b/chrome/browser/password_manager/password_store.cc
index ba258bf..ac8e911 100644
--- a/chrome/browser/password_manager/password_store.cc
+++ b/chrome/browser/password_manager/password_store.cc
@@ -31,28 +31,47 @@ void PasswordStore::ScheduleTask(Task* task) {
}
void PasswordStore::AddLogin(const PasswordForm& form) {
- ScheduleTask(NewRunnableMethod(
- this, &PasswordStore::AddLoginImpl, form));
+ ScheduleTask(NewRunnableMethod(this, &PasswordStore::AddLoginImpl, form));
}
void PasswordStore::UpdateLogin(const PasswordForm& form) {
- ScheduleTask(NewRunnableMethod(
- this, &PasswordStore::UpdateLoginImpl, form));
+ ScheduleTask(NewRunnableMethod(this, &PasswordStore::UpdateLoginImpl, form));
}
void PasswordStore::RemoveLogin(const PasswordForm& form) {
- ScheduleTask(NewRunnableMethod(
- this, &PasswordStore::RemoveLoginImpl, form));
+ ScheduleTask(NewRunnableMethod(this, &PasswordStore::RemoveLoginImpl, form));
+}
+
+void PasswordStore::RemoveLoginsCreatedBetween(const base::Time& delete_begin,
+ const base::Time& delete_end) {
+ ScheduleTask(NewRunnableMethod(this,
+ &PasswordStore::RemoveLoginsCreatedBetweenImpl,
+ delete_begin, delete_end));
}
int PasswordStore::GetLogins(const PasswordForm& form,
PasswordStoreConsumer* consumer) {
- int handle = handle_++;
- GetLoginsRequest* request = new GetLoginsRequest(form, consumer, handle);
+ int handle = GetNewRequestHandle();
+ GetLoginsRequest* request = new GetLoginsRequest(consumer, handle);
+ ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetLoginsImpl, request,
+ form));
+ return handle;
+}
- pending_requests_.insert(handle);
+int PasswordStore::GetAllLogins(PasswordStoreConsumer* consumer) {
+ int handle = GetNewRequestHandle();
+ GetLoginsRequest* request = new GetLoginsRequest(consumer, handle);
+ ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetAllLoginsImpl,
+ request));
+ return handle;
+}
- ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetLoginsImpl, request));
+int PasswordStore::GetAllAutofillableLogins(PasswordStoreConsumer* consumer) {
+ int handle = GetNewRequestHandle();
+ GetLoginsRequest* request = new GetLoginsRequest(consumer, handle);
+ ScheduleTask(NewRunnableMethod(this,
+ &PasswordStore::GetAllAutofillableLoginsImpl,
+ request));
return handle;
}
@@ -78,16 +97,17 @@ void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer,
consumer->OnPasswordStoreRequestDone(handle, forms);
}
+int PasswordStore::GetNewRequestHandle() {
+ int handle = handle_++;
+ pending_requests_.insert(handle);
+ return handle;
+}
+
void PasswordStore::CancelLoginsQuery(int handle) {
pending_requests_.erase(handle);
}
PasswordStore::GetLoginsRequest::GetLoginsRequest(
- const PasswordForm& form,
- PasswordStoreConsumer* consumer,
- int handle)
- : form(form),
- consumer(consumer),
- handle(handle),
- message_loop(MessageLoop::current()) {
+ PasswordStoreConsumer* consumer, int handle)
+ : consumer(consumer), handle(handle), message_loop(MessageLoop::current()) {
}
diff --git a/chrome/browser/password_manager/password_store.h b/chrome/browser/password_manager/password_store.h
index d63f099..22f8fb3 100644
--- a/chrome/browser/password_manager/password_store.h
+++ b/chrome/browser/password_manager/password_store.h
@@ -11,6 +11,7 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/thread.h"
+#include "base/time.h"
#include "webkit/glue/password_form.h"
class Profile;
@@ -40,37 +41,53 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
// Adds the given PasswordForm to the secure password store asynchronously.
virtual void AddLogin(const webkit_glue::PasswordForm& form);
+
// Updates the matching PasswordForm in the secure password store (async).
virtual void UpdateLogin(const webkit_glue::PasswordForm& form);
+
// Removes the matching PasswordForm from the secure password store (async).
virtual void RemoveLogin(const webkit_glue::PasswordForm& form);
+
+ // Removes all logins created in the given date range.
+ virtual void RemoveLoginsCreatedBetween(const base::Time& delete_begin,
+ const base::Time& delete_end);
+
// Searches for a matching PasswordForm and returns a handle so the async
// request can be tracked. Implement the PasswordStoreConsumer interface to
// be notified on completion.
virtual int GetLogins(const webkit_glue::PasswordForm& form,
PasswordStoreConsumer* consumer);
- // Cancels a previous GetLogins query (async)
+ // Gets the complete list of PasswordForms and returns a handle so the async
+ // request can be tracked. Implement the PasswordStoreConsumer interface to
+ // be notified on completion.
+ virtual int GetAllLogins(PasswordStoreConsumer* consumer);
+
+ // Gets the complete list of PasswordForms that are not blacklist entries--and
+ // are thus auto-fillable--and returns a handle so the async request can be
+ // tracked. Implement the PasswordStoreConsumer interface to be notified
+ // on completion.
+ virtual int GetAllAutofillableLogins(PasswordStoreConsumer* consumer);
+
+ // Cancels a previous Get*Logins query (async)
virtual void CancelLoginsQuery(int handle);
protected:
- // Simple container class that represents a GetLogins request.
- // Created in GetLogins and passed to GetLoginsImpl.
- struct GetLoginsRequest {
- GetLoginsRequest(const webkit_glue::PasswordForm& f,
- PasswordStoreConsumer* c,
+ // Simple container class that represents a login lookup request.
+ class GetLoginsRequest {
+ public:
+ GetLoginsRequest(PasswordStoreConsumer* c,
int handle);
- // The query form that was originally passed to GetLogins
- webkit_glue::PasswordForm form;
- // The consumer to notify when this GetLogins request is complete
+ // The consumer to notify when this request is complete.
PasswordStoreConsumer* consumer;
// A unique handle for the request
int handle;
- // The message loop that the GetLogins request was made from. We send the
- // result back to the consumer in this same message loop.
+ // The message loop that the request was made from. We send the result
+ // back to the consumer in this same message loop.
MessageLoop* message_loop;
+ private:
DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest);
};
@@ -87,16 +104,19 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
// Should find all PasswordForms with the same signon_realm. The results
// will then be scored by the PasswordFormManager. Once they are found
// (or not), the consumer should be notified.
- virtual void GetLoginsImpl(GetLoginsRequest* request) = 0;
-
- // Notifies the consumer that GetLoginsImpl() is complete.
+ virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
+ const base::Time& delete_end) = 0;
+ virtual void GetLoginsImpl(GetLoginsRequest* request,
+ const webkit_glue::PasswordForm& form) = 0;
+ // Finds all PasswordForms, and notifies the consumer.
+ virtual void GetAllLoginsImpl(GetLoginsRequest* request) = 0;
+ // Finds all non-blacklist PasswordForms, and notifies the consumer.
+ virtual void GetAllAutofillableLoginsImpl(GetLoginsRequest* request) = 0;
+
+ // Notifies the consumer that a Get*Logins() request is complete.
void NotifyConsumer(GetLoginsRequest* request,
const std::vector<webkit_glue::PasswordForm*> forms);
- // Next handle to return from GetLogins() to allow callers to track
- // their request.
- int handle_;
-
// Thread that the synchronous methods are run in.
scoped_ptr<base::Thread> thread_;
@@ -108,6 +128,13 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
void NotifyConsumerImpl(PasswordStoreConsumer* consumer, int handle,
const std::vector<webkit_glue::PasswordForm*> forms);
+ // Returns a new request handle tracked in pending_requests_.
+ int GetNewRequestHandle();
+
+ // Next handle to return from Get*Logins() to allow callers to track
+ // their request.
+ int handle_;
+
// List of pending request handles. Handles are removed from the set when
// they finish or are canceled.
std::set<int> pending_requests_;
diff --git a/chrome/browser/password_manager/password_store_default.cc b/chrome/browser/password_manager/password_store_default.cc
index 050fe46..4fdd1afc 100644
--- a/chrome/browser/password_manager/password_store_default.cc
+++ b/chrome/browser/password_manager/password_store_default.cc
@@ -12,7 +12,7 @@
using webkit_glue::PasswordForm;
PasswordStoreDefault::PasswordStoreDefault(WebDataService* web_data_service)
- : web_data_service_(web_data_service) {
+ : web_data_service_(web_data_service), handle_(0) {
}
PasswordStoreDefault::~PasswordStoreDefault() {
@@ -22,7 +22,7 @@ PasswordStoreDefault::~PasswordStoreDefault() {
}
}
-// Override all the public methods to do avoid passthroughs to the Impl
+// Override all the public methods to avoid passthroughs to the Impl
// versions. Since we are calling through to WebDataService, which is
// asynchronous, we'll still behave as the caller expects.
void PasswordStoreDefault::AddLogin(const PasswordForm& form) {
@@ -37,15 +37,29 @@ void PasswordStoreDefault::RemoveLogin(const PasswordForm& form) {
web_data_service_->RemoveLogin(form);
}
+void PasswordStoreDefault::RemoveLoginsCreatedBetween(
+ const base::Time& delete_begin, const base::Time& delete_end) {
+ web_data_service_->RemoveLoginsCreatedBetween(delete_begin, delete_end);
+}
+
int PasswordStoreDefault::GetLogins(const PasswordForm& form,
PasswordStoreConsumer* consumer) {
- int handle = handle_++;
- GetLoginsRequest* request = new GetLoginsRequest(form, consumer, handle);
+ WebDataService::Handle web_data_handle = web_data_service_->GetLogins(form,
+ this);
+ return CreateNewRequestForQuery(web_data_handle, consumer);
+}
- int web_data_handle = web_data_service_->GetLogins(form, this);
- pending_requests_.insert(PendingRequestMap::value_type(web_data_handle,
- request));
- return handle;
+int PasswordStoreDefault::GetAllLogins(PasswordStoreConsumer* consumer) {
+ WebDataService::Handle web_data_handle =
+ web_data_service_->GetAllLogins(this);
+ return CreateNewRequestForQuery(web_data_handle, consumer);
+}
+
+int PasswordStoreDefault::GetAllAutofillableLogins(
+ PasswordStoreConsumer* consumer) {
+ WebDataService::Handle web_data_handle =
+ web_data_service_->GetAllAutofillableLogins(this);
+ return CreateNewRequestForQuery(web_data_handle, consumer);
}
void PasswordStoreDefault::CancelLoginsQuery(int handle) {
@@ -69,27 +83,37 @@ void PasswordStoreDefault::RemoveLoginImpl(const PasswordForm& form) {
NOTREACHED();
}
+void PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(
+ const base::Time& delete_begin, const base::Time& delete_end) {
+ NOTREACHED();
+}
+
void PasswordStoreDefault::UpdateLoginImpl(const PasswordForm& form) {
NOTREACHED();
}
-void PasswordStoreDefault::GetLoginsImpl(GetLoginsRequest* request) {
+void PasswordStoreDefault::GetLoginsImpl(
+ GetLoginsRequest* request, const webkit_glue::PasswordForm& form) {
+ NOTREACHED();
+}
+
+void PasswordStoreDefault::GetAllLoginsImpl(GetLoginsRequest* request) {
+ NOTREACHED();
+}
+
+void PasswordStoreDefault::GetAllAutofillableLoginsImpl(
+ GetLoginsRequest* request) {
NOTREACHED();
}
void PasswordStoreDefault::OnWebDataServiceRequestDone(
WebDataService::Handle h,
const WDTypedResult *result) {
- // Look up this handle in our request map to get the original
- // GetLoginsRequest.
- PendingRequestMap::iterator it(pending_requests_.find(h));
+ scoped_ptr<GetLoginsRequest> request(TakeRequestWithHandle(h));
// If the request was cancelled, we are done.
- if (it == pending_requests_.end())
+ if (!request.get())
return;
- scoped_ptr<GetLoginsRequest> request(it->second);
- pending_requests_.erase(it);
-
DCHECK(result);
if (!result)
return;
@@ -100,3 +124,27 @@ void PasswordStoreDefault::OnWebDataServiceRequestDone(
request->consumer->OnPasswordStoreRequestDone(request->handle,
r->GetValue());
}
+
+PasswordStoreDefault::GetLoginsRequest*
+ PasswordStoreDefault::TakeRequestWithHandle(WebDataService::Handle handle) {
+ PendingRequestMap::iterator it(pending_requests_.find(handle));
+ if (it == pending_requests_.end())
+ return NULL;
+
+ GetLoginsRequest* request = it->second;
+ pending_requests_.erase(it);
+ return request;
+}
+
+int PasswordStoreDefault::CreateNewRequestForQuery(
+ WebDataService::Handle web_data_handle, PasswordStoreConsumer* consumer) {
+ int api_handle = handle_++;
+ GetLoginsRequest* request = new GetLoginsRequest(consumer, api_handle);
+ TrackRequest(web_data_handle, request);
+ return api_handle;
+}
+
+void PasswordStoreDefault::TrackRequest(WebDataService::Handle handle,
+ GetLoginsRequest* request) {
+ pending_requests_.insert(PendingRequestMap::value_type(handle, request));
+}
diff --git a/chrome/browser/password_manager/password_store_default.h b/chrome/browser/password_manager/password_store_default.h
index 2434900..aba016b 100644
--- a/chrome/browser/password_manager/password_store_default.h
+++ b/chrome/browser/password_manager/password_store_default.h
@@ -32,8 +32,12 @@ class PasswordStoreDefault : public PasswordStore,
virtual void AddLogin(const webkit_glue::PasswordForm& form);
virtual void UpdateLogin(const webkit_glue::PasswordForm& form);
virtual void RemoveLogin(const webkit_glue::PasswordForm& form);
+ virtual void RemoveLoginsCreatedBetween(const base::Time& delete_begin,
+ const base::Time& delete_end);
virtual int GetLogins(const webkit_glue::PasswordForm& form,
PasswordStoreConsumer* consumer);
+ virtual int GetAllLogins(PasswordStoreConsumer* consumer);
+ virtual int GetAllAutofillableLogins(PasswordStoreConsumer* consumer);
virtual void CancelLoginsQuery(int handle);
protected:
@@ -41,21 +45,45 @@ class PasswordStoreDefault : public PasswordStore,
void AddLoginImpl(const webkit_glue::PasswordForm& form);
void UpdateLoginImpl(const webkit_glue::PasswordForm& form);
void RemoveLoginImpl(const webkit_glue::PasswordForm& form);
- void GetLoginsImpl(GetLoginsRequest* request);
+ void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
+ const base::Time& delete_end);
+ void GetLoginsImpl(GetLoginsRequest* request,
+ const webkit_glue::PasswordForm& form);
+ void GetAllLoginsImpl(GetLoginsRequest* request);
+ void GetAllAutofillableLoginsImpl(GetLoginsRequest* request);
// Called when a WebDataService method finishes.
virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result);
+ // Finds the GetLoginsRequest associated with the in-flight WebDataService
+ // request identified by |handle|, removes it from the tracking list, and
+ // returns it. Ownership of the GetLoginsRequest passes to the caller.
+ // Returns NULL if the request has been cancelled.
+ GetLoginsRequest* TakeRequestWithHandle(WebDataService::Handle handle);
+
+ // Takes ownership of |request| and tracks it under |handle|.
+ void TrackRequest(WebDataService::Handle handle, GetLoginsRequest* request);
+
scoped_refptr<WebDataService> web_data_service_;
+ private:
+ // Creates a new request, stored in pending_requests_, for the given
+ // WebDataService query, and returns the request handle that should be used
+ // for it in the client API.
+ int CreateNewRequestForQuery(WebDataService::Handle web_data_handle,
+ PasswordStoreConsumer* consumer);
+
+ // Next handle to return from our Get*Logins() overrides to allow callers to
+ // track their request.
+ int handle_;
+
// Methods in this class call async WebDataService methods. This mapping
// remembers which WebDataService request corresponds to which PasswordStore
// request.
typedef std::map<WebDataService::Handle, GetLoginsRequest*> PendingRequestMap;
PendingRequestMap pending_requests_;
- private:
DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault);
};
diff --git a/chrome/browser/password_manager/password_store_mac.cc b/chrome/browser/password_manager/password_store_mac.cc
index a451bed..6841959 100644
--- a/chrome/browser/password_manager/password_store_mac.cc
+++ b/chrome/browser/password_manager/password_store_mac.cc
@@ -12,7 +12,6 @@
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
-#include "base/time.h"
#include "chrome/browser/keychain_mac.h"
#include "chrome/browser/password_manager/login_database_mac.h"
@@ -657,13 +656,19 @@ void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) {
NOTIMPLEMENTED();
}
-void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request) {
+void PasswordStoreMac::RemoveLoginsCreatedBetweenImpl(
+ const base::Time& delete_begin, const base::Time& delete_end) {
+ NOTIMPLEMENTED();
+}
+
+void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request,
+ const webkit_glue::PasswordForm& form) {
MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get());
std::vector<PasswordForm*> keychain_forms =
- keychainAdapter.PasswordsMatchingForm(request->form);
+ keychainAdapter.PasswordsMatchingForm(form);
std::vector<PasswordForm*> database_forms;
- login_metadata_db_->GetLogins(request->form, &database_forms);
+ login_metadata_db_->GetLogins(form, &database_forms);
std::vector<PasswordForm*> merged_forms;
internal_keychain_helpers::MergePasswordForms(&keychain_forms,
@@ -681,3 +686,11 @@ void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request) {
NotifyConsumer(request, merged_forms);
}
+
+void PasswordStoreMac::GetAllLoginsImpl(GetLoginsRequest* request) {
+ NOTIMPLEMENTED();
+}
+
+void PasswordStoreMac::GetAllAutofillableLoginsImpl(GetLoginsRequest* request) {
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/browser/password_manager/password_store_mac.h b/chrome/browser/password_manager/password_store_mac.h
index 43b4d3e..c407e4e 100644
--- a/chrome/browser/password_manager/password_store_mac.h
+++ b/chrome/browser/password_manager/password_store_mac.h
@@ -22,7 +22,12 @@ class PasswordStoreMac : public PasswordStore {
void AddLoginImpl(const webkit_glue::PasswordForm& form);
void UpdateLoginImpl(const webkit_glue::PasswordForm& form);
void RemoveLoginImpl(const webkit_glue::PasswordForm& form);
- void GetLoginsImpl(GetLoginsRequest* request);
+ void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
+ const base::Time& delete_end);
+ void GetLoginsImpl(GetLoginsRequest* request,
+ const webkit_glue::PasswordForm& form);
+ void GetAllLoginsImpl(GetLoginsRequest* request);
+ void GetAllAutofillableLoginsImpl(GetLoginsRequest* request);
scoped_ptr<MacKeychain> keychain_;
scoped_ptr<LoginDatabaseMac> login_metadata_db_;
diff --git a/chrome/browser/password_manager/password_store_win.cc b/chrome/browser/password_manager/password_store_win.cc
index c8bd867..1e5a6c6 100644
--- a/chrome/browser/password_manager/password_store_win.cc
+++ b/chrome/browser/password_manager/password_store_win.cc
@@ -18,45 +18,56 @@ PasswordStoreWin::PasswordStoreWin(WebDataService* web_data_service)
: PasswordStoreDefault(web_data_service) {
}
+void PasswordStoreWin::CancelLoginsQuery(int handle) {
+ PasswordStoreDefault::CancelLoginsQuery(handle);
+ DeleteFormForRequest(handle);
+}
+
+int PasswordStoreWin::GetLogins(const webkit_glue::PasswordForm& form,
+ PasswordStoreConsumer* consumer) {
+ int request_handle = PasswordStoreDefault::GetLogins(form, consumer);
+ pending_request_forms_.insert(PendingRequestFormMap::value_type(
+ request_handle, form));
+ return request_handle;
+}
+
void PasswordStoreWin::OnWebDataServiceRequestDone(
WebDataService::Handle h, const WDTypedResult *result) {
- // Look up this handle in our request map to get the original
- // GetLoginsRequest.
- PendingRequestMap::iterator it(pending_requests_.find(h));
+ scoped_ptr<GetLoginsRequest> request(TakeRequestWithHandle(h));
// If the request was cancelled, we are done.
- if (it == pending_requests_.end())
+ if (!request.get())
return;
- scoped_ptr<GetLoginsRequest> request(it->second);
- pending_requests_.erase(it);
-
DCHECK(result);
if (!result)
return;
switch (result->GetType()) {
case PASSWORD_RESULT: {
- // This is a response from WebDataService::GetLogins.
+ // This is a response from a WebDataService::Get*Logins method.
const WDResult<std::vector<PasswordForm*> >* r =
static_cast<const WDResult<std::vector<PasswordForm*> >*>(result);
std::vector<PasswordForm*> result_value = r->GetValue();
if (result_value.size()) {
// If we found some results then return them now.
- request->consumer->OnPasswordStoreRequestDone(request->handle,
- result_value);
+ CompleteRequest(request.get(), result_value);
return;
} else {
- // Otherwise try finding IE7 logins.
- IE7PasswordInfo info;
- std::wstring url = ASCIIToWide(request->form.origin.spec());
- info.url_hash = ie7_password::GetUrlHash(url);
-
- if (web_data_service_->IsRunning()) {
- WebDataService::Handle web_data_handle =
- web_data_service_->GetIE7Login(info, this);
- pending_requests_.insert(PendingRequestMap::value_type(
- web_data_handle, request.release()));
+ // Otherwise try finding IE7 logins if we were looking for a specific
+ // page.
+ PendingRequestFormMap::iterator it(pending_request_forms_.find(
+ request->handle));
+ if (it != pending_request_forms_.end()) {
+ IE7PasswordInfo info;
+ std::wstring url = ASCIIToWide(it->second.origin.spec());
+ info.url_hash = ie7_password::GetUrlHash(url);
+
+ if (web_data_service_->IsRunning()) {
+ WebDataService::Handle web_data_handle =
+ web_data_service_->GetIE7Login(info, this);
+ TrackRequest(web_data_handle, request.release());
+ }
}
}
break;
@@ -64,19 +75,34 @@ void PasswordStoreWin::OnWebDataServiceRequestDone(
case PASSWORD_IE7_RESULT: {
// This is a response from WebDataService::GetIE7Login.
- PasswordForm* ie7_form = GetIE7Result(result, request->form);
+ PendingRequestFormMap::iterator it(pending_request_forms_.find(
+ request->handle));
+ PasswordForm* ie7_form = GetIE7Result(result, it->second);
std::vector<PasswordForm*> forms;
if (ie7_form)
forms.push_back(ie7_form);
- request->consumer->OnPasswordStoreRequestDone(request->handle,
- forms);
+ CompleteRequest(request.get(), forms);
break;
}
}
}
+void PasswordStoreWin::DeleteFormForRequest(int handle) {
+ PendingRequestFormMap::iterator it(pending_request_forms_.find(handle));
+ if (it != pending_request_forms_.end()) {
+ pending_request_forms_.erase(it);
+ }
+}
+
+void PasswordStoreWin::CompleteRequest(
+ GetLoginsRequest* request,
+ const std::vector<webkit_glue::PasswordForm*>& forms) {
+ DeleteFormForRequest(request->handle);
+ request->consumer->OnPasswordStoreRequestDone(request->handle, forms);
+}
+
PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result,
const PasswordForm& form) {
const WDResult<IE7PasswordInfo>* r =
diff --git a/chrome/browser/password_manager/password_store_win.h b/chrome/browser/password_manager/password_store_win.h
index ad59d8a..0fbc4fa 100644
--- a/chrome/browser/password_manager/password_store_win.h
+++ b/chrome/browser/password_manager/password_store_win.h
@@ -23,17 +23,34 @@ class PasswordStoreWin : public PasswordStoreDefault {
explicit PasswordStoreWin(WebDataService* web_data_service);
virtual ~PasswordStoreWin() {}
+ // Overridden so that we can save the form for later use.
+ virtual int GetLogins(const webkit_glue::PasswordForm& form,
+ PasswordStoreConsumer* consumer);
+ virtual void CancelLoginsQuery(int handle);
+
private:
// See PasswordStoreDefault.
void OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result);
+ // Removes the form for |handle| from pending_request_forms_ (if any).
+ void DeleteFormForRequest(int handle);
+
+ // Cleans up internal state related to |request|, and sends its results to
+ // the request's consumer.
+ void CompleteRequest(GetLoginsRequest* request,
+ const std::vector<webkit_glue::PasswordForm*>& forms);
+
// Gets logins from IE7 if no others are found. Also copies them into
// Chrome's WebDatabase so we don't need to look next time.
webkit_glue::PasswordForm* GetIE7Result(
const WDTypedResult* result,
const webkit_glue::PasswordForm& form);
+ // Holds forms associated with in-flight GetLogin queries.
+ typedef std::map<int, webkit_glue::PasswordForm> PendingRequestFormMap;
+ PendingRequestFormMap pending_request_forms_;
+
DISALLOW_COPY_AND_ASSIGN(PasswordStoreWin);
};