diff options
16 files changed, 313 insertions, 141 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index d265fdc..abc97ef 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -10,6 +10,7 @@ #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" #include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/tab_restore_service.h" @@ -115,10 +116,10 @@ void BrowsingDataRemover::Remove(int remove_mask) { if (remove_mask & REMOVE_PASSWORDS) { UserMetrics::RecordAction(L"ClearBrowsingData_Passwords", profile_); - WebDataService* web_data_service = - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + PasswordStore* password_store = + profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); - web_data_service->RemoveLoginsCreatedBetween(delete_begin_, delete_end_); + password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_); } if (remove_mask & REMOVE_FORM_DATA) { 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); }; diff --git a/chrome/browser/views/options/exceptions_page_view.cc b/chrome/browser/views/options/exceptions_page_view.cc index 52de9eb..9486af4 100644 --- a/chrome/browser/views/options/exceptions_page_view.cc +++ b/chrome/browser/views/options/exceptions_page_view.cc @@ -41,31 +41,21 @@ int ExceptionsTableModel::CompareValues(int row1, int row2, void ExceptionsTableModel::GetAllExceptionsForProfile() { DCHECK(!pending_login_query_); - pending_login_query_ = web_data_service()->GetAllLogins(this); + pending_login_query_ = password_store()->GetAllLogins(this); } -void ExceptionsTableModel::OnWebDataServiceRequestDone( - WebDataService::Handle h, - const WDTypedResult* result) { - DCHECK_EQ(pending_login_query_, h); +void ExceptionsTableModel::OnPasswordStoreRequestDone( + int handle, const std::vector<webkit_glue::PasswordForm*>& result) { + DCHECK_EQ(pending_login_query_, handle); pending_login_query_ = NULL; - if (!result) - return; - - DCHECK(result->GetType() == PASSWORD_RESULT); - - // Get the result from the database into a useable form. - const WDResult<std::vector<PasswordForm*> >* r = - static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); - std::vector<PasswordForm*> rows = r->GetValue(); STLDeleteElements<PasswordRows>(&saved_signons_); std::wstring languages = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - for (size_t i = 0; i < rows.size(); ++i) { - if (rows[i]->blacklisted_by_user) { + for (size_t i = 0; i < result.size(); ++i) { + if (result[i]->blacklisted_by_user) { saved_signons_.push_back(new PasswordRow( - gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i])); + gfx::SortedDisplayURL(result[i]->origin, languages), result[i])); } } if (observer_) diff --git a/chrome/browser/views/options/exceptions_page_view.h b/chrome/browser/views/options/exceptions_page_view.h index 7a2906b..931abd1 100644 --- a/chrome/browser/views/options/exceptions_page_view.h +++ b/chrome/browser/views/options/exceptions_page_view.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_VIEWS_OPTIONS_EXCEPTIONS_PAGE_VIEW_H_ #define CHROME_BROWSER_VIEWS_OPTIONS_EXCEPTIONS_PAGE_VIEW_H_ +#include <vector> + #include "chrome/browser/views/options/options_page_view.h" #include "chrome/browser/views/options/passwords_page_view.h" #include "views/controls/table/table_view_observer.h" @@ -22,9 +24,9 @@ class ExceptionsTableModel : public PasswordsTableModel { virtual std::wstring GetText(int row, int column); virtual int CompareValues(int row1, int row2, int col_id); - // WebDataServiceConsumer implementation. - virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* result); + // PasswordStoreConsumer implementation. + virtual void OnPasswordStoreRequestDone( + int handle, const std::vector<webkit_glue::PasswordForm*>& result); // Request all logins data. void GetAllExceptionsForProfile(); }; diff --git a/chrome/browser/views/options/passwords_page_view.cc b/chrome/browser/views/options/passwords_page_view.cc index 2d82f27..4bd9648 100644 --- a/chrome/browser/views/options/passwords_page_view.cc +++ b/chrome/browser/views/options/passwords_page_view.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/string_util.h" +#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -53,7 +54,7 @@ PasswordsTableModel::PasswordsTableModel(Profile* profile) pending_login_query_(NULL), saved_signons_cleanup_(&saved_signons_), profile_(profile) { - DCHECK(profile && profile->GetWebDataService(Profile::EXPLICIT_ACCESS)); + DCHECK(profile && profile->GetPasswordStore(Profile::EXPLICIT_ACCESS)); } PasswordsTableModel::~PasswordsTableModel() { @@ -103,31 +104,21 @@ void PasswordsTableModel::SetObserver(TableModelObserver* observer) { void PasswordsTableModel::GetAllSavedLoginsForProfile() { DCHECK(!pending_login_query_); - pending_login_query_ = web_data_service()->GetAllAutofillableLogins(this); + pending_login_query_ = password_store()->GetAllAutofillableLogins(this); } -void PasswordsTableModel::OnWebDataServiceRequestDone( - WebDataService::Handle h, - const WDTypedResult* result) { - DCHECK_EQ(pending_login_query_, h); +void PasswordsTableModel::OnPasswordStoreRequestDone( + int handle, const std::vector<PasswordForm*>& result) { + DCHECK_EQ(pending_login_query_, handle); pending_login_query_ = NULL; - if (!result) - return; - - DCHECK(result->GetType() == PASSWORD_RESULT); - - // Get the result from the database into a useable form. - const WDResult<std::vector<PasswordForm*> >* r = - static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); - std::vector<PasswordForm*> rows = r->GetValue(); STLDeleteElements<PasswordRows>(&saved_signons_); - saved_signons_.resize(rows.size(), NULL); + saved_signons_.resize(result.size(), NULL); std::wstring languages = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - for (size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < result.size(); ++i) { saved_signons_[i] = new PasswordRow( - gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]); + gfx::SortedDisplayURL(result[i]->origin, languages), result[i]); } if (observer_) observer_->OnModelChanged(); @@ -145,7 +136,7 @@ void PasswordsTableModel::ForgetAndRemoveSignon(int row) { PasswordRows::iterator target_iter = saved_signons_.begin() + row; // Remove from DB, memory, and vector. PasswordRow* password_row = *target_iter; - web_data_service()->RemoveLogin(*(password_row->form.get())); + password_store()->RemoveLogin(*(password_row->form.get())); delete password_row; saved_signons_.erase(target_iter); if (observer_) @@ -159,7 +150,7 @@ void PasswordsTableModel::ForgetAndRemoveAllSignons() { while (iter != saved_signons_.end()) { // Remove from DB, memory, and vector. PasswordRow* row = *iter; - web_data_service()->RemoveLogin(*(row->form.get())); + password_store()->RemoveLogin(*(row->form.get())); delete row; iter = saved_signons_.erase(iter); } @@ -173,7 +164,7 @@ void PasswordsTableModel::ForgetAndRemoveAllSignons() { // PasswordsTableModel, private void PasswordsTableModel::CancelLoginsQuery() { if (pending_login_query_) { - web_data_service()->CancelRequest(pending_login_query_); + password_store()->CancelLoginsQuery(pending_login_query_); pending_login_query_ = NULL; } } diff --git a/chrome/browser/views/options/passwords_page_view.h b/chrome/browser/views/options/passwords_page_view.h index fb736ca..2766bce 100644 --- a/chrome/browser/views/options/passwords_page_view.h +++ b/chrome/browser/views/options/passwords_page_view.h @@ -12,7 +12,7 @@ #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "chrome/browser/views/options/options_page_view.h" -#include "chrome/browser/webdata/web_data_service.h" +#include "chrome/browser/password_manager/password_store.h" #include "views/controls/button/native_button.h" #include "views/controls/label.h" #include "views/controls/table/table_view.h" @@ -61,7 +61,7 @@ class MultiLabelButtons : public views::NativeButton { /////////////////////////////////////////////////////////////////////////////// // PasswordsTableModel class PasswordsTableModel : public TableModel, - public WebDataServiceConsumer { + public PasswordStoreConsumer { public: explicit PasswordsTableModel(Profile* profile); virtual ~PasswordsTableModel(); @@ -80,9 +80,10 @@ class PasswordsTableModel : public TableModel, // and clear the view. void ForgetAndRemoveAllSignons(); - // WebDataServiceConsumer implementation. - virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* result); + // PasswordStoreConsumer implementation. + virtual void OnPasswordStoreRequestDone( + int handle, const std::vector<webkit_glue::PasswordForm*>& result); + // Request saved logins data. void GetAllSavedLoginsForProfile(); @@ -110,9 +111,9 @@ class PasswordsTableModel : public TableModel, scoped_ptr<webkit_glue::PasswordForm> form; }; - // The web data service associated with the currently active profile. - WebDataService* web_data_service() { - return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + // The password store associated with the currently active profile. + PasswordStore* password_store() { + return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); } // The TableView observing this model. @@ -122,8 +123,8 @@ class PasswordsTableModel : public TableModel, // to this observer. PasswordsTableModelObserver* row_count_observer_; - // Handle to any pending WebDataService::GetLogins query. - WebDataService::Handle pending_login_query_; + // Handle to any pending PasswordStore login lookup query. + int pending_login_query_; // The set of passwords we're showing. typedef std::vector<PasswordRow*> PasswordRows; diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 05b997b..9e52ba8 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -306,6 +306,9 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { ////////////////////////////////////////////////////////////////////////////// // // Password manager + // NOTE: These methods are all deprecated; new clients should use + // PasswordStore. These are only still here because Windows is (temporarily) + // still using them for its PasswordStore implementation. // ////////////////////////////////////////////////////////////////////////////// |