Commit 85424c92 authored by Michael Bai's avatar Michael Bai Committed by Chromium LUCI CQ

Autofill: Move OnFormsParsed to AutofillHandler.

The query starts from AutofillHandler, there is no functionality
change since WV/WL doesn't instantiate DownloadManager.

Bug: 1151542
Change-Id: Ifccce22515ae2faef48fed6445a61bd415d51e7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570307
Commit-Queue: Michael Bai <michaelbai@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833489}
parent 2df57937
......@@ -74,12 +74,42 @@ std::string GetAPIKeyForUrl(version_info::Channel channel) {
using base::TimeTicks;
// static
void AutofillHandler::LogAutofillTypePredictionsAvailable(
LogManager* log_manager,
const std::vector<FormStructure*>& forms) {
if (VLOG_IS_ON(1)) {
VLOG(1) << "Parsed forms:";
for (FormStructure* form : forms)
VLOG(1) << *form;
}
if (!log_manager || !log_manager->IsLoggingActive())
return;
LogBuffer buffer;
for (FormStructure* form : forms)
buffer << *form;
log_manager->Log() << LoggingScope::kParsing << LogMessage::kParsedForms
<< std::move(buffer);
}
// static
bool AutofillHandler::IsRichQueryEnabled(version_info::Channel channel) {
return base::FeatureList::IsEnabled(features::kAutofillRichMetadataQueries) &&
channel != version_info::Channel::STABLE &&
channel != version_info::Channel::BETA;
}
AutofillHandler::AutofillHandler(
AutofillDriver* driver,
LogManager* log_manager,
AutofillDownloadManagerState enable_download_manager,
version_info::Channel channel)
: driver_(driver), log_manager_(log_manager) {
: driver_(driver),
log_manager_(log_manager),
is_rich_query_enabled_(IsRichQueryEnabled(channel)) {
if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {
download_manager_ = std::make_unique<AutofillDownloadManager>(
driver, this, GetAPIKeyForUrl(channel), log_manager);
......@@ -152,6 +182,55 @@ void AutofillHandler::OnFormsSeen(const std::vector<FormData>& forms) {
OnFormsParsed(new_forms);
}
void AutofillHandler::OnFormsParsed(const std::vector<const FormData*>& forms) {
DCHECK(!forms.empty());
OnBeforeProcessParsedForms();
driver()->HandleParsedForms(forms);
std::vector<FormStructure*> non_queryable_forms;
std::vector<FormStructure*> queryable_forms;
std::set<FormType> form_types;
for (const FormData* form : forms) {
FormStructure* form_structure =
FindCachedFormByRendererId(form->unique_renderer_id);
if (!form_structure) {
NOTREACHED();
continue;
}
std::set<FormType> current_form_types = form_structure->GetFormTypes();
form_types.insert(current_form_types.begin(), current_form_types.end());
// Configure the query encoding for this form and add it to the appropriate
// collection of forms: queryable vs non-queryable.
form_structure->set_is_rich_query_enabled(is_rich_query_enabled_);
if (form_structure->ShouldBeQueried())
queryable_forms.push_back(form_structure);
else
non_queryable_forms.push_back(form_structure);
OnFormProcessed(*form, *form_structure);
}
if (!queryable_forms.empty() || !non_queryable_forms.empty()) {
OnAfterProcessParsedForms(form_types);
}
// Send the current type predictions to the renderer. For non-queryable forms
// this is all the information about them that will ever be available. The
// queryable forms will be updated once the field type query is complete.
driver()->SendAutofillTypePredictionsToRenderer(non_queryable_forms);
driver()->SendAutofillTypePredictionsToRenderer(queryable_forms);
LogAutofillTypePredictionsAvailable(log_manager_, non_queryable_forms);
LogAutofillTypePredictionsAvailable(log_manager_, queryable_forms);
// Query the server if at least one of the forms was parsed.
if (!queryable_forms.empty() && download_manager()) {
download_manager()->StartQueryRequest(queryable_forms);
}
}
void AutofillHandler::OnTextFieldDidChange(const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box,
......
......@@ -51,6 +51,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
virtual void OnFormParsed() = 0;
};
// Rich queries are enabled by feature flag iff this chrome instance is
// neither on the STABLE nor BETA release channel.
static bool IsRichQueryEnabled(version_info::Channel channel);
// TODO(crbug.com/1151542): Move to anonymous namespace once
// AutofillManager::OnLoadedServerPredictions() moves to AutofillHandler.
static void LogAutofillTypePredictionsAvailable(
LogManager* log_manager,
const std::vector<FormStructure*>& forms);
~AutofillHandler() override;
// Invoked when the value of textfield is changed.
......@@ -166,7 +176,7 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
FormStructure* ParseFormForTest(const FormData& form) {
return ParseForm(form, nullptr);
}
#endif
#endif // UNIT_TEST
protected:
using FormInteractionsUkmLoggerFactoryCallback = base::RepeatingCallback<
......@@ -216,8 +226,17 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
// form_structures.
virtual bool ShouldParseForms(const std::vector<FormData>& forms) = 0;
// Invoked when forms from OnFormsSeen() has been parsed to |form_structures|.
virtual void OnFormsParsed(const std::vector<const FormData*>& forms) = 0;
// Invoked before parsing the forms.
virtual void OnBeforeProcessParsedForms() = 0;
// Invoked when the given |form| has been processed to the given
// |form_structure|.
virtual void OnFormProcessed(const FormData& form,
const FormStructure& form_structure) = 0;
// Invoked after all forms have been processed, |form_types| is a set of
// FormType found.
virtual void OnAfterProcessParsedForms(
const std::set<FormType>& form_types) = 0;
// Returns the number of FormStructures with the given |form_signature| and
// appends them to |form_structures|. Runs in linear time.
......@@ -245,11 +264,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
return &form_structures_;
}
#ifdef UNIT_TEST
// Exposed for testing.
void set_download_manager(AutofillDownloadManager* manager) {
download_manager_.reset(manager);
}
// Exposed for testing.
bool is_rich_query_enabled() const { return is_rich_query_enabled_; }
#endif // UNIT_TEST
private:
// AutofillDownloadManager::Observer:
void OnLoadedServerPredictions(
......@@ -259,6 +283,10 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
AutofillDownloadManager::RequestType request_type,
int http_error) override;
// Invoked when forms from OnFormsSeen() have been parsed to
// |form_structures|.
void OnFormsParsed(const std::vector<const FormData*>& forms);
// Provides driver-level context to the shared code of the component. Must
// outlive this object.
AutofillDriver* const driver_;
......@@ -280,6 +308,9 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
std::unique_ptr<AutofillMetrics::FormInteractionsUkmLogger>
form_interactions_ukm_logger_;
// Tracks whether or not rich query encoding is enabled for this client.
const bool is_rich_query_enabled_ = false;
// Will be not null only for |SaveCardBubbleViewsFullFormBrowserTest|.
ObserverForTest* observer_for_testing_ = nullptr;
......
......@@ -66,8 +66,13 @@ class AutofillHandlerProxy : public AutofillHandler {
bool ShouldParseForms(const std::vector<FormData>& forms) override;
void OnFormsParsed(
const std::vector<const FormData*>& form_structures) override {}
void OnBeforeProcessParsedForms() override {}
void OnFormProcessed(const FormData& form,
const FormStructure& form_structure) override {}
void OnAfterProcessParsedForms(
const std::set<FormType>& form_types) override {}
private:
AutofillProvider* provider_;
......
......@@ -244,10 +244,6 @@ class AutofillManager : public AutofillHandler,
// to be uploadable. Exposed for testing.
bool ShouldUploadForm(const FormStructure& form);
// Rich queries are enabled by feature flag iff this chrome instance is
// neither on the STABLE nor BETA release channel.
static bool IsRichQueryEnabled(version_info::Channel channel);
// Returns the last form the autofill manager considered in this frame.
virtual const FormData& last_query_form() const;
......@@ -358,10 +354,10 @@ class AutofillManager : public AutofillHandler,
const FormFieldData& field,
const gfx::RectF& bounding_box) override;
bool ShouldParseForms(const std::vector<FormData>& forms) override;
void OnFormsParsed(const std::vector<const FormData*>& forms) override;
// Exposed for testing.
bool is_rich_query_enabled() const { return is_rich_query_enabled_; }
void OnBeforeProcessParsedForms() override;
void OnFormProcessed(const FormData& form,
const FormStructure& form_structure) override;
void OnAfterProcessParsedForms(const std::set<FormType>& form_types) override;
// Exposed for testing.
FormData* pending_form_data() { return pending_form_data_.get(); }
......@@ -707,9 +703,6 @@ class AutofillManager : public AutofillHandler,
std::map<base::string16, std::unique_ptr<FillingContext>>
filling_context_by_unique_name_;
// Tracks whether or not rich query encoding is enabled for this client.
const bool is_rich_query_enabled_ = false;
// Used to record metrics. This should be set at the beginning of the
// interaction and re-used throughout the context of this manager.
AutofillSyncSigninState sync_state_ = AutofillSyncSigninState::kNumSyncStates;
......
......@@ -360,7 +360,9 @@ class FormStructure {
// - Name for Autofill of first field
base::string16 GetIdentifierForRefill() const;
int developer_engagement_metrics() { return developer_engagement_metrics_; }
int developer_engagement_metrics() const {
return developer_engagement_metrics_;
}
void set_randomized_encoder(std::unique_ptr<RandomizedEncoder> encoder);
......
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