Commit 9e367128 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Autofill] Create the new request proto in FormStructure

Before this patch:
The old query proto was created first and then converted to the new
proto.

After this patch:
The new query proto is created directly

Bug: 1114655
Change-Id: I08255787e05f99622d9ead139cd932ced1b4a87f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429407Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810697}
parent 6c0322a3
......@@ -29,8 +29,7 @@
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/logging/log_protobufs.h"
#include "components/autofill/core/browser/proto/legacy_proto_bridge.h"
#include "components/autofill/core/browser/proto/server.pb.h"
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
......@@ -324,16 +323,16 @@ const char* RequestTypeToString(AutofillDownloadManager::RequestType type) {
}
std::ostream& operator<<(std::ostream& out,
const autofill::AutofillQueryContents& query) {
const autofill::AutofillPageQueryRequest& query) {
out << "client_version: " << query.client_version();
for (const auto& form : query.form()) {
for (const auto& form : query.forms()) {
out << "\nForm\n signature: " << form.signature();
for (const auto& field : form.field()) {
for (const auto& field : form.fields()) {
out << "\n Field\n signature: " << field.signature();
if (!field.name().empty())
out << "\n name: " << field.name();
if (!field.type().empty())
out << "\n type: " << field.type();
if (!field.control_type().empty())
out << "\n type: " << field.control_type();
}
}
return out;
......@@ -560,13 +559,12 @@ bool GetAPIBodyPayload(const std::string& payload,
}
// Gets the data payload for API Query (POST and GET).
bool GetAPIQueryPayload(const AutofillQueryContents& query,
bool GetAPIQueryPayload(const AutofillPageQueryRequest& query,
std::string* payload) {
std::string serialized_query;
if (!CreateApiRequestFromLegacyRequest(query).SerializeToString(
&serialized_query)) {
if (!query.SerializeToString(&serialized_query))
return false;
}
base::Base64UrlEncode(serialized_query,
base::Base64UrlEncodePolicy::INCLUDE_PADDING, payload);
return true;
......@@ -627,7 +625,7 @@ bool AutofillDownloadManager::StartQueryRequest(
return false;
// Encode the query for the requested forms.
AutofillQueryContents query;
AutofillPageQueryRequest query;
FormAndFieldSignatures signatures;
if (!FormStructure::EncodeQueryRequest(forms, &query, &signatures)) {
return false;
......
......@@ -758,7 +758,7 @@ bool FormStructure::EncodeUploadRequest(
// static
bool FormStructure::EncodeQueryRequest(
const std::vector<FormStructure*>& forms,
AutofillQueryContents* query,
AutofillPageQueryRequest* query,
FormAndFieldSignatures* encoded_signatures) {
DCHECK(encoded_signatures);
encoded_signatures->clear();
......@@ -782,7 +782,7 @@ bool FormStructure::EncodeQueryRequest(
if (form->IsMalformed())
continue;
form->EncodeFormForQuery(query->add_form(), encoded_signatures);
form->EncodeFormForQuery(query->add_forms(), encoded_signatures);
}
return !encoded_signatures->empty();
......@@ -1964,7 +1964,7 @@ void FormStructure::RationalizeFieldTypePredictions() {
}
void FormStructure::EncodeFormForQuery(
AutofillQueryContents::Form* query_form,
AutofillPageQueryRequest::Form* query_form,
FormAndFieldSignatures* encoded_signatures) const {
DCHECK(!IsMalformed());
......@@ -1973,24 +1973,24 @@ void FormStructure::EncodeFormForQuery(
encoded_signatures->back().first = form_signature();
if (is_rich_query_enabled_) {
EncodeFormMetadataForQuery(*this, query_form->mutable_form_metadata());
EncodeFormMetadataForQuery(*this, query_form->mutable_metadata());
}
for (const auto& field : fields_) {
if (ShouldSkipField(*field))
continue;
AutofillQueryContents::Form::Field* added_field = query_form->add_field();
AutofillPageQueryRequest::Form::Field* added_field =
query_form->add_fields();
added_field->set_signature(field->GetFieldSignature().value());
encoded_signatures->back().second.push_back(field->GetFieldSignature());
if (is_rich_query_enabled_) {
EncodeFieldMetadataForQuery(*field,
added_field->mutable_field_metadata());
EncodeFieldMetadataForQuery(*field, added_field->mutable_metadata());
}
if (IsAutofillFieldMetadataEnabled()) {
added_field->set_type(field->form_control_type);
added_field->set_control_type(field->form_control_type);
if (!field->name.empty())
added_field->set_name(base::UTF16ToUTF8(field->name));
......
......@@ -87,7 +87,7 @@ class FormStructure {
// FormStructures have the same FormSignature, only the first one is included
// in |query| and |encoded_signatures|.
static bool EncodeQueryRequest(const std::vector<FormStructure*>& forms,
autofill::AutofillQueryContents* query,
autofill::AutofillPageQueryRequest* query,
FormAndFieldSignatures* encoded_signatures);
// Parses `payload` as AutofillQueryResponse proto and calls
......@@ -524,7 +524,7 @@ class FormStructure {
// when it considers necessary.
void RationalizeFieldTypePredictions();
void EncodeFormForQuery(autofill::AutofillQueryContents::Form* query_form,
void EncodeFormForQuery(autofill::AutofillPageQueryRequest::Form* query_form,
FormAndFieldSignatures* encoded_signatures) const;
void EncodeFormForUpload(autofill::AutofillUploadContents* upload,
......
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