OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_AUTOFILL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 #include <string> | 10 #include <string> |
11 #include <list> | 11 #include <list> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/scoped_vector.h" | 15 #include "base/scoped_vector.h" |
16 #include "chrome/browser/autofill/autofill_dialog.h" | 16 #include "chrome/browser/autofill/autofill_dialog.h" |
17 #include "chrome/browser/autofill/autofill_download.h" | 17 #include "chrome/browser/autofill/autofill_download.h" |
| 18 #include "chrome/browser/autofill/autofill_metrics.h" |
18 #include "chrome/browser/autofill/personal_data_manager.h" | 19 #include "chrome/browser/autofill/personal_data_manager.h" |
19 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 20 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
20 | 21 |
21 class AutoFillCCInfoBarDelegate; | 22 class AutoFillCCInfoBarDelegate; |
22 class AutoFillProfile; | 23 class AutoFillProfile; |
23 class CreditCard; | 24 class CreditCard; |
24 class FormStructure; | 25 class FormStructure; |
25 class PrefService; | 26 class PrefService; |
26 class TabContents; | 27 class TabContents; |
27 | 28 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 virtual void OnLoadedAutoFillHeuristics(const std::string& heuristic_xml); | 70 virtual void OnLoadedAutoFillHeuristics(const std::string& heuristic_xml); |
70 virtual void OnUploadedAutoFillHeuristics(const std::string& form_signature); | 71 virtual void OnUploadedAutoFillHeuristics(const std::string& form_signature); |
71 virtual void OnHeuristicsRequestError( | 72 virtual void OnHeuristicsRequestError( |
72 const std::string& form_signature, | 73 const std::string& form_signature, |
73 AutoFillDownloadManager::AutoFillRequestType request_type, | 74 AutoFillDownloadManager::AutoFillRequestType request_type, |
74 int http_error); | 75 int http_error); |
75 | 76 |
76 // Returns the value of the AutoFillEnabled pref. | 77 // Returns the value of the AutoFillEnabled pref. |
77 virtual bool IsAutoFillEnabled() const; | 78 virtual bool IsAutoFillEnabled() const; |
78 | 79 |
79 // Uses heuristics and existing personal data to determine the possible field | |
80 // types. | |
81 void DeterminePossibleFieldTypes(FormStructure* form_structure); | |
82 | |
83 // Handles the form data submitted by the user. | 80 // Handles the form data submitted by the user. |
84 void HandleSubmit(); | 81 void HandleSubmit(); |
85 | 82 |
86 // Uploads the form data to the AutoFill server. | 83 // Uploads the form data to the AutoFill server. |
87 void UploadFormData(); | 84 void UploadFormData(); |
88 | 85 |
89 protected: | 86 protected: |
90 // For tests. | 87 // For tests. |
91 AutoFillManager(); | 88 AutoFillManager(); |
92 AutoFillManager(TabContents* tab_contents, | 89 AutoFillManager(TabContents* tab_contents, |
93 PersonalDataManager* personal_data); | 90 PersonalDataManager* personal_data); |
94 | 91 |
95 void set_personal_data_manager(PersonalDataManager* personal_data) { | 92 void set_personal_data_manager(PersonalDataManager* personal_data) { |
96 personal_data_ = personal_data; | 93 personal_data_ = personal_data; |
97 } | 94 } |
98 | 95 |
| 96 void set_log_server_query_metric_fn( |
| 97 autofill_metrics::LogServerQueryMetricFn log_server_query_metric) { |
| 98 log_server_query_metric_ = log_server_query_metric; |
| 99 } |
| 100 void set_log_quality_metric_fn( |
| 101 autofill_metrics::LogQualityMetricFn log_quality_metric) { |
| 102 log_quality_metric_ = log_quality_metric; |
| 103 } |
| 104 |
99 // Maps GUIDs to and from IDs that are used to identify profiles and credit | 105 // Maps GUIDs to and from IDs that are used to identify profiles and credit |
100 // cards sent to and from the renderer process. | 106 // cards sent to and from the renderer process. |
101 virtual int GUIDToID(const std::string& guid); | 107 virtual int GUIDToID(const std::string& guid); |
102 virtual const std::string IDToGUID(int id); | 108 virtual const std::string IDToGUID(int id); |
103 | 109 |
104 // Methods for packing and unpacking credit card and profile IDs for sending | 110 // Methods for packing and unpacking credit card and profile IDs for sending |
105 // and receiving to and from the renderer process. | 111 // and receiving to and from the renderer process. |
106 int PackGUIDs(const std::string& cc_guid, const std::string& profile_guid); | 112 int PackGUIDs(const std::string& cc_guid, const std::string& profile_guid); |
107 void UnpackGUIDs(int id, std::string* cc_guid, std::string* profile_guid); | 113 void UnpackGUIDs(int id, std::string* cc_guid, std::string* profile_guid); |
108 | 114 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 webkit_glue::FormField* field); | 161 webkit_glue::FormField* field); |
156 | 162 |
157 // Set |field| argument's value for phone number based on contents of the | 163 // Set |field| argument's value for phone number based on contents of the |
158 // |profile|. | 164 // |profile|. |
159 void FillPhoneNumberField(const AutoFillProfile* profile, | 165 void FillPhoneNumberField(const AutoFillProfile* profile, |
160 webkit_glue::FormField* field); | 166 webkit_glue::FormField* field); |
161 | 167 |
162 // Parses the forms using heuristic matching and querying the AutoFill server. | 168 // Parses the forms using heuristic matching and querying the AutoFill server. |
163 void ParseForms(const std::vector<webkit_glue::FormData>& forms); | 169 void ParseForms(const std::vector<webkit_glue::FormData>& forms); |
164 | 170 |
165 // The following function is meant to be called from unit-test only. | 171 // Uses existing personal data to determine possible field types for the |
166 void set_disable_download_manager_requests(bool value) { | 172 // |upload_form_structure_|. |
167 disable_download_manager_requests_ = value; | 173 void DeterminePossibleFieldTypesForUpload(); |
168 } | |
169 | 174 |
170 // The TabContents hosting this AutoFillManager. | 175 // The TabContents hosting this AutoFillManager. |
171 // Weak reference. | 176 // Weak reference. |
172 // May not be NULL. | 177 // May not be NULL. |
173 TabContents* tab_contents_; | 178 TabContents* tab_contents_; |
174 | 179 |
175 // The personal data manager, used to save and load personal data to/from the | 180 // The personal data manager, used to save and load personal data to/from the |
176 // web database. This is overridden by the AutoFillManagerTest. | 181 // web database. This is overridden by the AutoFillManagerTest. |
177 // Weak reference. | 182 // Weak reference. |
178 // May be NULL. NULL indicates OTR. | 183 // May be NULL. NULL indicates OTR. |
179 PersonalDataManager* personal_data_; | 184 PersonalDataManager* personal_data_; |
180 | 185 |
181 std::list<std::string> autofilled_forms_signatures_; | 186 std::list<std::string> autofilled_forms_signatures_; |
182 // Handles queries and uploads to AutoFill servers. | 187 // Handles queries and uploads to AutoFill servers. |
183 AutoFillDownloadManager download_manager_; | 188 AutoFillDownloadManager download_manager_; |
184 | 189 |
185 // Should be set to true in AutoFillManagerTest and other tests, false in | 190 // Should be set to true in AutoFillManagerTest and other tests, false in |
186 // AutoFillDownloadManagerTest and in non-test environment. Is false by | 191 // AutoFillDownloadManagerTest and in non-test environment. Is false by |
187 // default. | 192 // default for the public constructor, and true by default for the test-only |
| 193 // constructors. |
188 bool disable_download_manager_requests_; | 194 bool disable_download_manager_requests_; |
189 | 195 |
| 196 // Function pointers for logging UMA metrics. Overridden by metrics tests. |
| 197 autofill_metrics::LogServerQueryMetricFn log_server_query_metric_; |
| 198 autofill_metrics::LogQualityMetricFn log_quality_metric_; |
| 199 |
190 // Our copy of the form data. | 200 // Our copy of the form data. |
191 ScopedVector<FormStructure> form_structures_; | 201 ScopedVector<FormStructure> form_structures_; |
192 | 202 |
193 // The form data the user has submitted. | 203 // The form data the user has submitted. |
194 scoped_ptr<FormStructure> upload_form_structure_; | 204 scoped_ptr<FormStructure> upload_form_structure_; |
195 | 205 |
196 // The InfoBar that asks for permission to store credit card information. | 206 // The InfoBar that asks for permission to store credit card information. |
197 // Deletes itself when closed. | 207 // Deletes itself when closed. |
198 AutoFillCCInfoBarDelegate* cc_infobar_; | 208 AutoFillCCInfoBarDelegate* cc_infobar_; |
199 | 209 |
200 // GUID to ID mapping. We keep two maps to convert back and forth. | 210 // GUID to ID mapping. We keep two maps to convert back and forth. |
201 std::map<std::string, int> guid_id_map_; | 211 std::map<std::string, int> guid_id_map_; |
202 std::map<int, std::string> id_guid_map_; | 212 std::map<int, std::string> id_guid_map_; |
203 | 213 |
204 friend class FormStructureBrowserTest; | 214 friend class FormStructureBrowserTest; |
205 friend class TestAutoFillManager; | 215 friend class TestAutoFillManager; |
206 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillCreditCardForm); | 216 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillCreditCardForm); |
207 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressForm); | 217 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressForm); |
208 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressAndCreditCardForm); | 218 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressAndCreditCardForm); |
209 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAutoFilledForm); | 219 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAutoFilledForm); |
210 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillPhoneNumber); | 220 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillPhoneNumber); |
211 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesRemoveField); | 221 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesRemoveField); |
212 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesAddField); | 222 FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesAddField); |
213 | 223 |
214 DISALLOW_COPY_AND_ASSIGN(AutoFillManager); | 224 DISALLOW_COPY_AND_ASSIGN(AutoFillManager); |
215 }; | 225 }; |
216 | 226 |
217 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 227 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
OLD | NEW |