Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: components/autofill/core/browser/form_structure.cc

Issue 1141133003: [Autofill] Control using Variations the sending of Autofill field metadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/metrics/field_trial.h"
14 #include "base/sha1.h" 15 #include "base/sha1.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "components/autofill/core/browser/autofill_metrics.h" 21 #include "components/autofill/core/browser/autofill_metrics.h"
21 #include "components/autofill/core/browser/autofill_type.h" 22 #include "components/autofill/core/browser/autofill_type.h"
22 #include "components/autofill/core/browser/autofill_xml_parser.h" 23 #include "components/autofill/core/browser/autofill_xml_parser.h"
23 #include "components/autofill/core/browser/field_types.h" 24 #include "components/autofill/core/browser/field_types.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char kBillingMode[] = "billing"; 59 const char kBillingMode[] = "billing";
59 const char kShippingMode[] = "shipping"; 60 const char kShippingMode[] = "shipping";
60 61
61 // Strip away >= 5 consecutive digits. 62 // Strip away >= 5 consecutive digits.
62 const char kIgnorePatternInFieldName[] = "\\d{5,}+"; 63 const char kIgnorePatternInFieldName[] = "\\d{5,}+";
63 64
64 // A form is considered to have a high prediction mismatch rate if the number of 65 // A form is considered to have a high prediction mismatch rate if the number of
65 // mismatches exceeds this threshold. 66 // mismatches exceeds this threshold.
66 const int kNumberOfMismatchesThreshold = 3; 67 const int kNumberOfMismatchesThreshold = 3;
67 68
69 // Returns whether sending autofill field metadata to the server is enabled.
70 bool IsAutofillFieldMetadataEnabled() {
71 const std::string group_name =
72 base::FieldTrialList::FindFullName("AutofillFieldMetadata");
73 return StartsWithASCII(group_name, "Enabled", true);
74 }
75
68 // Helper for |EncodeUploadRequest()| that creates a bit field corresponding to 76 // Helper for |EncodeUploadRequest()| that creates a bit field corresponding to
69 // |available_field_types| and returns the hex representation as a string. 77 // |available_field_types| and returns the hex representation as a string.
70 std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) { 78 std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) {
71 // There are |MAX_VALID_FIELD_TYPE| different field types and 8 bits per byte, 79 // There are |MAX_VALID_FIELD_TYPE| different field types and 8 bits per byte,
72 // so we need ceil(MAX_VALID_FIELD_TYPE / 8) bytes to encode the bit field. 80 // so we need ceil(MAX_VALID_FIELD_TYPE / 8) bytes to encode the bit field.
73 const size_t kNumBytes = (MAX_VALID_FIELD_TYPE + 0x7) / 8; 81 const size_t kNumBytes = (MAX_VALID_FIELD_TYPE + 0x7) / 8;
74 82
75 // Pack the types in |available_field_types| into |bit_field|. 83 // Pack the types in |available_field_types| into |bit_field|.
76 std::vector<uint8> bit_field(kNumBytes, 0); 84 std::vector<uint8> bit_field(kNumBytes, 0);
77 for (ServerFieldTypeSet::const_iterator field_type = 85 for (ServerFieldTypeSet::const_iterator field_type =
(...skipping 26 matching lines...) Expand all
104 112
105 // Helper for |EncodeFormRequest()| and |EncodeFieldForUpload| that returns an 113 // Helper for |EncodeFormRequest()| and |EncodeFieldForUpload| that returns an
106 // XmlElement for the given field in query xml, and also add it to the parent 114 // XmlElement for the given field in query xml, and also add it to the parent
107 // XmlElement. 115 // XmlElement.
108 buzz::XmlElement* EncodeFieldForQuery(const AutofillField& field, 116 buzz::XmlElement* EncodeFieldForQuery(const AutofillField& field,
109 buzz::XmlElement* parent) { 117 buzz::XmlElement* parent) {
110 buzz::XmlElement* field_element = new buzz::XmlElement( 118 buzz::XmlElement* field_element = new buzz::XmlElement(
111 buzz::QName(kXMLElementField)); 119 buzz::QName(kXMLElementField));
112 field_element->SetAttr(buzz::QName(kAttributeSignature), 120 field_element->SetAttr(buzz::QName(kAttributeSignature),
113 field.FieldSignature()); 121 field.FieldSignature());
114 if (!field.name.empty()) { 122 if (IsAutofillFieldMetadataEnabled()) {
115 field_element->SetAttr(buzz::QName(kAttributeName), 123 if (!field.name.empty()) {
116 base::UTF16ToUTF8(field.name)); 124 field_element->SetAttr(buzz::QName(kAttributeName),
125 base::UTF16ToUTF8(field.name));
126 }
127 field_element->SetAttr(buzz::QName(kAttributeControlType),
128 field.form_control_type);
117 } 129 }
118 field_element->SetAttr(buzz::QName(kAttributeControlType),
119 field.form_control_type);
120 parent->AddElement(field_element); 130 parent->AddElement(field_element);
121 return field_element; 131 return field_element;
122 } 132 }
123 133
124 // Helper for |EncodeFormRequest()| that creates XmlElements for the given field 134 // Helper for |EncodeFormRequest()| that creates XmlElements for the given field
125 // in upload xml, and also add them to the parent XmlElement. 135 // in upload xml, and also add them to the parent XmlElement.
126 void EncodeFieldForUpload(const AutofillField& field, 136 void EncodeFieldForUpload(const AutofillField& field,
127 buzz::XmlElement* parent) { 137 buzz::XmlElement* parent) {
128 // Don't upload checkable fields. 138 // Don't upload checkable fields.
129 if (field.is_checkable) 139 if (field.is_checkable)
130 return; 140 return;
131 141
132 ServerFieldTypeSet types = field.possible_types(); 142 ServerFieldTypeSet types = field.possible_types();
133 // |types| could be empty in unit-tests only. 143 // |types| could be empty in unit-tests only.
134 for (ServerFieldTypeSet::iterator field_type = types.begin(); 144 for (ServerFieldTypeSet::iterator field_type = types.begin();
135 field_type != types.end(); ++field_type) { 145 field_type != types.end(); ++field_type) {
136 // We use the same field elements as the query and add a few more below. 146 // We use the same field elements as the query and add a few more below.
137 buzz::XmlElement* field_element = EncodeFieldForQuery(field, parent); 147 buzz::XmlElement* field_element = EncodeFieldForQuery(field, parent);
138 148
139 if (!field.autocomplete_attribute.empty()) { 149 if (IsAutofillFieldMetadataEnabled()) {
140 field_element->SetAttr(buzz::QName(kAttributeAutocomplete), 150 if (!field.autocomplete_attribute.empty()) {
141 field.autocomplete_attribute); 151 field_element->SetAttr(buzz::QName(kAttributeAutocomplete),
152 field.autocomplete_attribute);
153 }
154 field_element->SetAttr(buzz::QName(kAttributeAutofillType),
155 base::IntToString(*field_type));
142 } 156 }
143 field_element->SetAttr(buzz::QName(kAttributeAutofillType),
144 base::IntToString(*field_type));
145 } 157 }
146 } 158 }
147 159
148 // Helper for |EncodeFormRequest()| that creates XmlElements for the given field 160 // Helper for |EncodeFormRequest()| that creates XmlElements for the given field
149 // in field assignments xml, and also add them to the parent XmlElement. 161 // in field assignments xml, and also add them to the parent XmlElement.
150 void EncodeFieldForFieldAssignments(const AutofillField& field, 162 void EncodeFieldForFieldAssignments(const AutofillField& field,
151 buzz::XmlElement* parent) { 163 buzz::XmlElement* parent) {
152 ServerFieldTypeSet types = field.possible_types(); 164 ServerFieldTypeSet types = field.possible_types();
153 for (ServerFieldTypeSet::iterator field_type = types.begin(); 165 for (ServerFieldTypeSet::iterator field_type = types.begin();
154 field_type != types.end(); ++field_type) { 166 field_type != types.end(); ++field_type) {
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 for (AutofillField* field : fields_) { 1305 for (AutofillField* field : fields_) {
1294 FieldTypeGroup field_type_group = field->Type().group(); 1306 FieldTypeGroup field_type_group = field->Type().group();
1295 if (field_type_group == CREDIT_CARD) 1307 if (field_type_group == CREDIT_CARD)
1296 field->set_section(field->section() + "-cc"); 1308 field->set_section(field->section() + "-cc");
1297 else 1309 else
1298 field->set_section(field->section() + "-default"); 1310 field->set_section(field->section() + "-default");
1299 } 1311 }
1300 } 1312 }
1301 1313
1302 } // namespace autofill 1314 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/DEPS ('k') | components/autofill/core/browser/form_structure_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698