Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: components/autofill/core/common/form_data.cc

Issue 614023002: [Password manager] Relplace the FormFieldData vector from autofill::FormData with named fields… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/common/form_data.h" 5 #include "components/autofill/core/common/form_data.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/common/form_field_data.h" 10 #include "components/autofill/core/common/form_field_data.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 FormData::FormData() 58 FormData::FormData()
59 : user_submitted(false) { 59 : user_submitted(false) {
60 } 60 }
61 61
62 FormData::FormData(const FormData& data) 62 FormData::FormData(const FormData& data)
63 : name(data.name), 63 : name(data.name),
64 origin(data.origin), 64 origin(data.origin),
65 action(data.action), 65 action(data.action),
66 user_submitted(data.user_submitted), 66 user_submitted(data.user_submitted),
67 username_field(data.username_field),
68 password_field(data.password_field),
67 fields(data.fields) { 69 fields(data.fields) {
68 } 70 }
69 71
70 FormData::~FormData() { 72 FormData::~FormData() {
71 } 73 }
72 74
73 bool FormData::operator==(const FormData& form) const { 75 bool FormData::operator==(const FormData& form) const {
74 return name == form.name && 76 return name == form.name && origin == form.origin && action == form.action &&
75 origin == form.origin &&
76 action == form.action &&
77 user_submitted == form.user_submitted && 77 user_submitted == form.user_submitted &&
78 fields == form.fields; 78 username_field == form.username_field &&
79 password_field == form.password_field && fields == form.fields;
79 } 80 }
80 81
81 bool FormData::operator!=(const FormData& form) const { 82 bool FormData::operator!=(const FormData& form) const {
82 return !operator==(form); 83 return !operator==(form);
83 } 84 }
84 85
85 bool FormData::operator<(const FormData& form) const { 86 bool FormData::operator<(const FormData& form) const {
86 if (name != form.name) 87 if (name != form.name)
87 return name < form.name; 88 return name < form.name;
88 if (origin != form.origin) 89 if (origin != form.origin)
89 return origin < form.origin; 90 return origin < form.origin;
90 if (action != form.action) 91 if (action != form.action)
91 return action < form.action; 92 return action < form.action;
92 if (user_submitted != form.user_submitted) 93 if (user_submitted != form.user_submitted)
93 return user_submitted < form.user_submitted; 94 return user_submitted < form.user_submitted;
95 if (username_field != form.username_field)
96 return username_field < form.username_field;
97 if (password_field != form.password_field)
98 return password_field < form.password_field;
94 return fields < form.fields; 99 return fields < form.fields;
95 } 100 }
96 101
97 std::ostream& operator<<(std::ostream& os, const FormData& form) { 102 std::ostream& operator<<(std::ostream& os, const FormData& form) {
98 os << base::UTF16ToUTF8(form.name) << " " 103 os << base::UTF16ToUTF8(form.name) << " " << form.origin << " " << form.action
99 << form.origin << " " 104 << " " << form.user_submitted << " " << form.username_field << " "
100 << form.action << " " 105 << form.password_field << " "
101 << form.user_submitted << " "
102 << "Fields:"; 106 << "Fields:";
103 for (size_t i = 0; i < form.fields.size(); ++i) { 107 for (size_t i = 0; i < form.fields.size(); ++i) {
104 os << form.fields[i] << ","; 108 os << form.fields[i] << ",";
105 } 109 }
106 return os; 110 return os;
107 } 111 }
108 112
109 void SerializeFormData(const FormData& form_data, Pickle* pickle) { 113 void SerializeFormData(const FormData& form_data, Pickle* pickle) {
110 pickle->WriteInt(kPickleVersion); 114 pickle->WriteInt(kPickleVersion);
111 pickle->WriteString16(form_data.name); 115 pickle->WriteString16(form_data.name);
112 pickle->WriteString(form_data.origin.spec()); 116 pickle->WriteString(form_data.origin.spec());
113 pickle->WriteString(form_data.action.spec()); 117 pickle->WriteString(form_data.action.spec());
114 pickle->WriteBool(form_data.user_submitted); 118 pickle->WriteBool(form_data.user_submitted);
119 SerializeFormFieldData(form_data.username_field, pickle);
120 SerializeFormFieldData(form_data.password_field, pickle);
115 SerializeFormFieldDataVector(form_data.fields, pickle); 121 SerializeFormFieldDataVector(form_data.fields, pickle);
116 } 122 }
117 123
118 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { 124 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) {
119 int version; 125 int version;
120 if (!iter->ReadInt(&version)) { 126 if (!iter->ReadInt(&version)) {
121 DVLOG(1) << "Bad pickle of FormData, no version present"; 127 DVLOG(1) << "Bad pickle of FormData, no version present";
122 return false; 128 return false;
123 } 129 }
124 130
125 switch (version) { 131 switch (version) {
126 case 1: { 132 case 1: {
127 base::string16 method; 133 base::string16 method;
128 if (!iter->ReadString16(&form_data->name) || 134 if (!iter->ReadString16(&form_data->name) ||
129 !iter->ReadString16(&method) || 135 !iter->ReadString16(&method) || !ReadGURL(iter, &form_data->origin) ||
130 !ReadGURL(iter, &form_data->origin) ||
131 !ReadGURL(iter, &form_data->action) || 136 !ReadGURL(iter, &form_data->action) ||
132 !iter->ReadBool(&form_data->user_submitted) || 137 !iter->ReadBool(&form_data->user_submitted) ||
138 !DeserializeFormFieldData(iter, &form_data->username_field) ||
139 !DeserializeFormFieldData(iter, &form_data->password_field) ||
133 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { 140 !DeserializeFormFieldDataVector(iter, &form_data->fields)) {
134 LogDeserializationError(version); 141 LogDeserializationError(version);
135 return false; 142 return false;
136 } 143 }
137 break; 144 break;
138 } 145 }
139 case 2: 146 case 2:
140 if (!iter->ReadString16(&form_data->name) || 147 if (!iter->ReadString16(&form_data->name) ||
141 !ReadGURL(iter, &form_data->origin) || 148 !ReadGURL(iter, &form_data->origin) ||
142 !ReadGURL(iter, &form_data->action) || 149 !ReadGURL(iter, &form_data->action) ||
143 !iter->ReadBool(&form_data->user_submitted) || 150 !iter->ReadBool(&form_data->user_submitted) ||
151 !DeserializeFormFieldData(iter, &form_data->username_field) ||
152 !DeserializeFormFieldData(iter, &form_data->password_field) ||
144 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { 153 !DeserializeFormFieldDataVector(iter, &form_data->fields)) {
145 LogDeserializationError(version); 154 LogDeserializationError(version);
146 return false; 155 return false;
147 } 156 }
148 break; 157 break;
149 default: { 158 default: {
150 DVLOG(1) << "Unknown FormData pickle version " << version; 159 DVLOG(1) << "Unknown FormData pickle version " << version;
151 return false; 160 return false;
152 } 161 }
153 } 162 }
154 return true; 163 return true;
155 } 164 }
156 165
157 } // namespace autofill 166 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698