OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/scoped_vector.h" | 15 #include "base/scoped_vector.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "chrome/browser/autofill/autofill_dialog.h" | 17 #include "chrome/browser/autofill/autofill_dialog.h" |
18 #include "chrome/browser/autofill/autofill_profile.h" | 18 #include "chrome/browser/autofill/autofill_profile.h" |
19 #include "chrome/browser/autofill/credit_card.h" | 19 #include "chrome/browser/autofill/credit_card.h" |
20 #include "chrome/browser/autofill/field_types.h" | 20 #include "chrome/browser/autofill/field_types.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_observer.h" |
21 #include "chrome/browser/webdata/web_data_service.h" | 22 #include "chrome/browser/webdata/web_data_service.h" |
22 | 23 |
23 class AutofillManager; | 24 class AutofillManager; |
24 class AutofillMetrics; | 25 class AutofillMetrics; |
25 class FormStructure; | 26 class FormStructure; |
26 class Profile; | 27 class Profile; |
27 | 28 |
28 // Handles loading and saving AutoFill profile information to the web database. | 29 // Handles loading and saving AutoFill profile information to the web database. |
29 // This class also stores the profiles loaded from the database for use during | 30 // This class also stores the profiles loaded from the database for use during |
30 // AutoFill. | 31 // AutoFill. |
31 class PersonalDataManager | 32 class PersonalDataManager |
32 : public WebDataServiceConsumer, | 33 : public WebDataServiceConsumer, |
33 public AutoFillDialogObserver, | 34 public AutoFillDialogObserver, |
| 35 public ProfileSyncServiceObserver, |
34 public base::RefCountedThreadSafe<PersonalDataManager> { | 36 public base::RefCountedThreadSafe<PersonalDataManager> { |
35 public: | 37 public: |
36 // An interface the PersonalDataManager uses to notify its clients (observers) | 38 // An interface the PersonalDataManager uses to notify its clients (observers) |
37 // when it has finished loading personal data from the web database. Register | 39 // when it has finished loading personal data from the web database. Register |
38 // the observer via PersonalDataManager::SetObserver. | 40 // the observer via PersonalDataManager::SetObserver. |
39 class Observer { | 41 class Observer { |
40 public: | 42 public: |
41 // Notifies the observer that the PersonalDataManager has finished loading. | 43 // Notifies the observer that the PersonalDataManager has finished loading. |
42 // TODO: OnPersonalDataLoaded should be nuked in favor of only | 44 // TODO: OnPersonalDataLoaded should be nuked in favor of only |
43 // OnPersonalDataChanged. | 45 // OnPersonalDataChanged. |
(...skipping 13 matching lines...) Expand all Loading... |
57 // AutoFillDialogObserver implementation: | 59 // AutoFillDialogObserver implementation: |
58 virtual void OnAutoFillDialogApply(std::vector<AutofillProfile>* profiles, | 60 virtual void OnAutoFillDialogApply(std::vector<AutofillProfile>* profiles, |
59 std::vector<CreditCard>* credit_cards); | 61 std::vector<CreditCard>* credit_cards); |
60 | 62 |
61 // Sets the listener to be notified of PersonalDataManager events. | 63 // Sets the listener to be notified of PersonalDataManager events. |
62 virtual void SetObserver(PersonalDataManager::Observer* observer); | 64 virtual void SetObserver(PersonalDataManager::Observer* observer); |
63 | 65 |
64 // Removes |observer| as the observer of this PersonalDataManager. | 66 // Removes |observer| as the observer of this PersonalDataManager. |
65 virtual void RemoveObserver(PersonalDataManager::Observer* observer); | 67 virtual void RemoveObserver(PersonalDataManager::Observer* observer); |
66 | 68 |
| 69 // ProfileSyncServiceObserver: |
| 70 virtual void OnStateChanged(); |
| 71 |
67 // TODO(isherman): Update this comment | 72 // TODO(isherman): Update this comment |
68 // If AutoFill is able to determine the field types of a significant number of | 73 // If AutoFill is able to determine the field types of a significant number of |
69 // field types that contain information in the FormStructures a profile will | 74 // field types that contain information in the FormStructures a profile will |
70 // be created with all of the information from recognized fields. Returns | 75 // be created with all of the information from recognized fields. Returns |
71 // whether a profile was created. | 76 // whether a profile was created. |
72 bool ImportFormData(const std::vector<const FormStructure*>& form_structures, | 77 bool ImportFormData(const std::vector<const FormStructure*>& form_structures, |
73 const CreditCard** credit_card); | 78 const CreditCard** credit_card); |
74 | 79 |
75 // Saves a credit card value detected in |ImportedFormData|. | 80 // Saves a credit card value detected in |ImportedFormData|. |
76 void SaveImportedCreditCard(const CreditCard& imported_credit_card); | 81 void SaveImportedCreditCard(const CreditCard& imported_credit_card); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // profiles in the WebDatabase directly, as is the case if the browser sync | 148 // profiles in the WebDatabase directly, as is the case if the browser sync |
144 // engine processed a change from the cloud, we will learn of these as a | 149 // engine processed a change from the cloud, we will learn of these as a |
145 // result of this call. | 150 // result of this call. |
146 // | 151 // |
147 // Also see SetProfile for more details. | 152 // Also see SetProfile for more details. |
148 virtual void Refresh(); | 153 virtual void Refresh(); |
149 | 154 |
150 // Kicks off asynchronous loading of profiles and credit cards. | 155 // Kicks off asynchronous loading of profiles and credit cards. |
151 void Init(Profile* profile); | 156 void Init(Profile* profile); |
152 | 157 |
| 158 // Checks suitability of |profile| for adding to the user's set of profiles. |
| 159 static bool IsValidLearnableProfile(const AutofillProfile& profile); |
| 160 |
| 161 // Merges |profile| into one of the |existing_profiles| if possible; otherwise |
| 162 // appends |profile| to the end of that list. Fills |merged_profiles| with the |
| 163 // result. |
| 164 static bool MergeProfile( |
| 165 const AutofillProfile& profile, |
| 166 const std::vector<AutofillProfile*>& existing_profiles, |
| 167 std::vector<AutofillProfile>* merged_profiles); |
| 168 |
153 protected: | 169 protected: |
154 // Make sure that only Profile and certain tests can create an instance of | 170 // Make sure that only Profile and certain tests can create an instance of |
155 // PersonalDataManager. | 171 // PersonalDataManager. |
156 friend class base::RefCountedThreadSafe<PersonalDataManager>; | 172 friend class base::RefCountedThreadSafe<PersonalDataManager>; |
157 friend class AutoFillMergeTest; | 173 friend class AutoFillMergeTest; |
158 friend class PersonalDataManagerTest; | 174 friend class PersonalDataManagerTest; |
159 friend class ProfileImpl; | 175 friend class ProfileImpl; |
160 friend class ProfileSyncServiceAutofillTest; | 176 friend class ProfileSyncServiceAutofillTest; |
161 | 177 |
162 // For tests. | 178 // For tests. |
(...skipping 24 matching lines...) Expand all Loading... |
187 void ReceiveLoadedCreditCards(WebDataService::Handle h, | 203 void ReceiveLoadedCreditCards(WebDataService::Handle h, |
188 const WDTypedResult* result); | 204 const WDTypedResult* result); |
189 | 205 |
190 // Cancels a pending query to the web database. |handle| is a pointer to the | 206 // Cancels a pending query to the web database. |handle| is a pointer to the |
191 // query handle. | 207 // query handle. |
192 void CancelPendingQuery(WebDataService::Handle* handle); | 208 void CancelPendingQuery(WebDataService::Handle* handle); |
193 | 209 |
194 // Saves |imported_profile| to the WebDB if it exists. | 210 // Saves |imported_profile| to the WebDB if it exists. |
195 virtual void SaveImportedProfile(const AutofillProfile& imported_profile); | 211 virtual void SaveImportedProfile(const AutofillProfile& imported_profile); |
196 | 212 |
197 // Merges |profile| into one of the |existing_profiles| if possible; otherwise | 213 // Notifies Sync about data migration if necessary. |
198 // appends |profile| to the end of that list. Fills |merged_profiles| with the | 214 void EmptyMigrationTrash(); |
199 // result. | |
200 bool MergeProfile(const AutofillProfile& profile, | |
201 const std::vector<AutofillProfile*>& existing_profiles, | |
202 std::vector<AutofillProfile>* merged_profiles); | |
203 | 215 |
204 // The first time this is called, logs an UMA metrics for the number of | 216 // The first time this is called, logs an UMA metrics for the number of |
205 // profiles the user has. On subsequent calls, does nothing. | 217 // profiles the user has. On subsequent calls, does nothing. |
206 void LogProfileCount() const; | 218 void LogProfileCount() const; |
207 | 219 |
208 // For tests. | 220 // For tests. |
209 const AutofillMetrics* metric_logger() const; | 221 const AutofillMetrics* metric_logger() const; |
210 void set_metric_logger(const AutofillMetrics* metric_logger); | 222 void set_metric_logger(const AutofillMetrics* metric_logger); |
211 | 223 |
212 // The profile hosting this PersonalDataManager. | 224 // The profile hosting this PersonalDataManager. |
(...skipping 30 matching lines...) Expand all Loading... |
243 ObserverList<Observer> observers_; | 255 ObserverList<Observer> observers_; |
244 | 256 |
245 private: | 257 private: |
246 // For logging UMA metrics. Overridden by metrics tests. | 258 // For logging UMA metrics. Overridden by metrics tests. |
247 scoped_ptr<const AutofillMetrics> metric_logger_; | 259 scoped_ptr<const AutofillMetrics> metric_logger_; |
248 | 260 |
249 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 261 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
250 }; | 262 }; |
251 | 263 |
252 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 264 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
OLD | NEW |