| 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 #include "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return false; | 185 return false; |
| 186 | 186 |
| 187 // Obtain the XML structure as a string. | 187 // Obtain the XML structure as a string. |
| 188 *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 188 *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
| 189 *encoded_xml += autofil_request_xml.Str().c_str(); | 189 *encoded_xml += autofil_request_xml.Str().c_str(); |
| 190 | 190 |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 void FormStructure::ParseQueryResponse(const std::string& response_xml, | 195 void FormStructure::ParseQueryResponse( |
| 196 const std::vector<FormStructure*>& forms, | 196 const std::string& response_xml, |
| 197 UploadRequired* upload_required) { | 197 const std::vector<FormStructure*>& forms, |
| 198 autofill_metrics::LogServerQueryMetric( | 198 UploadRequired* upload_required, |
| 199 autofill_metrics::QUERY_RESPONSE_RECEIVED); | 199 autofill_metrics::LogServerQueryMetricFn log_server_query_metric) { |
| 200 log_server_query_metric(autofill_metrics::QUERY_RESPONSE_RECEIVED); |
| 200 | 201 |
| 201 // Parse the field types from the server response to the query. | 202 // Parse the field types from the server response to the query. |
| 202 std::vector<AutoFillFieldType> field_types; | 203 std::vector<AutoFillFieldType> field_types; |
| 203 AutoFillQueryXmlParser parse_handler(&field_types, upload_required); | 204 AutoFillQueryXmlParser parse_handler(&field_types, upload_required); |
| 204 buzz::XmlParser parser(&parse_handler); | 205 buzz::XmlParser parser(&parse_handler); |
| 205 parser.Parse(response_xml.c_str(), response_xml.length(), true); | 206 parser.Parse(response_xml.c_str(), response_xml.length(), true); |
| 206 if (!parse_handler.succeeded()) | 207 if (!parse_handler.succeeded()) |
| 207 return; | 208 return; |
| 208 | 209 |
| 209 autofill_metrics::LogServerQueryMetric( | 210 log_server_query_metric(autofill_metrics::QUERY_RESPONSE_PARSED); |
| 210 autofill_metrics::QUERY_RESPONSE_PARSED); | |
| 211 | 211 |
| 212 bool heuristics_detected_fillable_field = false; | 212 bool heuristics_detected_fillable_field = false; |
| 213 bool query_response_overrode_heuristics = false; | 213 bool query_response_overrode_heuristics = false; |
| 214 | 214 |
| 215 // Copy the field types into the actual form. | 215 // Copy the field types into the actual form. |
| 216 std::vector<AutoFillFieldType>::iterator current_type = field_types.begin(); | 216 std::vector<AutoFillFieldType>::iterator current_type = field_types.begin(); |
| 217 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 217 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); |
| 218 iter != forms.end(); ++iter) { | 218 iter != forms.end(); ++iter) { |
| 219 FormStructure* form = *iter; | 219 FormStructure* form = *iter; |
| 220 | 220 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 autofill_metrics::ServerQueryMetricType metric_type; | 253 autofill_metrics::ServerQueryMetricType metric_type; |
| 254 if (query_response_overrode_heuristics) { | 254 if (query_response_overrode_heuristics) { |
| 255 if (heuristics_detected_fillable_field) { | 255 if (heuristics_detected_fillable_field) { |
| 256 metric_type = autofill_metrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; | 256 metric_type = autofill_metrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; |
| 257 } else { | 257 } else { |
| 258 metric_type = autofill_metrics::QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS; | 258 metric_type = autofill_metrics::QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS; |
| 259 } | 259 } |
| 260 } else { | 260 } else { |
| 261 metric_type = autofill_metrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS; | 261 metric_type = autofill_metrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS; |
| 262 } | 262 } |
| 263 autofill_metrics::LogServerQueryMetric(metric_type); | 263 log_server_query_metric(metric_type); |
| 264 } | 264 } |
| 265 | 265 |
| 266 std::string FormStructure::FormSignature() const { | 266 std::string FormStructure::FormSignature() const { |
| 267 std::string form_string = target_url_.scheme() + | 267 std::string form_string = target_url_.scheme() + |
| 268 "://" + | 268 "://" + |
| 269 target_url_.host() + | 269 target_url_.host() + |
| 270 "&" + | 270 "&" + |
| 271 UTF16ToUTF8(form_name_) + | 271 UTF16ToUTF8(form_name_) + |
| 272 form_signature_field_names_; | 272 form_signature_field_names_; |
| 273 | 273 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } else { | 425 } else { |
| 426 buzz::XmlElement *field_element = new buzz::XmlElement( | 426 buzz::XmlElement *field_element = new buzz::XmlElement( |
| 427 buzz::QName(kXMLElementField)); | 427 buzz::QName(kXMLElementField)); |
| 428 field_element->SetAttr(buzz::QName(kAttributeSignature), | 428 field_element->SetAttr(buzz::QName(kAttributeSignature), |
| 429 field->FieldSignature()); | 429 field->FieldSignature()); |
| 430 encompassing_xml_element->AddElement(field_element); | 430 encompassing_xml_element->AddElement(field_element); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 return true; | 433 return true; |
| 434 } | 434 } |
| OLD | NEW |