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/observer_list.h" |
11 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
13 #include "base/scoped_vector.h" | 14 #include "base/scoped_vector.h" |
14 #include "base/string16.h" | 15 #include "base/string16.h" |
15 #include "chrome/browser/autofill/autofill_dialog.h" | 16 #include "chrome/browser/autofill/autofill_dialog.h" |
16 #include "chrome/browser/autofill/autofill_profile.h" | 17 #include "chrome/browser/autofill/autofill_profile.h" |
17 #include "chrome/browser/autofill/credit_card.h" | 18 #include "chrome/browser/autofill/credit_card.h" |
18 #include "chrome/browser/autofill/field_types.h" | 19 #include "chrome/browser/autofill/field_types.h" |
19 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
20 | 21 |
21 class AutoFillManager; | 22 class AutoFillManager; |
22 class FormStructure; | 23 class FormStructure; |
23 class Profile; | 24 class Profile; |
24 | 25 |
25 // Handles loading and saving AutoFill profile information to the web database. | 26 // Handles loading and saving AutoFill profile information to the web database. |
26 // This class also stores the profiles loaded from the database for use during | 27 // This class also stores the profiles loaded from the database for use during |
27 // AutoFill. | 28 // AutoFill. |
28 class PersonalDataManager | 29 class PersonalDataManager |
29 : public WebDataServiceConsumer, | 30 : public WebDataServiceConsumer, |
30 public AutoFillDialogObserver, | 31 public AutoFillDialogObserver, |
31 public base::RefCountedThreadSafe<PersonalDataManager> { | 32 public base::RefCountedThreadSafe<PersonalDataManager> { |
32 public: | 33 public: |
33 // An interface the PersonalDataManager uses to notify its clients (observers) | 34 // An interface the PersonalDataManager uses to notify its clients (observers) |
34 // when it has finished loading personal data from the web database. Register | 35 // when it has finished loading personal data from the web database. Register |
35 // the observer via PersonalDataManager::SetObserver. | 36 // the observer via PersonalDataManager::SetObserver. |
36 class Observer { | 37 class Observer { |
37 public: | 38 public: |
38 // Notifies the observer that the PersonalDataManager has finished loading. | 39 // Notifies the observer that the PersonalDataManager has finished loading. |
| 40 // TODO: OnPersonalDataLoaded should be nuked in favor of only |
| 41 // OnPersonalDataChanged. |
39 virtual void OnPersonalDataLoaded() = 0; | 42 virtual void OnPersonalDataLoaded() = 0; |
40 | 43 |
| 44 // Notifies the observer that the PersonalDataManager changed in some way. |
| 45 virtual void OnPersonalDataChanged() {} |
| 46 |
41 protected: | 47 protected: |
42 virtual ~Observer() {} | 48 virtual ~Observer() {} |
43 }; | 49 }; |
44 | 50 |
45 // WebDataServiceConsumer implementation: | 51 // WebDataServiceConsumer implementation: |
46 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 52 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
47 const WDTypedResult* result); | 53 const WDTypedResult* result); |
48 | 54 |
49 // AutoFillDialogObserver implementation: | 55 // AutoFillDialogObserver implementation: |
50 virtual void OnAutoFillDialogApply(std::vector<AutoFillProfile>* profiles, | 56 virtual void OnAutoFillDialogApply(std::vector<AutoFillProfile>* profiles, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // no password exists. | 239 // no password exists. |
234 string16 password_hash_; | 240 string16 password_hash_; |
235 | 241 |
236 // When the manager makes a request from WebDataService, the database | 242 // When the manager makes a request from WebDataService, the database |
237 // is queried on another thread, we record the query handle until we | 243 // is queried on another thread, we record the query handle until we |
238 // get called back. We store handles for both profile and credit card queries | 244 // get called back. We store handles for both profile and credit card queries |
239 // so they can be loaded at the same time. | 245 // so they can be loaded at the same time. |
240 WebDataService::Handle pending_profiles_query_; | 246 WebDataService::Handle pending_profiles_query_; |
241 WebDataService::Handle pending_creditcards_query_; | 247 WebDataService::Handle pending_creditcards_query_; |
242 | 248 |
243 // The observers. This can be empty. | 249 // The observers. |
244 std::vector<PersonalDataManager::Observer*> observers_; | 250 ObserverList<Observer> observers_; |
245 | 251 |
246 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 252 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
247 }; | 253 }; |
248 | 254 |
249 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 255 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
OLD | NEW |