| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/browser/password_manager/password_store.h" | 13 #include "chrome/browser/password_manager/password_store.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
| 15 | 15 |
| 16 class Task; | 16 class Task; |
| 17 | 17 |
| 18 // Simple password store implementation that delegates everything to | 18 // Simple password store implementation that delegates everything to |
| 19 // the WebDatabase. | 19 // the WebDatabase. |
| 20 // TODO(stuartmorgan): This is a temprorary shim for Windows from the new | 20 // TODO(stuartmorgan): This is a temprorary shim for Windows from the new |
| 21 // PasswordStore interface to the old model of storing passwords in the | 21 // PasswordStore interface to the old model of storing passwords in the |
| 22 // WebDatabase. This should be replaced by a self-contained Windows | 22 // WebDatabase. This should be replaced by a self-contained Windows |
| 23 // implementation once PasswordStore is completed. | 23 // implementation once PasswordStore is completed. |
| 24 class PasswordStoreDefault : public PasswordStore, | 24 class PasswordStoreDefault : public PasswordStore, |
| 25 public WebDataServiceConsumer { | 25 public WebDataServiceConsumer { |
| 26 public: | 26 public: |
| 27 explicit PasswordStoreDefault(WebDataService* web_data_service); | 27 explicit PasswordStoreDefault(WebDataService* web_data_service); |
| 28 virtual ~PasswordStoreDefault() {} | 28 virtual ~PasswordStoreDefault(); |
| 29 |
| 30 // Overridden to bypass the threading logic in PasswordStore, since |
| 31 // WebDataService's API is not threadsafe. |
| 32 virtual void AddLogin(const PasswordForm& form); |
| 33 virtual void UpdateLogin(const PasswordForm& form); |
| 34 virtual void RemoveLogin(const PasswordForm& form); |
| 35 virtual int GetLogins(const PasswordForm& form, |
| 36 PasswordStoreConsumer* consumer); |
| 37 virtual void CancelLoginsQuery(int handle); |
| 29 | 38 |
| 30 protected: | 39 protected: |
| 31 // Implements PasswordStore interface. | 40 // Implements PasswordStore interface. |
| 32 void AddLoginImpl(const PasswordForm& form); | 41 void AddLoginImpl(const PasswordForm& form); |
| 33 void UpdateLoginImpl(const PasswordForm& form); | 42 void UpdateLoginImpl(const PasswordForm& form); |
| 34 void RemoveLoginImpl(const PasswordForm& form); | 43 void RemoveLoginImpl(const PasswordForm& form); |
| 35 void GetLoginsImpl(GetLoginsRequest* request); | 44 void GetLoginsImpl(GetLoginsRequest* request); |
| 36 | 45 |
| 37 // Called when a WebDataService method finishes. | 46 // Called when a WebDataService method finishes. |
| 38 // Overrides must call RemovePendingWebDataServiceRequest. | |
| 39 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 47 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
| 40 const WDTypedResult* result); | 48 const WDTypedResult* result); |
| 41 | 49 |
| 42 // Keeps track of a pending WebDataService request, and the original | |
| 43 // GetLogins request it is associated with. | |
| 44 // Increases the reference count of |this|, so must be balanced with a | |
| 45 // call to RemovePendingWebDataServiceRequest. | |
| 46 void AddPendingWebDataServiceRequest(WebDataService::Handle handle, | |
| 47 GetLoginsRequest* request); | |
| 48 // Removes a WebDataService request from the list of pending requests, | |
| 49 // and reduces the reference count of |this|. | |
| 50 void RemovePendingWebDataServiceRequest(WebDataService::Handle handle); | |
| 51 // Returns the GetLoginsRequest associated with |handle|. | |
| 52 GetLoginsRequest* GetLoginsRequestForWebDataServiceRequest( | |
| 53 WebDataService::Handle handle); | |
| 54 | |
| 55 scoped_refptr<WebDataService> web_data_service_; | 50 scoped_refptr<WebDataService> web_data_service_; |
| 56 | 51 |
| 57 private: | |
| 58 // Methods in this class call async WebDataService methods. This mapping | 52 // Methods in this class call async WebDataService methods. This mapping |
| 59 // remembers which WebDataService request corresponds to which PasswordStore | 53 // remembers which WebDataService request corresponds to which PasswordStore |
| 60 // request. | 54 // request. |
| 61 typedef std::map<WebDataService::Handle, GetLoginsRequest*> PendingRequestMap; | 55 typedef std::map<WebDataService::Handle, GetLoginsRequest*> PendingRequestMap; |
| 62 PendingRequestMap pending_requests_; | 56 PendingRequestMap pending_requests_; |
| 63 | 57 |
| 58 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault); | 59 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault); |
| 65 }; | 60 }; |
| 66 | 61 |
| 67 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT | 62 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT |
| OLD | NEW |