Commit 26af8a79 authored by Christoph Schwering's avatar Christoph Schwering Committed by Commit Bot

Clean up autofill constructors, operator=, comparison methods in auto.

Added copy and move constructors and move assignment operators to
structs which had only a copy constructor defined.

Set constructors to =default where applicable.

Added |name_attribute|, |id_attribute| to FormData's comparison methods
to be in line with FormFieldData's comparison methods.

Bug: 1007974
Change-Id: I97cf61c8a5b3512b9d99f677f848fb74ca669041
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844775
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703667}
parent 84d37438
...@@ -70,15 +70,21 @@ void LogDeserializationError(int version) { ...@@ -70,15 +70,21 @@ void LogDeserializationError(int version) {
} // namespace } // namespace
FormData::FormData() = default; FormData::FormData() = default;
FormData::FormData(const FormData&) = default; FormData::FormData(const FormData&) = default;
FormData& FormData::operator=(const FormData&) = default; FormData& FormData::operator=(const FormData&) = default;
FormData::FormData(FormData&&) = default; FormData::FormData(FormData&&) = default;
FormData& FormData::operator=(FormData&&) = default; FormData& FormData::operator=(FormData&&) = default;
FormData::~FormData() = default; FormData::~FormData() = default;
bool FormData::SameFormAs(const FormData& form) const { bool FormData::SameFormAs(const FormData& form) const {
if (name != form.name || url != form.url || action != form.action || if (name != form.name || id_attribute != form.id_attribute ||
is_form_tag != form.is_form_tag || name_attribute != form.name_attribute || url != form.url ||
action != form.action || is_form_tag != form.is_form_tag ||
is_formless_checkout != form.is_formless_checkout || is_formless_checkout != form.is_formless_checkout ||
fields.size() != form.fields.size()) fields.size() != form.fields.size())
return false; return false;
...@@ -90,8 +96,9 @@ bool FormData::SameFormAs(const FormData& form) const { ...@@ -90,8 +96,9 @@ bool FormData::SameFormAs(const FormData& form) const {
} }
bool FormData::SimilarFormAs(const FormData& form) const { bool FormData::SimilarFormAs(const FormData& form) const {
if (name != form.name || url != form.url || action != form.action || if (name != form.name || id_attribute != form.id_attribute ||
is_form_tag != form.is_form_tag || name_attribute != form.name_attribute || url != form.url ||
action != form.action || is_form_tag != form.is_form_tag ||
is_formless_checkout != form.is_formless_checkout || is_formless_checkout != form.is_formless_checkout ||
fields.size() != form.fields.size()) fields.size() != form.fields.size())
return false; return false;
...@@ -103,7 +110,9 @@ bool FormData::SimilarFormAs(const FormData& form) const { ...@@ -103,7 +110,9 @@ bool FormData::SimilarFormAs(const FormData& form) const {
} }
bool FormData::DynamicallySameFormAs(const FormData& form) const { bool FormData::DynamicallySameFormAs(const FormData& form) const {
if (name != form.name || fields.size() != form.fields.size()) if (name != form.name || id_attribute != form.id_attribute ||
name_attribute != form.name_attribute ||
fields.size() != form.fields.size())
return false; return false;
for (size_t i = 0; i < fields.size(); ++i) { for (size_t i = 0; i < fields.size(); ++i) {
if (!fields[i].DynamicallySameFieldAs(form.fields[i])) if (!fields[i].DynamicallySameFieldAs(form.fields[i]))
...@@ -113,7 +122,9 @@ bool FormData::DynamicallySameFormAs(const FormData& form) const { ...@@ -113,7 +122,9 @@ bool FormData::DynamicallySameFormAs(const FormData& form) const {
} }
bool FormData::operator==(const FormData& form) const { bool FormData::operator==(const FormData& form) const {
return name == form.name && url == form.url && action == form.action && return name == form.name && id_attribute == form.id_attribute &&
name_attribute == form.name_attribute && url == form.url &&
action == form.action &&
unique_renderer_id == form.unique_renderer_id && unique_renderer_id == form.unique_renderer_id &&
submission_event == form.submission_event && submission_event == form.submission_event &&
is_form_tag == form.is_form_tag && is_form_tag == form.is_form_tag &&
...@@ -127,10 +138,11 @@ bool FormData::operator!=(const FormData& form) const { ...@@ -127,10 +138,11 @@ bool FormData::operator!=(const FormData& form) const {
} }
bool FormData::operator<(const FormData& form) const { bool FormData::operator<(const FormData& form) const {
return std::tie(name, url, action, is_form_tag, is_formless_checkout, return std::tie(name, id_attribute, name_attribute, url, action, is_form_tag,
fields) < std::tie(form.name, form.url, form.action, is_formless_checkout, fields) <
form.is_form_tag, std::tie(form.name, form.id_attribute, form.name_attribute, form.url,
form.is_formless_checkout, form.fields); form.action, form.is_form_tag, form.is_formless_checkout,
form.fields);
} }
std::ostream& operator<<(std::ostream& os, const FormData& form) { std::ostream& operator<<(std::ostream& os, const FormData& form) {
......
...@@ -6,23 +6,24 @@ ...@@ -6,23 +6,24 @@
namespace autofill { namespace autofill {
FormDataPredictions::FormDataPredictions() { FormDataPredictions::FormDataPredictions() = default;
}
FormDataPredictions::FormDataPredictions(const FormDataPredictions& other) FormDataPredictions::FormDataPredictions(const FormDataPredictions&) = default;
: data(other.data),
signature(other.signature),
fields(other.fields) {
}
FormDataPredictions::~FormDataPredictions() { FormDataPredictions& FormDataPredictions::operator=(
} const FormDataPredictions&) = default;
FormDataPredictions::FormDataPredictions(FormDataPredictions&&) = default;
FormDataPredictions& FormDataPredictions::operator=(FormDataPredictions&&) =
default;
FormDataPredictions::~FormDataPredictions() = default;
bool FormDataPredictions::operator==( bool FormDataPredictions::operator==(
const FormDataPredictions& predictions) const { const FormDataPredictions& predictions) const {
return (data.SameFormAs(predictions.data) && return (data.SameFormAs(predictions.data) &&
signature == predictions.signature && signature == predictions.signature && fields == predictions.fields);
fields == predictions.fields);
} }
bool FormDataPredictions::operator!=( bool FormDataPredictions::operator!=(
......
...@@ -23,7 +23,10 @@ struct FormDataPredictions { ...@@ -23,7 +23,10 @@ struct FormDataPredictions {
std::vector<FormFieldDataPredictions> fields; std::vector<FormFieldDataPredictions> fields;
FormDataPredictions(); FormDataPredictions();
FormDataPredictions(const FormDataPredictions& other); FormDataPredictions(const FormDataPredictions&);
FormDataPredictions& operator=(const FormDataPredictions&);
FormDataPredictions(FormDataPredictions&&);
FormDataPredictions& operator=(FormDataPredictions&&);
~FormDataPredictions(); ~FormDataPredictions();
// Added for the sake of testing. // Added for the sake of testing.
......
...@@ -144,7 +144,13 @@ bool HaveSameLabel(const FormFieldData& field1, const FormFieldData& field2) { ...@@ -144,7 +144,13 @@ bool HaveSameLabel(const FormFieldData& field1, const FormFieldData& field2) {
FormFieldData::FormFieldData() = default; FormFieldData::FormFieldData() = default;
FormFieldData::FormFieldData(const FormFieldData& other) = default; FormFieldData::FormFieldData(const FormFieldData&) = default;
FormFieldData& FormFieldData::operator=(const FormFieldData&) = default;
FormFieldData::FormFieldData(FormFieldData&&) = default;
FormFieldData& FormFieldData::operator=(FormFieldData&&) = default;
FormFieldData::~FormFieldData() = default; FormFieldData::~FormFieldData() = default;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace base { namespace base {
class Pickle; class Pickle;
class PickleIterator; class PickleIterator;
} } // namespace base
namespace autofill { namespace autofill {
...@@ -61,7 +61,10 @@ struct FormFieldData { ...@@ -61,7 +61,10 @@ struct FormFieldData {
std::numeric_limits<uint32_t>::max(); std::numeric_limits<uint32_t>::max();
FormFieldData(); FormFieldData();
FormFieldData(const FormFieldData& other); FormFieldData(const FormFieldData&);
FormFieldData& operator=(const FormFieldData&);
FormFieldData(FormFieldData&&);
FormFieldData& operator=(FormFieldData&&);
~FormFieldData(); ~FormFieldData();
// Returns true if two form fields are the same, not counting the value. // Returns true if two form fields are the same, not counting the value.
......
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
namespace autofill { namespace autofill {
FormFieldDataPredictions::FormFieldDataPredictions() { FormFieldDataPredictions::FormFieldDataPredictions() = default;
}
FormFieldDataPredictions::FormFieldDataPredictions( FormFieldDataPredictions::FormFieldDataPredictions(
const FormFieldDataPredictions& other) const FormFieldDataPredictions&) = default;
: field(other.field),
signature(other.signature), FormFieldDataPredictions& FormFieldDataPredictions::operator=(
heuristic_type(other.heuristic_type), const FormFieldDataPredictions&) = default;
server_type(other.server_type),
overall_type(other.overall_type), FormFieldDataPredictions::FormFieldDataPredictions(FormFieldDataPredictions&&) =
parseable_name(other.parseable_name), default;
section(other.section) {}
FormFieldDataPredictions& FormFieldDataPredictions::operator=(
FormFieldDataPredictions::~FormFieldDataPredictions() { FormFieldDataPredictions&&) = default;
}
FormFieldDataPredictions::~FormFieldDataPredictions() = default;
bool FormFieldDataPredictions::operator==( bool FormFieldDataPredictions::operator==(
const FormFieldDataPredictions& predictions) const { const FormFieldDataPredictions& predictions) const {
......
...@@ -15,7 +15,10 @@ namespace autofill { ...@@ -15,7 +15,10 @@ namespace autofill {
// Stores information about a field in a form. // Stores information about a field in a form.
struct FormFieldDataPredictions { struct FormFieldDataPredictions {
FormFieldDataPredictions(); FormFieldDataPredictions();
FormFieldDataPredictions(const FormFieldDataPredictions& other); FormFieldDataPredictions(const FormFieldDataPredictions&);
FormFieldDataPredictions& operator=(const FormFieldDataPredictions&);
FormFieldDataPredictions(FormFieldDataPredictions&&);
FormFieldDataPredictions& operator=(FormFieldDataPredictions&&);
~FormFieldDataPredictions(); ~FormFieldDataPredictions();
FormFieldData field; FormFieldData field;
......
...@@ -75,7 +75,15 @@ PasswordFormFillData::PasswordFormFillData( ...@@ -75,7 +75,15 @@ PasswordFormFillData::PasswordFormFillData(
} }
} }
PasswordFormFillData::PasswordFormFillData(const PasswordFormFillData& other) = PasswordFormFillData::PasswordFormFillData(const PasswordFormFillData&) =
default;
PasswordFormFillData& PasswordFormFillData::operator=(
const PasswordFormFillData&) = default;
PasswordFormFillData::PasswordFormFillData(PasswordFormFillData&&) = default;
PasswordFormFillData& PasswordFormFillData::operator=(PasswordFormFillData&&) =
default; default;
PasswordFormFillData::~PasswordFormFillData() = default; PasswordFormFillData::~PasswordFormFillData() = default;
......
...@@ -38,8 +38,10 @@ struct PasswordFormFillData { ...@@ -38,8 +38,10 @@ struct PasswordFormFillData {
const PasswordForm& preferred_match, const PasswordForm& preferred_match,
bool wait_for_username); bool wait_for_username);
PasswordFormFillData(const PasswordFormFillData& other); PasswordFormFillData(const PasswordFormFillData&);
PasswordFormFillData& operator=(const PasswordFormFillData&);
PasswordFormFillData(PasswordFormFillData&&);
PasswordFormFillData& operator=(PasswordFormFillData&&);
~PasswordFormFillData(); ~PasswordFormFillData();
// If |has_renderer_ids| == true then |form_renderer_id| contains the unique // If |has_renderer_ids| == true then |form_renderer_id| contains the unique
...@@ -89,7 +91,6 @@ struct PasswordFormFillData { ...@@ -89,7 +91,6 @@ struct PasswordFormFillData {
// TODO(https://crbug.com/831123): Remove this field when old parsing is // TODO(https://crbug.com/831123): Remove this field when old parsing is
// removed and filling by renderer ids is by default. // removed and filling by renderer ids is by default.
bool has_renderer_ids = false; bool has_renderer_ids = false;
}; };
// If |data.wait_for_username| is set, the renderer does not need to receive // If |data.wait_for_username| is set, the renderer does not need to receive
......
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