Commit f58ae1e7 authored by Roger McFarlane's avatar Roger McFarlane Committed by Commit Bot

[autofill] Control autofill server communciation via Finch

This CL adds a feature flag to enable/disable communication with the
autofill server. It further adds a feature parameter by which the
autofill server URL can be controlled.

This functionality is to support:

  - routing a % of users to exercise a staging server environment
    to ensure better server validation before rollout.

  - turning off or rerouting autofill server traffic from the test
    bots.

By default, autofill server communication is enabled and will send
traffic to the existing autofill server.

Bug: 874553, 866940
Change-Id: I8a425c76d483731fce9ef0ef8e10ac0cc145cb1d
Reviewed-on: https://chromium-review.googlesource.com/1176287
Commit-Queue: Roger McFarlane <rogerm@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584076}
parent bef8e43b
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -75,6 +76,9 @@ const char kDefaultAutofillServerURL[] = ...@@ -75,6 +76,9 @@ const char kDefaultAutofillServerURL[] =
// Returns the base URL for the autofill server. // Returns the base URL for the autofill server.
GURL GetAutofillServerURL() { GURL GetAutofillServerURL() {
// If a valid autofill server URL is specified on the command line, then the
// AutofillDownlaodManager will use it, and assume that server communication
// is enabled.
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kAutofillServerURL)) { if (command_line.HasSwitch(switches::kAutofillServerURL)) {
...@@ -82,13 +86,35 @@ GURL GetAutofillServerURL() { ...@@ -82,13 +86,35 @@ GURL GetAutofillServerURL() {
if (url.is_valid()) if (url.is_valid())
return url; return url;
LOG(ERROR) << "Invalid URL given for --" << switches::kAutofillServerURL LOG(ERROR) << "Invalid URL value for --" << switches::kAutofillServerURL
<< ". Using default value."; << ": "
<< command_line.GetSwitchValueASCII(
switches::kAutofillServerURL);
} }
GURL default_url(kDefaultAutofillServerURL); // If communication is disabled, leave the autofill server URL unset.
DCHECK(default_url.is_valid()); if (!base::FeatureList::IsEnabled(features::kAutofillServerCommunication))
return default_url; return GURL();
// Server communication is enabled. If there's an autofill server url param
// use it, otherwise use the default.
const std::string autofill_server_url_str =
base::FeatureParam<std::string>(&features::kAutofillServerCommunication,
switches::kAutofillServerURL,
kDefaultAutofillServerURL)
.Get();
GURL autofill_server_url(autofill_server_url_str);
if (!autofill_server_url.is_valid()) {
LOG(ERROR) << "Invalid URL param for "
<< features::kAutofillServerCommunication.name << "/"
<< switches::kAutofillServerURL << ": "
<< autofill_server_url_str;
return GURL();
}
return autofill_server_url;
} }
// Helper to log the HTTP |response_code| received for |request_type| to UMA. // Helper to log the HTTP |response_code| received for |request_type| to UMA.
...@@ -298,6 +324,9 @@ AutofillDownloadManager::~AutofillDownloadManager() = default; ...@@ -298,6 +324,9 @@ AutofillDownloadManager::~AutofillDownloadManager() = default;
bool AutofillDownloadManager::StartQueryRequest( bool AutofillDownloadManager::StartQueryRequest(
const std::vector<FormStructure*>& forms) { const std::vector<FormStructure*>& forms) {
if (!IsEnabled())
return false;
// Do not send the request if it contains more fields than the server can // Do not send the request if it contains more fields than the server can
// accept. // accept.
if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest) if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest)
...@@ -339,6 +368,9 @@ bool AutofillDownloadManager::StartUploadRequest( ...@@ -339,6 +368,9 @@ bool AutofillDownloadManager::StartUploadRequest(
const ServerFieldTypeSet& available_field_types, const ServerFieldTypeSet& available_field_types,
const std::string& login_form_signature, const std::string& login_form_signature,
bool observed_submission) { bool observed_submission) {
if (!IsEnabled())
return false;
AutofillUploadContents upload; AutofillUploadContents upload;
if (!form.EncodeUploadRequest(available_field_types, form_was_autofilled, if (!form.EncodeUploadRequest(available_field_types, form_was_autofilled,
login_form_signature, observed_submission, login_form_signature, observed_submission,
......
...@@ -88,6 +88,9 @@ class AutofillDownloadManager { ...@@ -88,6 +88,9 @@ class AutofillDownloadManager {
const std::string& login_form_signature, const std::string& login_form_signature,
bool observed_submission); bool observed_submission);
// Returns true if the autofill server communication is enabled.
bool IsEnabled() const { return autofill_server_url_.is_valid(); }
private: private:
friend class AutofillDownloadManagerTest; friend class AutofillDownloadManagerTest;
FRIEND_TEST_ALL_PREFIXES(AutofillDownloadManagerTest, QueryAndUploadTest); FRIEND_TEST_ALL_PREFIXES(AutofillDownloadManagerTest, QueryAndUploadTest);
...@@ -144,7 +147,7 @@ class AutofillDownloadManager { ...@@ -144,7 +147,7 @@ class AutofillDownloadManager {
// The autofill server URL root: scheme://host[:port]/path excluding the // The autofill server URL root: scheme://host[:port]/path excluding the
// final path component for the request and the query params. // final path component for the request and the query params.
GURL autofill_server_url_; const GURL autofill_server_url_;
// Loaders used for the processing the requests. Invalidated after completion. // Loaders used for the processing the requests. Invalidated after completion.
std::list<std::unique_ptr<network::SimpleURLLoader>> url_loaders_; std::list<std::unique_ptr<network::SimpleURLLoader>> url_loaders_;
......
...@@ -108,6 +108,15 @@ const base::Feature kAutofillSendOnlyCountryInGetUploadDetails{ ...@@ -108,6 +108,15 @@ const base::Feature kAutofillSendOnlyCountryInGetUploadDetails{
"AutofillSendOnlyCountryInGetUploadDetails", "AutofillSendOnlyCountryInGetUploadDetails",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Enables or Disables (mostly for hermetic testing) autofill server
// communication. The URL of the autofill server can further be controlled via
// the autofill-server-url param. The given URL should specify the complete
// autofill server API url up to the parent "directory" of the "query" and
// "upload" resources.
// i.e., https://other.autofill.server:port/tbproxy/af/
const base::Feature kAutofillServerCommunication{
"kAutofillServerCommunication", base::FEATURE_ENABLED_BY_DEFAULT};
// Controls whether we show warnings in the Dev console for misused autocomplete // Controls whether we show warnings in the Dev console for misused autocomplete
// types. // types.
const base::Feature kAutofillShowAutocompleteConsoleWarnings{ const base::Feature kAutofillShowAutocompleteConsoleWarnings{
......
...@@ -28,6 +28,7 @@ extern const base::Feature kAutofillRestrictUnownedFieldsToFormlessCheckout; ...@@ -28,6 +28,7 @@ extern const base::Feature kAutofillRestrictUnownedFieldsToFormlessCheckout;
extern const base::Feature kAutofillSaveCardSignInAfterLocalSave; extern const base::Feature kAutofillSaveCardSignInAfterLocalSave;
extern const base::Feature kAutofillSendExperimentIdsInPaymentsRPCs; extern const base::Feature kAutofillSendExperimentIdsInPaymentsRPCs;
extern const base::Feature kAutofillSendOnlyCountryInGetUploadDetails; extern const base::Feature kAutofillSendOnlyCountryInGetUploadDetails;
extern const base::Feature kAutofillServerCommunication;
extern const base::Feature kAutofillShowAllSuggestionsOnPrefilledForms; extern const base::Feature kAutofillShowAllSuggestionsOnPrefilledForms;
extern const base::Feature kAutofillShowAutocompleteConsoleWarnings; extern const base::Feature kAutofillShowAutocompleteConsoleWarnings;
extern const base::Feature kAutofillShowTypePredictions; extern const base::Feature kAutofillShowTypePredictions;
...@@ -40,6 +41,7 @@ extern const base::Feature kAutomaticPasswordGeneration; ...@@ -40,6 +41,7 @@ extern const base::Feature kAutomaticPasswordGeneration;
extern const base::Feature kSingleClickAutofill; extern const base::Feature kSingleClickAutofill;
extern const base::Feature kAutofillPrefilledFields; extern const base::Feature kAutofillPrefilledFields;
extern const base::Feature kAutofillRationalizeRepeatedServerPredictions; extern const base::Feature kAutofillRationalizeRepeatedServerPredictions;
} // namespace features } // namespace features
} // namespace autofill } // namespace autofill
......
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