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

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

Issue 7967024: Profile shouldn't own PersonalDataManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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) 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/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h" 15 #include "base/observer_list.h"
17 #include "base/string16.h" 16 #include "base/string16.h"
18 #include "chrome/browser/autofill/autofill_profile.h" 17 #include "chrome/browser/autofill/autofill_profile.h"
19 #include "chrome/browser/autofill/credit_card.h" 18 #include "chrome/browser/autofill/credit_card.h"
20 #include "chrome/browser/autofill/field_types.h" 19 #include "chrome/browser/autofill/field_types.h"
20 #include "chrome/browser/profiles/profile_keyed_service.h"
21 #include "chrome/browser/sync/profile_sync_service_observer.h" 21 #include "chrome/browser/sync/profile_sync_service_observer.h"
22 #include "chrome/browser/webdata/web_data_service.h" 22 #include "chrome/browser/webdata/web_data_service.h"
23 #include "content/common/notification_observer.h"
24 #include "content/common/notification_registrar.h"
23 25
24 class AutofillManager; 26 class AutofillManager;
25 class AutofillMetrics; 27 class AutofillMetrics;
26 class FormStructure; 28 class FormStructure;
27 class PersonalDataManagerObserver; 29 class PersonalDataManagerObserver;
28 class Profile; 30 class Profile;
29 31
30 namespace autofill_helper { 32 namespace autofill_helper {
31 void SetProfiles(int, std::vector<AutofillProfile>*); 33 void SetProfiles(int, std::vector<AutofillProfile>*);
32 } 34 }
33 35
34 // Handles loading and saving Autofill profile information to the web database. 36 // Handles loading and saving Autofill profile information to the web database.
35 // This class also stores the profiles loaded from the database for use during 37 // This class also stores the profiles loaded from the database for use during
36 // Autofill. 38 // Autofill.
37 class PersonalDataManager 39 class PersonalDataManager
38 : public WebDataServiceConsumer, 40 : public WebDataServiceConsumer,
39 public ProfileSyncServiceObserver, 41 public ProfileSyncServiceObserver,
40 public base::RefCountedThreadSafe<PersonalDataManager> { 42 public ProfileKeyedService,
43 public NotificationObserver {
41 public: 44 public:
42 // WebDataServiceConsumer implementation: 45 // WebDataServiceConsumer:
43 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 46 virtual void OnWebDataServiceRequestDone(
44 const WDTypedResult* result); 47 WebDataService::Handle h,
48 const WDTypedResult* result) OVERRIDE;
45 49
46 // Sets the listener to be notified of PersonalDataManager events. 50 // Sets the listener to be notified of PersonalDataManager events.
47 virtual void SetObserver(PersonalDataManagerObserver* observer); 51 virtual void SetObserver(PersonalDataManagerObserver* observer);
48 52
49 // Removes |observer| as the observer of this PersonalDataManager. 53 // Removes |observer| as the observer of this PersonalDataManager.
50 virtual void RemoveObserver(PersonalDataManagerObserver* observer); 54 virtual void RemoveObserver(PersonalDataManagerObserver* observer);
51 55
52 // ProfileSyncServiceObserver: 56 // ProfileSyncServiceObserver:
53 virtual void OnStateChanged(); 57 virtual void OnStateChanged() OVERRIDE;
58
59 // ProfileKeyedService:
60 // Cancels any pending requests to WebDataService and stops listening for Sync
61 // notifications.
62 virtual void Shutdown() OVERRIDE;
63
64 // NotificationObserver:
65 // Observes "batch" changes made by Sync and refreshes data from the
66 // WebDataService in response.
67 virtual void Observe(int type,
68 const NotificationSource& source,
69 const NotificationDetails& details) OVERRIDE;
54 70
55 // Scans the given |form| for importable Autofill data. If the form includes 71 // Scans the given |form| for importable Autofill data. If the form includes
56 // sufficient address data, it is immediately imported. If the form includes 72 // sufficient address data, it is immediately imported. If the form includes
57 // sufficient credit card data, it is stored into |credit_card|, so that we 73 // sufficient credit card data, it is stored into |credit_card|, so that we
58 // can prompt the user whether to save this data. 74 // can prompt the user whether to save this data.
59 // Returns |true| if sufficient address or credit card data was found. 75 // Returns |true| if sufficient address or credit card data was found.
60 bool ImportFormData(const FormStructure& form, 76 bool ImportFormData(const FormStructure& form,
61 const CreditCard** credit_card); 77 const CreditCard** credit_card);
62 78
63 // Saves a credit card value detected in |ImportedFormData|. 79 // Saves a credit card value detected in |ImportedFormData|.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 140
125 // Merges |profile| into one of the |existing_profiles| if possible; otherwise 141 // Merges |profile| into one of the |existing_profiles| if possible; otherwise
126 // appends |profile| to the end of that list. Fills |merged_profiles| with the 142 // appends |profile| to the end of that list. Fills |merged_profiles| with the
127 // result. 143 // result.
128 static bool MergeProfile( 144 static bool MergeProfile(
129 const AutofillProfile& profile, 145 const AutofillProfile& profile,
130 const std::vector<AutofillProfile*>& existing_profiles, 146 const std::vector<AutofillProfile*>& existing_profiles,
131 std::vector<AutofillProfile>* merged_profiles); 147 std::vector<AutofillProfile>* merged_profiles);
132 148
133 protected: 149 protected:
134 // Make sure that only Profile and certain tests can create an instance of 150 // Only PersonalDataManagerFactory and certain tests can create instances of
135 // PersonalDataManager. 151 // PersonalDataManager.
136 friend class base::RefCountedThreadSafe<PersonalDataManager>; 152 friend class PersonalDataManagerFactory;
137 friend class AutofillMergeTest;
138 friend class PersonalDataManagerTest; 153 friend class PersonalDataManagerTest;
139 friend class ProfileImpl; 154 friend class scoped_ptr<PersonalDataManager>;
140 friend class ProfileSyncServiceAutofillTest;
141 friend class TestingAutomationProvider; 155 friend class TestingAutomationProvider;
142 friend void autofill_helper::SetProfiles(int, std::vector<AutofillProfile>*); 156 friend void autofill_helper::SetProfiles(int, std::vector<AutofillProfile>*);
143 157
158 // Creation and destruction is managed by PersonalDataManagerFactory only.
159 // Except for tests which subclass.
Ilya Sherman 2011/09/23 03:56:34 nit: I find this comment a bit confusing as writte
dhollowa 2011/09/23 16:30:03 Done.
144 PersonalDataManager(); 160 PersonalDataManager();
145 virtual ~PersonalDataManager(); 161 virtual ~PersonalDataManager();
146 162
147 // Sets |web_profiles_| to the contents of |profiles| and updates the web 163 // Sets |web_profiles_| to the contents of |profiles| and updates the web
148 // database by adding, updating and removing profiles. 164 // database by adding, updating and removing profiles.
149 // The relationship between this and Refresh is subtle. 165 // The relationship between this and Refresh is subtle.
150 // A call to |SetProfiles| could include out-of-date data that may conflict 166 // A call to |SetProfiles| could include out-of-date data that may conflict
151 // if we didn't refresh-to-latest before an Autofill window was opened for 167 // if we didn't refresh-to-latest before an Autofill window was opened for
152 // editing. |SetProfiles| is implemented to make a "best effort" to apply the 168 // editing. |SetProfiles| is implemented to make a "best effort" to apply the
153 // changes, but in extremely rare edge cases it is possible not all of the 169 // changes, but in extremely rare edge cases it is possible not all of the
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // The observers. 245 // The observers.
230 ObserverList<PersonalDataManagerObserver> observers_; 246 ObserverList<PersonalDataManagerObserver> observers_;
231 247
232 private: 248 private:
233 // For logging UMA metrics. Overridden by metrics tests. 249 // For logging UMA metrics. Overridden by metrics tests.
234 scoped_ptr<const AutofillMetrics> metric_logger_; 250 scoped_ptr<const AutofillMetrics> metric_logger_;
235 251
236 // Whether we have already logged the number of profiles this session. 252 // Whether we have already logged the number of profiles this session.
237 mutable bool has_logged_profile_count_; 253 mutable bool has_logged_profile_count_;
238 254
255 // Manages registration lifetime for NotificationObserver implementation.
256 NotificationRegistrar notification_registrar_;
257
239 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); 258 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
240 }; 259 };
241 260
242 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ 261 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698