Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: chrome/browser/autofill/personal_data_manager.h

Issue 10908065: Introduce a couple of abstract bases for WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "chrome/browser/autofill/autofill_profile.h" 16 #include "chrome/browser/autofill/autofill_profile.h"
17 #include "chrome/browser/autofill/credit_card.h" 17 #include "chrome/browser/autofill/credit_card.h"
18 #include "chrome/browser/autofill/field_types.h" 18 #include "chrome/browser/autofill/field_types.h"
19 #include "chrome/browser/api/webdata/autofill_web_data.h"
19 #include "chrome/browser/profiles/profile_keyed_service.h" 20 #include "chrome/browser/profiles/profile_keyed_service.h"
20 #include "chrome/browser/sync/profile_sync_service_observer.h" 21 #include "chrome/browser/sync/profile_sync_service_observer.h"
21 #include "chrome/browser/webdata/web_data_service.h"
22 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
24 24
25 class AutofillMetrics; 25 class AutofillMetrics;
26 class FormStructure; 26 class FormStructure;
27 class PersonalDataManagerObserver; 27 class PersonalDataManagerObserver;
28 class Profile; 28 class Profile;
29 29
30 namespace autofill_helper { 30 namespace autofill_helper {
31 void SetProfiles(int, std::vector<AutofillProfile>*); 31 void SetProfiles(int, std::vector<AutofillProfile>*);
32 void SetCreditCards(int, std::vector<CreditCard>*); 32 void SetCreditCards(int, std::vector<CreditCard>*);
33 } 33 }
34 34
35 // Handles loading and saving Autofill profile information to the web database. 35 // Handles loading and saving Autofill profile information to the web database.
36 // This class also stores the profiles loaded from the database for use during 36 // This class also stores the profiles loaded from the database for use during
37 // Autofill. 37 // Autofill.
38 class PersonalDataManager 38 class PersonalDataManager
39 : public WebDataServiceConsumer, 39 : public WebDataServiceConsumer,
40 public ProfileSyncServiceObserver, 40 public ProfileSyncServiceObserver,
41 public ProfileKeyedService, 41 public ProfileKeyedService,
42 public content::NotificationObserver { 42 public content::NotificationObserver {
43 public: 43 public:
44 // WebDataServiceConsumer: 44 // WebDataServiceConsumer:
45 virtual void OnWebDataServiceRequestDone( 45 virtual void OnWebDataServiceRequestDone(
46 WebDataService::Handle h, 46 WebDataServiceBase::Handle h,
47 const WDTypedResult* result) OVERRIDE; 47 const WDTypedResult* result) OVERRIDE;
48 48
49 // Sets the listener to be notified of PersonalDataManager events. 49 // Sets the listener to be notified of PersonalDataManager events.
50 virtual void SetObserver(PersonalDataManagerObserver* observer); 50 virtual void SetObserver(PersonalDataManagerObserver* observer);
51 51
52 // Removes |observer| as the observer of this PersonalDataManager. 52 // Removes |observer| as the observer of this PersonalDataManager.
53 virtual void RemoveObserver(PersonalDataManagerObserver* observer); 53 virtual void RemoveObserver(PersonalDataManagerObserver* observer);
54 54
55 // ProfileSyncServiceObserver: 55 // ProfileSyncServiceObserver:
56 virtual void OnStateChanged() OVERRIDE; 56 virtual void OnStateChanged() OVERRIDE;
57 57
58 // ProfileKeyedService: 58 // ProfileKeyedService:
59 // Cancels any pending requests to WebDataService and stops listening for Sync 59 // Cancels any pending requests to WebDataServiceBase and stops
60 // notifications. 60 // listening for Sync notifications.
61 virtual void Shutdown() OVERRIDE; 61 virtual void Shutdown() OVERRIDE;
62 62
63 // content::NotificationObserver: 63 // content::NotificationObserver:
64 // Observes "batch" changes made by Sync and refreshes data from the 64 // Observes "batch" changes made by Sync and refreshes data from the
65 // WebDataService in response. 65 // WebDataServiceBase in response.
66 virtual void Observe(int type, 66 virtual void Observe(int type,
67 const content::NotificationSource& source, 67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) OVERRIDE; 68 const content::NotificationDetails& details) OVERRIDE;
69 69
70 // Scans the given |form| for importable Autofill data. If the form includes 70 // Scans the given |form| for importable Autofill data. If the form includes
71 // sufficient address data, it is immediately imported. If the form includes 71 // sufficient address data, it is immediately imported. If the form includes
72 // sufficient credit card data, it is stored into |credit_card|, so that we 72 // sufficient credit card data, it is stored into |credit_card|, so that we
73 // can prompt the user whether to save this data. 73 // can prompt the user whether to save this data.
74 // Returns |true| if sufficient address or credit card data was found. 74 // Returns |true| if sufficient address or credit card data was found.
75 bool ImportFormData(const FormStructure& form, 75 bool ImportFormData(const FormStructure& form,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 virtual void LoadProfiles(); 182 virtual void LoadProfiles();
183 183
184 // Loads the auxiliary profiles. Currently Mac only. 184 // Loads the auxiliary profiles. Currently Mac only.
185 void LoadAuxiliaryProfiles() const; 185 void LoadAuxiliaryProfiles() const;
186 186
187 // Loads the saved credit cards from the web database. 187 // Loads the saved credit cards from the web database.
188 virtual void LoadCreditCards(); 188 virtual void LoadCreditCards();
189 189
190 // Receives the loaded profiles from the web data service and stores them in 190 // Receives the loaded profiles from the web data service and stores them in
191 // |credit_cards_|. 191 // |credit_cards_|.
192 void ReceiveLoadedProfiles(WebDataService::Handle h, 192 void ReceiveLoadedProfiles(WebDataServiceBase::Handle h,
193 const WDTypedResult* result); 193 const WDTypedResult* result);
194 194
195 // Receives the loaded credit cards from the web data service and stores them 195 // Receives the loaded credit cards from the web data service and stores them
196 // in |credit_cards_|. 196 // in |credit_cards_|.
197 void ReceiveLoadedCreditCards(WebDataService::Handle h, 197 void ReceiveLoadedCreditCards(WebDataServiceBase::Handle h,
198 const WDTypedResult* result); 198 const WDTypedResult* result);
199 199
200 // Cancels a pending query to the web database. |handle| is a pointer to the 200 // Cancels a pending query to the web database. |handle| is a pointer to the
201 // query handle. 201 // query handle.
202 void CancelPendingQuery(WebDataService::Handle* handle); 202 void CancelPendingQuery(WebDataServiceBase::Handle* handle);
203 203
204 // Saves |imported_profile| to the WebDB if it exists. 204 // Saves |imported_profile| to the WebDB if it exists.
205 virtual void SaveImportedProfile(const AutofillProfile& imported_profile); 205 virtual void SaveImportedProfile(const AutofillProfile& imported_profile);
206 206
207 // Notifies Sync about data migration if necessary. 207 // Notifies Sync about data migration if necessary.
208 void EmptyMigrationTrash(); 208 void EmptyMigrationTrash();
209 209
210 // The first time this is called, logs an UMA metrics for the number of 210 // The first time this is called, logs an UMA metrics for the number of
211 // profiles the user has. On subsequent calls, does nothing. 211 // profiles the user has. On subsequent calls, does nothing.
212 void LogProfileCount() const; 212 void LogProfileCount() const;
(...skipping 17 matching lines...) Expand all
230 // Auxiliary profiles. 230 // Auxiliary profiles.
231 mutable ScopedVector<AutofillProfile> auxiliary_profiles_; 231 mutable ScopedVector<AutofillProfile> auxiliary_profiles_;
232 232
233 // Storage for combined web and auxiliary profiles. Contents are weak 233 // Storage for combined web and auxiliary profiles. Contents are weak
234 // references. Lifetime managed by |web_profiles_| and |auxiliary_profiles_|. 234 // references. Lifetime managed by |web_profiles_| and |auxiliary_profiles_|.
235 mutable std::vector<AutofillProfile*> profiles_; 235 mutable std::vector<AutofillProfile*> profiles_;
236 236
237 // The loaded credit cards. 237 // The loaded credit cards.
238 ScopedVector<CreditCard> credit_cards_; 238 ScopedVector<CreditCard> credit_cards_;
239 239
240 // When the manager makes a request from WebDataService, the database 240 // When the manager makes a request from WebDataServiceBase, the database
241 // is queried on another thread, we record the query handle until we 241 // is queried on another thread, we record the query handle until we
242 // get called back. We store handles for both profile and credit card queries 242 // get called back. We store handles for both profile and credit card queries
243 // so they can be loaded at the same time. 243 // so they can be loaded at the same time.
244 WebDataService::Handle pending_profiles_query_; 244 WebDataServiceBase::Handle pending_profiles_query_;
245 WebDataService::Handle pending_creditcards_query_; 245 WebDataServiceBase::Handle pending_creditcards_query_;
246 246
247 // The observers. 247 // The observers.
248 ObserverList<PersonalDataManagerObserver> observers_; 248 ObserverList<PersonalDataManagerObserver> observers_;
249 249
250 private: 250 private:
251 // Kicks off asynchronous loading of profiles and credit cards. 251 // Kicks off asynchronous loading of profiles and credit cards.
252 void Init(Profile* profile); 252 void Init(Profile* profile);
253 253
254 // For logging UMA metrics. Overridden by metrics tests. 254 // For logging UMA metrics. Overridden by metrics tests.
255 scoped_ptr<const AutofillMetrics> metric_logger_; 255 scoped_ptr<const AutofillMetrics> metric_logger_;
256 256
257 // Whether we have already logged the number of profiles this session. 257 // Whether we have already logged the number of profiles this session.
258 mutable bool has_logged_profile_count_; 258 mutable bool has_logged_profile_count_;
259 259
260 // Manages registration lifetime for NotificationObserver implementation. 260 // Manages registration lifetime for NotificationObserver implementation.
261 content::NotificationRegistrar notification_registrar_; 261 content::NotificationRegistrar notification_registrar_;
262 262
263 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); 263 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
264 }; 264 };
265 265
266 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ 266 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698