OLD | NEW |
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 COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |
6 #define COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
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 : public WebDataServiceConsumer, | 38 class PersonalDataManager : public WebDataServiceConsumer, |
39 public AutofillWebDataServiceObserverOnUIThread { | 39 public AutofillWebDataServiceObserverOnUIThread { |
40 public: | 40 public: |
41 // A pair of GUID and variant index. Represents a single FormGroup and a | 41 // A pair of GUID and variant index. Represents a single FormGroup and a |
42 // specific data variant. | 42 // specific data variant. |
43 typedef std::pair<std::string, size_t> GUIDPair; | 43 typedef std::pair<std::string, size_t> GUIDPair; |
44 | 44 |
45 PersonalDataManager(); | 45 explicit PersonalDataManager(const std::string& app_locale); |
46 virtual ~PersonalDataManager(); | 46 virtual ~PersonalDataManager(); |
47 | 47 |
48 // Kicks off asynchronous loading of profiles and credit cards. | 48 // Kicks off asynchronous loading of profiles and credit cards. |
49 void Init(content::BrowserContext* context); | 49 void Init(content::BrowserContext* context); |
50 | 50 |
51 // WebDataServiceConsumer: | 51 // WebDataServiceConsumer: |
52 virtual void OnWebDataServiceRequestDone( | 52 virtual void OnWebDataServiceRequestDone( |
53 WebDataServiceBase::Handle h, | 53 WebDataServiceBase::Handle h, |
54 const WDTypedResult* result) OVERRIDE; | 54 const WDTypedResult* result) OVERRIDE; |
55 | 55 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Re-loads profiles and credit cards from the WebDatabase asynchronously. | 145 // Re-loads profiles and credit cards from the WebDatabase asynchronously. |
146 // In the general case, this is a no-op and will re-create the same | 146 // In the general case, this is a no-op and will re-create the same |
147 // in-memory model as existed prior to the call. If any change occurred to | 147 // in-memory model as existed prior to the call. If any change occurred to |
148 // 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 |
149 // 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 |
150 // result of this call. | 150 // result of this call. |
151 // | 151 // |
152 // Also see SetProfile for more details. | 152 // Also see SetProfile for more details. |
153 virtual void Refresh(); | 153 virtual void Refresh(); |
154 | 154 |
| 155 const std::string& app_locale() const { return app_locale_; } |
| 156 |
155 // Checks suitability of |profile| for adding to the user's set of profiles. | 157 // Checks suitability of |profile| for adding to the user's set of profiles. |
156 static bool IsValidLearnableProfile(const AutofillProfile& profile); | 158 static bool IsValidLearnableProfile(const AutofillProfile& profile); |
157 | 159 |
158 // Merges |profile| into one of the |existing_profiles| if possible; otherwise | 160 // Merges |profile| into one of the |existing_profiles| if possible; otherwise |
159 // appends |profile| to the end of that list. Fills |merged_profiles| with the | 161 // appends |profile| to the end of that list. Fills |merged_profiles| with the |
160 // result. | 162 // result. |
161 static bool MergeProfile( | 163 static bool MergeProfile( |
162 const AutofillProfile& profile, | 164 const AutofillProfile& profile, |
163 const std::vector<AutofillProfile*>& existing_profiles, | 165 const std::vector<AutofillProfile*>& existing_profiles, |
| 166 const std::string& app_locale, |
164 std::vector<AutofillProfile>* merged_profiles); | 167 std::vector<AutofillProfile>* merged_profiles); |
165 | 168 |
166 protected: | 169 protected: |
167 // Only PersonalDataManagerFactory and certain tests can create instances of | 170 // Only PersonalDataManagerFactory and certain tests can create instances of |
168 // PersonalDataManager. | 171 // PersonalDataManager. |
169 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast); | 172 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast); |
170 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup); | 173 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup); |
171 FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest, | 174 FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest, |
172 AggregateExistingAuxiliaryProfile); | 175 AggregateExistingAuxiliaryProfile); |
173 friend class AutofillTest; | 176 friend class AutofillTest; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // is queried on another thread, we record the query handle until we | 257 // is queried on another thread, we record the query handle until we |
255 // get called back. We store handles for both profile and credit card queries | 258 // get called back. We store handles for both profile and credit card queries |
256 // so they can be loaded at the same time. | 259 // so they can be loaded at the same time. |
257 WebDataServiceBase::Handle pending_profiles_query_; | 260 WebDataServiceBase::Handle pending_profiles_query_; |
258 WebDataServiceBase::Handle pending_creditcards_query_; | 261 WebDataServiceBase::Handle pending_creditcards_query_; |
259 | 262 |
260 // The observers. | 263 // The observers. |
261 ObserverList<PersonalDataManagerObserver> observers_; | 264 ObserverList<PersonalDataManagerObserver> observers_; |
262 | 265 |
263 private: | 266 private: |
| 267 std::string app_locale_; |
264 | 268 |
265 // For logging UMA metrics. Overridden by metrics tests. | 269 // For logging UMA metrics. Overridden by metrics tests. |
266 scoped_ptr<const AutofillMetrics> metric_logger_; | 270 scoped_ptr<const AutofillMetrics> metric_logger_; |
267 | 271 |
268 // Whether we have already logged the number of profiles this session. | 272 // Whether we have already logged the number of profiles this session. |
269 mutable bool has_logged_profile_count_; | 273 mutable bool has_logged_profile_count_; |
270 | 274 |
271 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 275 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
272 }; | 276 }; |
273 | 277 |
274 #endif // COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 278 #endif // COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |
OLD | NEW |