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