OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 22 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 23 #include "components/autofill/core/browser/autofill_client.h" |
23 #include "components/autofill/core/browser/autofill_download.h" | 24 #include "components/autofill/core/browser/autofill_download.h" |
24 #include "components/autofill/core/browser/autofill_driver.h" | 25 #include "components/autofill/core/browser/autofill_driver.h" |
25 #include "components/autofill/core/browser/autofill_manager_delegate.h" | |
26 #include "components/autofill/core/browser/form_structure.h" | 26 #include "components/autofill/core/browser/form_structure.h" |
27 #include "components/autofill/core/browser/personal_data_manager.h" | 27 #include "components/autofill/core/browser/personal_data_manager.h" |
28 #include "components/autofill/core/common/form_data.h" | 28 #include "components/autofill/core/common/form_data.h" |
29 | 29 |
30 class GURL; | 30 class GURL; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 class RenderViewHost; | 33 class RenderViewHost; |
34 class WebContents; | 34 class WebContents; |
35 } | 35 } |
36 | 36 |
37 namespace gfx { | 37 namespace gfx { |
38 class Rect; | 38 class Rect; |
39 class RectF; | 39 class RectF; |
40 } | 40 } |
41 | 41 |
42 namespace user_prefs { | 42 namespace user_prefs { |
43 class PrefRegistrySyncable; | 43 class PrefRegistrySyncable; |
44 } | 44 } |
45 | 45 |
46 namespace autofill { | 46 namespace autofill { |
47 | 47 |
48 class AutofillDataModel; | 48 class AutofillDataModel; |
49 class AutofillDownloadManager; | 49 class AutofillDownloadManager; |
50 class AutofillExternalDelegate; | 50 class AutofillExternalDelegate; |
51 class AutofillField; | 51 class AutofillField; |
52 class AutofillManagerDelegate; | 52 class AutofillClient; |
53 class AutofillManagerTestDelegate; | 53 class AutofillManagerTestDelegate; |
54 class AutofillMetrics; | 54 class AutofillMetrics; |
55 class AutofillProfile; | 55 class AutofillProfile; |
56 class AutofillType; | 56 class AutofillType; |
57 class CreditCard; | 57 class CreditCard; |
58 class FormStructureBrowserTest; | 58 class FormStructureBrowserTest; |
59 | 59 |
60 struct FormData; | 60 struct FormData; |
61 struct FormFieldData; | 61 struct FormFieldData; |
62 struct PasswordFormFillData; | 62 struct PasswordFormFillData; |
63 | 63 |
64 // Manages saving and restoring the user's personal information entered into web | 64 // Manages saving and restoring the user's personal information entered into web |
65 // forms. | 65 // forms. |
66 class AutofillManager : public AutofillDownloadManager::Observer { | 66 class AutofillManager : public AutofillDownloadManager::Observer { |
67 public: | 67 public: |
68 enum AutofillDownloadManagerState { | 68 enum AutofillDownloadManagerState { |
69 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, | 69 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, |
70 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, | 70 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, |
71 }; | 71 }; |
72 | 72 |
73 // Registers our Enable/Disable Autofill pref. | 73 // Registers our Enable/Disable Autofill pref. |
74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
75 | 75 |
76 #if defined(OS_MACOSX) && !defined(OS_IOS) | 76 #if defined(OS_MACOSX) && !defined(OS_IOS) |
77 static void MigrateUserPrefs(PrefService* prefs); | 77 static void MigrateUserPrefs(PrefService* prefs); |
78 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 78 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
79 | 79 |
80 AutofillManager(AutofillDriver* driver, | 80 AutofillManager(AutofillDriver* driver, |
81 autofill::AutofillManagerDelegate* delegate, | 81 AutofillClient* client, |
82 const std::string& app_locale, | 82 const std::string& app_locale, |
83 AutofillDownloadManagerState enable_download_manager); | 83 AutofillDownloadManagerState enable_download_manager); |
84 virtual ~AutofillManager(); | 84 virtual ~AutofillManager(); |
85 | 85 |
86 // Sets an external delegate. | 86 // Sets an external delegate. |
87 void SetExternalDelegate(AutofillExternalDelegate* delegate); | 87 void SetExternalDelegate(AutofillExternalDelegate* delegate); |
88 | 88 |
89 void ShowAutofillSettings(); | 89 void ShowAutofillSettings(); |
90 | 90 |
91 #if defined(OS_MACOSX) && !defined(OS_IOS) | 91 #if defined(OS_MACOSX) && !defined(OS_IOS) |
(...skipping 26 matching lines...) Expand all Loading... |
118 // Remove the specified Autocomplete entry. | 118 // Remove the specified Autocomplete entry. |
119 void RemoveAutocompleteEntry(const base::string16& name, | 119 void RemoveAutocompleteEntry(const base::string16& name, |
120 const base::string16& value); | 120 const base::string16& value); |
121 | 121 |
122 // Returns the present form structures seen by Autofill manager. | 122 // Returns the present form structures seen by Autofill manager. |
123 const std::vector<FormStructure*>& GetFormStructures(); | 123 const std::vector<FormStructure*>& GetFormStructures(); |
124 | 124 |
125 // Happens when the autocomplete dialog runs its callback when being closed. | 125 // Happens when the autocomplete dialog runs its callback when being closed. |
126 void RequestAutocompleteDialogClosed(); | 126 void RequestAutocompleteDialogClosed(); |
127 | 127 |
128 autofill::AutofillManagerDelegate* delegate() const { | 128 AutofillClient* client() const { return client_; } |
129 return manager_delegate_; | |
130 } | |
131 | 129 |
132 const std::string& app_locale() const { return app_locale_; } | 130 const std::string& app_locale() const { return app_locale_; } |
133 | 131 |
134 // Only for testing. | 132 // Only for testing. |
135 void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate); | 133 void SetTestDelegate(AutofillManagerTestDelegate* delegate); |
136 | 134 |
137 void OnFormsSeen(const std::vector<FormData>& forms, | 135 void OnFormsSeen(const std::vector<FormData>& forms, |
138 const base::TimeTicks& timestamp); | 136 const base::TimeTicks& timestamp); |
139 | 137 |
140 // Processes the submitted |form|, saving any new Autofill data and uploading | 138 // Processes the submitted |form|, saving any new Autofill data and uploading |
141 // the possible field types for the submitted fields to the crowdsourcing | 139 // the possible field types for the submitted fields to the crowdsourcing |
142 // server. Returns false if this form is not relevant for Autofill. | 140 // server. Returns false if this form is not relevant for Autofill. |
143 bool OnFormSubmitted(const FormData& form, | 141 bool OnFormSubmitted(const FormData& form, |
144 const base::TimeTicks& timestamp); | 142 const base::TimeTicks& timestamp); |
145 | 143 |
(...skipping 24 matching lines...) Expand all Loading... |
170 | 168 |
171 // Resets cache. | 169 // Resets cache. |
172 virtual void Reset(); | 170 virtual void Reset(); |
173 | 171 |
174 // Returns the value of the AutofillEnabled pref. | 172 // Returns the value of the AutofillEnabled pref. |
175 virtual bool IsAutofillEnabled() const; | 173 virtual bool IsAutofillEnabled() const; |
176 | 174 |
177 protected: | 175 protected: |
178 // Test code should prefer to use this constructor. | 176 // Test code should prefer to use this constructor. |
179 AutofillManager(AutofillDriver* driver, | 177 AutofillManager(AutofillDriver* driver, |
180 autofill::AutofillManagerDelegate* delegate, | 178 AutofillClient* client, |
181 PersonalDataManager* personal_data); | 179 PersonalDataManager* personal_data); |
182 | 180 |
183 // Uploads the form data to the Autofill server. | 181 // Uploads the form data to the Autofill server. |
184 virtual void UploadFormData(const FormStructure& submitted_form); | 182 virtual void UploadFormData(const FormStructure& submitted_form); |
185 | 183 |
186 // Logs quality metrics for the |submitted_form| and uploads the form data | 184 // Logs quality metrics for the |submitted_form| and uploads the form data |
187 // to the crowdsourcing server, if appropriate. | 185 // to the crowdsourcing server, if appropriate. |
188 virtual void UploadFormDataAsyncCallback( | 186 virtual void UploadFormDataAsyncCallback( |
189 const FormStructure* submitted_form, | 187 const FormStructure* submitted_form, |
190 const base::TimeTicks& load_time, | 188 const base::TimeTicks& load_time, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 void UpdateInitialInteractionTimestamp( | 284 void UpdateInitialInteractionTimestamp( |
287 const base::TimeTicks& interaction_timestamp); | 285 const base::TimeTicks& interaction_timestamp); |
288 | 286 |
289 // Shared code to determine if |form| should be uploaded. | 287 // Shared code to determine if |form| should be uploaded. |
290 bool ShouldUploadForm(const FormStructure& form); | 288 bool ShouldUploadForm(const FormStructure& form); |
291 | 289 |
292 // Provides driver-level context to the shared code of the component. Must | 290 // Provides driver-level context to the shared code of the component. Must |
293 // outlive this object. | 291 // outlive this object. |
294 AutofillDriver* driver_; | 292 AutofillDriver* driver_; |
295 | 293 |
296 autofill::AutofillManagerDelegate* const manager_delegate_; | 294 AutofillClient* const client_; |
297 | 295 |
298 std::string app_locale_; | 296 std::string app_locale_; |
299 | 297 |
300 // The personal data manager, used to save and load personal data to/from the | 298 // The personal data manager, used to save and load personal data to/from the |
301 // web database. This is overridden by the AutofillManagerTest. | 299 // web database. This is overridden by the AutofillManagerTest. |
302 // Weak reference. | 300 // Weak reference. |
303 // May be NULL. NULL indicates OTR. | 301 // May be NULL. NULL indicates OTR. |
304 PersonalDataManager* personal_data_; | 302 PersonalDataManager* personal_data_; |
305 | 303 |
306 std::list<std::string> autofilled_form_signatures_; | 304 std::list<std::string> autofilled_form_signatures_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 336 |
339 // GUID to ID mapping. We keep two maps to convert back and forth. | 337 // GUID to ID mapping. We keep two maps to convert back and forth. |
340 mutable std::map<PersonalDataManager::GUIDPair, int> guid_id_map_; | 338 mutable std::map<PersonalDataManager::GUIDPair, int> guid_id_map_; |
341 mutable std::map<int, PersonalDataManager::GUIDPair> id_guid_map_; | 339 mutable std::map<int, PersonalDataManager::GUIDPair> id_guid_map_; |
342 | 340 |
343 // Delegate to perform external processing (display, selection) on | 341 // Delegate to perform external processing (display, selection) on |
344 // our behalf. Weak. | 342 // our behalf. Weak. |
345 AutofillExternalDelegate* external_delegate_; | 343 AutofillExternalDelegate* external_delegate_; |
346 | 344 |
347 // Delegate used in test to get notifications on certain events. | 345 // Delegate used in test to get notifications on certain events. |
348 autofill::AutofillManagerTestDelegate* test_delegate_; | 346 AutofillManagerTestDelegate* test_delegate_; |
349 | 347 |
350 base::WeakPtrFactory<AutofillManager> weak_ptr_factory_; | 348 base::WeakPtrFactory<AutofillManager> weak_ptr_factory_; |
351 | 349 |
352 friend class AutofillManagerTest; | 350 friend class AutofillManagerTest; |
353 friend class autofill::FormStructureBrowserTest; | 351 friend class FormStructureBrowserTest; |
354 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 352 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
355 DeterminePossibleFieldTypesForUpload); | 353 DeterminePossibleFieldTypesForUpload); |
356 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 354 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
357 DeterminePossibleFieldTypesForUploadStressTest); | 355 DeterminePossibleFieldTypesForUploadStressTest); |
358 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 356 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
359 DisabledAutofillDispatchesError); | 357 DisabledAutofillDispatchesError); |
360 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AddressSuggestionsCount); | 358 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AddressSuggestionsCount); |
361 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtPageLoad); | 359 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtPageLoad); |
362 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, DeveloperEngagement); | 360 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, DeveloperEngagement); |
363 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); | 361 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); |
(...skipping 10 matching lines...) Expand all Loading... |
374 UserHappinessFormLoadAndSubmission); | 372 UserHappinessFormLoadAndSubmission); |
375 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 373 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
376 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 374 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
377 FormSubmittedAutocompleteEnabled); | 375 FormSubmittedAutocompleteEnabled); |
378 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 376 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
379 }; | 377 }; |
380 | 378 |
381 } // namespace autofill | 379 } // namespace autofill |
382 | 380 |
383 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 381 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
OLD | NEW |