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) { ...@@ -74,12 +74,42 @@ std::string GetAPIKeyForUrl(version_info::Channel channel) {
using base::TimeTicks; 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( AutofillHandler::AutofillHandler(
AutofillDriver* driver, AutofillDriver* driver,
LogManager* log_manager, LogManager* log_manager,
AutofillDownloadManagerState enable_download_manager, AutofillDownloadManagerState enable_download_manager,
version_info::Channel channel) 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) { if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {
download_manager_ = std::make_unique<AutofillDownloadManager>( download_manager_ = std::make_unique<AutofillDownloadManager>(
driver, this, GetAPIKeyForUrl(channel), log_manager); driver, this, GetAPIKeyForUrl(channel), log_manager);
...@@ -152,6 +182,55 @@ void AutofillHandler::OnFormsSeen(const std::vector<FormData>& forms) { ...@@ -152,6 +182,55 @@ void AutofillHandler::OnFormsSeen(const std::vector<FormData>& forms) {
OnFormsParsed(new_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, void AutofillHandler::OnTextFieldDidChange(const FormData& form,
const FormFieldData& field, const FormFieldData& field,
const gfx::RectF& bounding_box, const gfx::RectF& bounding_box,
......
...@@ -51,6 +51,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -51,6 +51,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
virtual void OnFormParsed() = 0; 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; ~AutofillHandler() override;
// Invoked when the value of textfield is changed. // Invoked when the value of textfield is changed.
...@@ -166,7 +176,7 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -166,7 +176,7 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
FormStructure* ParseFormForTest(const FormData& form) { FormStructure* ParseFormForTest(const FormData& form) {
return ParseForm(form, nullptr); return ParseForm(form, nullptr);
} }
#endif #endif // UNIT_TEST
protected: protected:
using FormInteractionsUkmLoggerFactoryCallback = base::RepeatingCallback< using FormInteractionsUkmLoggerFactoryCallback = base::RepeatingCallback<
...@@ -216,8 +226,17 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -216,8 +226,17 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
// form_structures. // form_structures.
virtual bool ShouldParseForms(const std::vector<FormData>& forms) = 0; virtual bool ShouldParseForms(const std::vector<FormData>& forms) = 0;
// Invoked when forms from OnFormsSeen() has been parsed to |form_structures|. // Invoked before parsing the forms.
virtual void OnFormsParsed(const std::vector<const FormData*>& forms) = 0; 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 // Returns the number of FormStructures with the given |form_signature| and
// appends them to |form_structures|. Runs in linear time. // appends them to |form_structures|. Runs in linear time.
...@@ -245,11 +264,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -245,11 +264,16 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
return &form_structures_; return &form_structures_;
} }
#ifdef UNIT_TEST
// Exposed for testing. // Exposed for testing.
void set_download_manager(AutofillDownloadManager* manager) { void set_download_manager(AutofillDownloadManager* manager) {
download_manager_.reset(manager); download_manager_.reset(manager);
} }
// Exposed for testing.
bool is_rich_query_enabled() const { return is_rich_query_enabled_; }
#endif // UNIT_TEST
private: private:
// AutofillDownloadManager::Observer: // AutofillDownloadManager::Observer:
void OnLoadedServerPredictions( void OnLoadedServerPredictions(
...@@ -259,6 +283,10 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -259,6 +283,10 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
AutofillDownloadManager::RequestType request_type, AutofillDownloadManager::RequestType request_type,
int http_error) override; 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 // Provides driver-level context to the shared code of the component. Must
// outlive this object. // outlive this object.
AutofillDriver* const driver_; AutofillDriver* const driver_;
...@@ -280,6 +308,9 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -280,6 +308,9 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
std::unique_ptr<AutofillMetrics::FormInteractionsUkmLogger> std::unique_ptr<AutofillMetrics::FormInteractionsUkmLogger>
form_interactions_ukm_logger_; 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|. // Will be not null only for |SaveCardBubbleViewsFullFormBrowserTest|.
ObserverForTest* observer_for_testing_ = nullptr; ObserverForTest* observer_for_testing_ = nullptr;
......
...@@ -66,8 +66,13 @@ class AutofillHandlerProxy : public AutofillHandler { ...@@ -66,8 +66,13 @@ class AutofillHandlerProxy : public AutofillHandler {
bool ShouldParseForms(const std::vector<FormData>& forms) override; bool ShouldParseForms(const std::vector<FormData>& forms) override;
void OnFormsParsed( void OnBeforeProcessParsedForms() override {}
const std::vector<const FormData*>& form_structures) override {}
void OnFormProcessed(const FormData& form,
const FormStructure& form_structure) override {}
void OnAfterProcessParsedForms(
const std::set<FormType>& form_types) override {}
private: private:
AutofillProvider* provider_; AutofillProvider* provider_;
......
...@@ -244,10 +244,6 @@ class AutofillManager : public AutofillHandler, ...@@ -244,10 +244,6 @@ class AutofillManager : public AutofillHandler,
// to be uploadable. Exposed for testing. // to be uploadable. Exposed for testing.
bool ShouldUploadForm(const FormStructure& form); 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. // Returns the last form the autofill manager considered in this frame.
virtual const FormData& last_query_form() const; virtual const FormData& last_query_form() const;
...@@ -358,10 +354,10 @@ class AutofillManager : public AutofillHandler, ...@@ -358,10 +354,10 @@ class AutofillManager : public AutofillHandler,
const FormFieldData& field, const FormFieldData& field,
const gfx::RectF& bounding_box) override; const gfx::RectF& bounding_box) override;
bool ShouldParseForms(const std::vector<FormData>& forms) override; bool ShouldParseForms(const std::vector<FormData>& forms) override;
void OnFormsParsed(const std::vector<const FormData*>& forms) override; void OnBeforeProcessParsedForms() override;
void OnFormProcessed(const FormData& form,
// Exposed for testing. const FormStructure& form_structure) override;
bool is_rich_query_enabled() const { return is_rich_query_enabled_; } void OnAfterProcessParsedForms(const std::set<FormType>& form_types) override;
// Exposed for testing. // Exposed for testing.
FormData* pending_form_data() { return pending_form_data_.get(); } FormData* pending_form_data() { return pending_form_data_.get(); }
...@@ -707,9 +703,6 @@ class AutofillManager : public AutofillHandler, ...@@ -707,9 +703,6 @@ class AutofillManager : public AutofillHandler,
std::map<base::string16, std::unique_ptr<FillingContext>> std::map<base::string16, std::unique_ptr<FillingContext>>
filling_context_by_unique_name_; 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 // Used to record metrics. This should be set at the beginning of the
// interaction and re-used throughout the context of this manager. // interaction and re-used throughout the context of this manager.
AutofillSyncSigninState sync_state_ = AutofillSyncSigninState::kNumSyncStates; AutofillSyncSigninState sync_state_ = AutofillSyncSigninState::kNumSyncStates;
......
...@@ -360,7 +360,9 @@ class FormStructure { ...@@ -360,7 +360,9 @@ class FormStructure {
// - Name for Autofill of first field // - Name for Autofill of first field
base::string16 GetIdentifierForRefill() const; 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); 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