Commit 1c436858 authored by sebsg's avatar sebsg Committed by Commit Bot

[AF] More efficient dynamic form fill on select options change.

The previous implementation was finding the form and field of the
select element that was modified for each option added or removed.

Since this can happen several times in a row it was not efficient.

This search now happens after all the add/remove have been debounced.

Bug: 832077
Change-Id: Icf28910459163a4d92eca96e2e4adad65a147cf7
Reviewed-on: https://chromium-review.googlesource.com/1015322
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551719}
parent 4c934ee4
......@@ -81,8 +81,8 @@ namespace autofill {
namespace {
// Time to wait, in ms, after a select option change before taking action to
// wait for other option changes.
// Time to wait, in ms, o ensure that only a single select change will be acted
// upon, instead of multiple in close succession (debounce time).
size_t kWaitTimeForSelectOptionsChangesMs = 50;
// Whether the "single click" autofill feature is enabled, through command-line
......@@ -803,31 +803,34 @@ void AutofillAgent::SelectFieldOptionsChanged(
if (!was_last_action_fill_ || element_.IsNull())
return;
// Since a change of a select options often come in batches, use a timer
// to wait for other changes. Stop the timer if it was already running. It
// will be started again for this change.
if (on_select_update_timer_.IsRunning())
on_select_update_timer_.AbandonAndStop();
// Start the timer to notify the driver that the select field was updated
// after the options have finished changing,
on_select_update_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kWaitTimeForSelectOptionsChangesMs),
base::BindRepeating(&AutofillAgent::SelectWasUpdated,
weak_ptr_factory_.GetWeakPtr(), element));
}
void AutofillAgent::SelectWasUpdated(
const blink::WebFormControlElement& element) {
// Look for the form and field associated with the select element. If they are
// found, notify the driver that the the form was modified dynamically.
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form,
&field) &&
!field.option_values.empty()) {
// Since a change of a select options often come in batches, start a timer
// to wait for other changed. Restart the timer if it was already running.
if (on_select_update_timer_.IsRunning()) {
on_select_update_timer_.AbandonAndStop();
}
// After the options have finished changing, notify the driver that the
// select field was updated.
on_select_update_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kWaitTimeForSelectOptionsChangesMs),
base::BindRepeating(&AutofillAgent::SelectWasUpdated,
weak_ptr_factory_.GetWeakPtr(), form));
GetAutofillDriver()->SelectFieldOptionsDidChange(form);
}
}
void AutofillAgent::SelectWasUpdated(FormData form) {
GetAutofillDriver()->SelectFieldOptionsDidChange(form);
}
void AutofillAgent::FormControlElementClicked(
const WebFormControlElement& element,
bool was_focused) {
......
......@@ -110,7 +110,7 @@ class AutofillAgent : public content::RenderFrameObserver,
FormTracker* form_tracker_for_testing() { return &form_tracker_; }
void SelectWasUpdated(FormData form);
void SelectWasUpdated(const blink::WebFormControlElement& element);
protected:
// blink::WebAutofillClient:
......
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