Commit fef3d83e authored by mathp's avatar mathp Committed by Commit bot

[Autofill] Control using Variations the sending of Autofill field metadata

We default most tests to having the trial enabled because that is the expected way forward. Nevertheless we put the trial so we can control rollout or kill it after the fact.

BUG=488602
TBR=asvitkine
TEST=FormStructureTest*,AutofillServerTest*

Review URL: https://codereview.chromium.org/1141133003

Cr-Commit-Position: refs/heads/master@{#330601}
parent 7923e436
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
......@@ -11,6 +12,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/autofill_profile.h"
......@@ -93,6 +95,12 @@ class WindowedNetworkObserver : public net::TestURLFetcher::DelegateForTests {
class AutofillServerTest : public InProcessBrowserTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
// Enable finch experiment for sending field metadata.
command_line->AppendSwitchASCII(
::switches::kForceFieldTrials, "AutofillFieldMetadata/Enabled/");
}
void SetUpOnMainThread() override {
// Disable interactions with the Mac Keychain.
PrefService* pref_service = browser()->profile()->GetPrefs();
......
......@@ -4,6 +4,7 @@ include_rules = [
"+components/signin/core/browser",
"+components/signin/core/common",
"+components/sync_driver",
"+components/variations",
"+components/webdata/common",
"+components/webdata_services",
"+crypto/random.h",
......
......@@ -11,6 +11,7 @@
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
......@@ -65,6 +66,13 @@ const char kIgnorePatternInFieldName[] = "\\d{5,}+";
// mismatches exceeds this threshold.
const int kNumberOfMismatchesThreshold = 3;
// Returns whether sending autofill field metadata to the server is enabled.
bool IsAutofillFieldMetadataEnabled() {
const std::string group_name =
base::FieldTrialList::FindFullName("AutofillFieldMetadata");
return StartsWithASCII(group_name, "Enabled", true);
}
// Helper for |EncodeUploadRequest()| that creates a bit field corresponding to
// |available_field_types| and returns the hex representation as a string.
std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) {
......@@ -111,12 +119,14 @@ buzz::XmlElement* EncodeFieldForQuery(const AutofillField& field,
buzz::QName(kXMLElementField));
field_element->SetAttr(buzz::QName(kAttributeSignature),
field.FieldSignature());
if (!field.name.empty()) {
field_element->SetAttr(buzz::QName(kAttributeName),
base::UTF16ToUTF8(field.name));
if (IsAutofillFieldMetadataEnabled()) {
if (!field.name.empty()) {
field_element->SetAttr(buzz::QName(kAttributeName),
base::UTF16ToUTF8(field.name));
}
field_element->SetAttr(buzz::QName(kAttributeControlType),
field.form_control_type);
}
field_element->SetAttr(buzz::QName(kAttributeControlType),
field.form_control_type);
parent->AddElement(field_element);
return field_element;
}
......@@ -136,12 +146,14 @@ void EncodeFieldForUpload(const AutofillField& field,
// We use the same field elements as the query and add a few more below.
buzz::XmlElement* field_element = EncodeFieldForQuery(field, parent);
if (!field.autocomplete_attribute.empty()) {
field_element->SetAttr(buzz::QName(kAttributeAutocomplete),
field.autocomplete_attribute);
if (IsAutofillFieldMetadataEnabled()) {
if (!field.autocomplete_attribute.empty()) {
field_element->SetAttr(buzz::QName(kAttributeAutocomplete),
field.autocomplete_attribute);
}
field_element->SetAttr(buzz::QName(kAttributeAutofillType),
base::IntToString(*field_type));
}
field_element->SetAttr(buzz::QName(kAttributeAutofillType),
base::IntToString(*field_type));
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment