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

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: Addresses isherman #11 Created 9 years, 2 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Re-loads profiles and credit cards from the WebDatabase asynchronously. 125 // Re-loads profiles and credit cards from the WebDatabase asynchronously.
110 // In the general case, this is a no-op and will re-create the same 126 // In the general case, this is a no-op and will re-create the same
111 // in-memory model as existed prior to the call. If any change occurred to 127 // in-memory model as existed prior to the call. If any change occurred to
112 // profiles in the WebDatabase directly, as is the case if the browser sync 128 // profiles in the WebDatabase directly, as is the case if the browser sync
113 // engine processed a change from the cloud, we will learn of these as a 129 // engine processed a change from the cloud, we will learn of these as a
114 // result of this call. 130 // result of this call.
115 // 131 //
116 // Also see SetProfile for more details. 132 // Also see SetProfile for more details.
117 virtual void Refresh(); 133 virtual void Refresh();
118 134
119 // Kicks off asynchronous loading of profiles and credit cards.
120 void Init(Profile* profile);
121
122 // Checks suitability of |profile| for adding to the user's set of profiles. 135 // Checks suitability of |profile| for adding to the user's set of profiles.
123 static bool IsValidLearnableProfile(const AutofillProfile& profile); 136 static bool IsValidLearnableProfile(const AutofillProfile& profile);
124 137
125 // Merges |profile| into one of the |existing_profiles| if possible; otherwise 138 // 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 139 // appends |profile| to the end of that list. Fills |merged_profiles| with the
127 // result. 140 // result.
128 static bool MergeProfile( 141 static bool MergeProfile(
129 const AutofillProfile& profile, 142 const AutofillProfile& profile,
130 const std::vector<AutofillProfile*>& existing_profiles, 143 const std::vector<AutofillProfile*>& existing_profiles,
131 std::vector<AutofillProfile>* merged_profiles); 144 std::vector<AutofillProfile>* merged_profiles);
132 145
133 protected: 146 protected:
134 // Make sure that only Profile and certain tests can create an instance of 147 // Only PersonalDataManagerFactory and certain tests can create instances of
135 // PersonalDataManager. 148 // PersonalDataManager.
136 friend class base::RefCountedThreadSafe<PersonalDataManager>; 149 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast);
137 friend class AutofillMergeTest; 150 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup);
151 friend class PersonalDataManagerFactory;
138 friend class PersonalDataManagerTest; 152 friend class PersonalDataManagerTest;
139 friend class ProfileImpl; 153 friend class scoped_ptr<PersonalDataManager>;
140 friend class ProfileSyncServiceAutofillTest; 154 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
144 PersonalDataManager(); 158 PersonalDataManager();
145 virtual ~PersonalDataManager(); 159 virtual ~PersonalDataManager();
146 160
147 // Sets |web_profiles_| to the contents of |profiles| and updates the web 161 // Sets |web_profiles_| to the contents of |profiles| and updates the web
148 // database by adding, updating and removing profiles. 162 // database by adding, updating and removing profiles.
149 // The relationship between this and Refresh is subtle. 163 // The relationship between this and Refresh is subtle.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // is queried on another thread, we record the query handle until we 237 // is queried on another thread, we record the query handle until we
224 // get called back. We store handles for both profile and credit card queries 238 // get called back. We store handles for both profile and credit card queries
225 // so they can be loaded at the same time. 239 // so they can be loaded at the same time.
226 WebDataService::Handle pending_profiles_query_; 240 WebDataService::Handle pending_profiles_query_;
227 WebDataService::Handle pending_creditcards_query_; 241 WebDataService::Handle pending_creditcards_query_;
228 242
229 // The observers. 243 // The observers.
230 ObserverList<PersonalDataManagerObserver> observers_; 244 ObserverList<PersonalDataManagerObserver> observers_;
231 245
232 private: 246 private:
247 // Kicks off asynchronous loading of profiles and credit cards.
248 void Init(Profile* profile);
249
233 // For logging UMA metrics. Overridden by metrics tests. 250 // For logging UMA metrics. Overridden by metrics tests.
234 scoped_ptr<const AutofillMetrics> metric_logger_; 251 scoped_ptr<const AutofillMetrics> metric_logger_;
235 252
236 // Whether we have already logged the number of profiles this session. 253 // Whether we have already logged the number of profiles this session.
237 mutable bool has_logged_profile_count_; 254 mutable bool has_logged_profile_count_;
238 255
256 // Manages registration lifetime for NotificationObserver implementation.
257 NotificationRegistrar notification_registrar_;
258
239 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); 259 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
240 }; 260 };
241 261
242 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ 262 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_metrics_unittest.cc ('k') | chrome/browser/autofill/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698