| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/ref_counted.h" |
| 11 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 12 #include "base/scoped_vector.h" | 13 #include "base/scoped_vector.h" |
| 13 #include "base/string16.h" | 14 #include "base/string16.h" |
| 14 #include "chrome/browser/autofill/autofill_dialog.h" | 15 #include "chrome/browser/autofill/autofill_dialog.h" |
| 15 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
| 16 #include "chrome/browser/autofill/credit_card.h" | 17 #include "chrome/browser/autofill/credit_card.h" |
| 17 #include "chrome/browser/autofill/field_types.h" | 18 #include "chrome/browser/autofill/field_types.h" |
| 18 #include "chrome/browser/webdata/web_data_service.h" | 19 #include "chrome/browser/webdata/web_data_service.h" |
| 19 | 20 |
| 20 class AutoFillManager; | 21 class AutoFillManager; |
| 21 class FormStructure; | 22 class FormStructure; |
| 22 class Profile; | 23 class Profile; |
| 23 | 24 |
| 24 // Handles loading and saving AutoFill profile information to the web database. | 25 // Handles loading and saving AutoFill profile information to the web database. |
| 25 // This class also stores the profiles loaded from the database for use during | 26 // This class also stores the profiles loaded from the database for use during |
| 26 // AutoFill. | 27 // AutoFill. |
| 27 class PersonalDataManager : public WebDataServiceConsumer, | 28 class PersonalDataManager |
| 28 public AutoFillDialogObserver { | 29 : public WebDataServiceConsumer, |
| 30 public AutoFillDialogObserver, |
| 31 public base::RefCountedThreadSafe<PersonalDataManager> { |
| 29 public: | 32 public: |
| 30 // An interface the PersonalDataManager uses to notify its clients (observers) | 33 // An interface the PersonalDataManager uses to notify its clients (observers) |
| 31 // when it has finished loading personal data from the web database. Register | 34 // when it has finished loading personal data from the web database. Register |
| 32 // the observer via PersonalDataManager::SetObserver. | 35 // the observer via PersonalDataManager::SetObserver. |
| 33 class Observer { | 36 class Observer { |
| 34 public: | 37 public: |
| 35 // Notifies the observer that the PersonalDataManager has finished loading. | 38 // Notifies the observer that the PersonalDataManager has finished loading. |
| 36 virtual void OnPersonalDataLoaded() = 0; | 39 virtual void OnPersonalDataLoaded() = 0; |
| 37 | 40 |
| 38 protected: | 41 protected: |
| 39 virtual ~Observer() {} | 42 virtual ~Observer() {} |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 virtual ~PersonalDataManager(); | |
| 43 | |
| 44 // WebDataServiceConsumer implementation: | 45 // WebDataServiceConsumer implementation: |
| 45 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 46 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
| 46 const WDTypedResult* result); | 47 const WDTypedResult* result); |
| 47 | 48 |
| 48 // AutoFillDialogObserver implementation: | 49 // AutoFillDialogObserver implementation: |
| 49 virtual void OnAutoFillDialogApply(std::vector<AutoFillProfile>* profiles, | 50 virtual void OnAutoFillDialogApply(std::vector<AutoFillProfile>* profiles, |
| 50 std::vector<CreditCard>* credit_cards); | 51 std::vector<CreditCard>* credit_cards); |
| 51 | 52 |
| 52 // Sets the listener to be notified of PersonalDataManager events. | 53 // Sets the listener to be notified of PersonalDataManager events. |
| 53 virtual void SetObserver(PersonalDataManager::Observer* observer); | 54 virtual void SetObserver(PersonalDataManager::Observer* observer); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // the next call to Refresh. It could get deleted before we | 147 // the next call to Refresh. It could get deleted before we |
| 147 // manage, but this is safe (we just hold on to the ID a bit longer). | 148 // manage, but this is safe (we just hold on to the ID a bit longer). |
| 148 // | 149 // |
| 149 // Also see SetProfile for more details. | 150 // Also see SetProfile for more details. |
| 150 virtual void Refresh(); | 151 virtual void Refresh(); |
| 151 | 152 |
| 152 // Kicks off asynchronous loading of profiles and credit cards. | 153 // Kicks off asynchronous loading of profiles and credit cards. |
| 153 void Init(Profile* profile); | 154 void Init(Profile* profile); |
| 154 | 155 |
| 155 protected: | 156 protected: |
| 156 // Make sure that only Profile and the PersonalDataManager tests can create an | 157 // Make sure that only Profile and certain tests can create an instance of |
| 157 // instance of PersonalDataManager. | 158 // PersonalDataManager. |
| 159 friend class base::RefCountedThreadSafe<PersonalDataManager>; |
| 160 friend class PersonalDataManagerTest; |
| 158 friend class ProfileImpl; | 161 friend class ProfileImpl; |
| 159 friend class PersonalDataManagerTest; | 162 friend class ProfileSyncServiceAutofillTest; |
| 160 | 163 |
| 161 PersonalDataManager(); | 164 PersonalDataManager(); |
| 165 ~PersonalDataManager(); |
| 162 | 166 |
| 163 // Returns the profile of the tab contents. | 167 // Returns the profile of the tab contents. |
| 164 Profile* profile(); | 168 Profile* profile(); |
| 165 | 169 |
| 166 // Initializes the object if needed. This should be called at the beginning | 170 // Initializes the object if needed. This should be called at the beginning |
| 167 // of all the public functions to make sure that the object has been properly | 171 // of all the public functions to make sure that the object has been properly |
| 168 // initialized before use. | 172 // initialized before use. |
| 169 virtual void InitializeIfNeeded(); | 173 virtual void InitializeIfNeeded(); |
| 170 | 174 |
| 171 // This will create and reserve a new unique ID for a profile. | 175 // This will create and reserve a new unique ID for a profile. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 WebDataService::Handle pending_profiles_query_; | 255 WebDataService::Handle pending_profiles_query_; |
| 252 WebDataService::Handle pending_creditcards_query_; | 256 WebDataService::Handle pending_creditcards_query_; |
| 253 | 257 |
| 254 // The observers. This can be empty. | 258 // The observers. This can be empty. |
| 255 std::vector<PersonalDataManager::Observer*> observers_; | 259 std::vector<PersonalDataManager::Observer*> observers_; |
| 256 | 260 |
| 257 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 261 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
| 258 }; | 262 }; |
| 259 | 263 |
| 260 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 264 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| OLD | NEW |