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

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

Issue 2044503002: Refactor the naming scheme of Deserialize* functions in form_field_data.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_field_data.h" 5 #include "components/autofill/core/common/form_field_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 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 template <typename T> 43 template <typename T>
44 bool ReadAsInt(base::PickleIterator* iter, T* target_value) { 44 bool ReadAsInt(base::PickleIterator* iter, T* target_value) {
45 int pickle_data; 45 int pickle_data;
46 if (!iter->ReadInt(&pickle_data)) 46 if (!iter->ReadInt(&pickle_data))
47 return false; 47 return false;
48 48
49 *target_value = static_cast<T>(pickle_data); 49 *target_value = static_cast<T>(pickle_data);
50 return true; 50 return true;
51 } 51 }
52 52
53 bool DeserializeCommonSection1(base::PickleIterator* iter, 53 bool DeserializeSection1(base::PickleIterator* iter,
54 FormFieldData* field_data) { 54 FormFieldData* field_data) {
55 return iter->ReadString16(&field_data->label) && 55 return iter->ReadString16(&field_data->label) &&
56 iter->ReadString16(&field_data->name) && 56 iter->ReadString16(&field_data->name) &&
57 iter->ReadString16(&field_data->value) && 57 iter->ReadString16(&field_data->value) &&
58 iter->ReadString(&field_data->form_control_type) && 58 iter->ReadString(&field_data->form_control_type) &&
59 iter->ReadString(&field_data->autocomplete_attribute) && 59 iter->ReadString(&field_data->autocomplete_attribute) &&
60 iter->ReadUInt64(&field_data->max_length) && 60 iter->ReadUInt64(&field_data->max_length) &&
61 iter->ReadBool(&field_data->is_autofilled) && 61 iter->ReadBool(&field_data->is_autofilled) &&
62 iter->ReadBool(&field_data->is_checked) && 62 iter->ReadBool(&field_data->is_checked) &&
63 iter->ReadBool(&field_data->is_checkable) && 63 iter->ReadBool(&field_data->is_checkable) &&
64 iter->ReadBool(&field_data->is_focusable) && 64 iter->ReadBool(&field_data->is_focusable) &&
65 iter->ReadBool(&field_data->should_autocomplete); 65 iter->ReadBool(&field_data->should_autocomplete);
66 } 66 }
67 67
68 bool DeserializeCommonSection2(base::PickleIterator* iter,
69 FormFieldData* field_data) {
70 return ReadAsInt(iter, &field_data->text_direction) &&
71 ReadStringVector(iter, &field_data->option_values) &&
72 ReadStringVector(iter, &field_data->option_contents);
73 }
74
75 bool DeserializeVersion2Specific(base::PickleIterator* iter, 68 bool DeserializeVersion2Specific(base::PickleIterator* iter,
vabr (Chromium) 2016/06/07 07:14:22 nit: This should also have the name of the form De
76 FormFieldData* field_data) { 69 FormFieldData* field_data) {
77 return ReadAsInt(iter, &field_data->role); 70 return ReadAsInt(iter, &field_data->role);
78 } 71 }
79 72
73 bool DeserializeSection2(base::PickleIterator* iter,
vabr (Chromium) 2016/06/07 07:14:22 Please do not move this, just rename. That way git
74 FormFieldData* field_data) {
75 return ReadAsInt(iter, &field_data->text_direction) &&
76 ReadStringVector(iter, &field_data->option_values) &&
77 ReadStringVector(iter, &field_data->option_contents);
78 }
79
80 bool DeserializeVersion3Specific(base::PickleIterator* iter, 80 bool DeserializeVersion3Specific(base::PickleIterator* iter,
vabr (Chromium) 2016/06/07 07:14:22 nit: This should also have the name of the form De
81 FormFieldData* field_data) { 81 FormFieldData* field_data) {
82 return iter->ReadString16(&field_data->placeholder); 82 return iter->ReadString16(&field_data->placeholder);
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 FormFieldData::FormFieldData() 87 FormFieldData::FormFieldData()
88 : max_length(0), 88 : max_length(0),
89 is_autofilled(false), 89 is_autofilled(false),
90 is_checked(false), 90 is_checked(false),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 FormFieldData* field_data) { 181 FormFieldData* field_data) {
182 int version; 182 int version;
183 FormFieldData temp_form_field_data; 183 FormFieldData temp_form_field_data;
184 if (!iter->ReadInt(&version)) { 184 if (!iter->ReadInt(&version)) {
185 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; 185 LOG(ERROR) << "Bad pickle of FormFieldData, no version present";
186 return false; 186 return false;
187 } 187 }
188 188
189 switch (version) { 189 switch (version) {
190 case 1: { 190 case 1: {
191 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 191 if (!DeserializeSection1(iter, &temp_form_field_data) ||
192 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 192 !DeserializeSection2(iter, &temp_form_field_data)) {
193 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 193 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
194 return false; 194 return false;
195 } 195 }
196 break; 196 break;
197 } 197 }
198 case 2: { 198 case 2: {
199 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 199 if (!DeserializeSection1(iter, &temp_form_field_data) ||
200 !DeserializeVersion2Specific(iter, &temp_form_field_data) || 200 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
201 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 201 !DeserializeSection2(iter, &temp_form_field_data)) {
202 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 202 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
203 return false; 203 return false;
204 } 204 }
205 break; 205 break;
206 } 206 }
207 case 3: { 207 case 3: {
208 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 208 if (!DeserializeSection1(iter, &temp_form_field_data) ||
209 !DeserializeVersion2Specific(iter, &temp_form_field_data) || 209 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
210 !DeserializeCommonSection2(iter, &temp_form_field_data) || 210 !DeserializeSection2(iter, &temp_form_field_data) ||
211 !DeserializeVersion3Specific(iter, &temp_form_field_data)) { 211 !DeserializeVersion3Specific(iter, &temp_form_field_data)) {
212 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 212 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
213 return false; 213 return false;
214 } 214 }
215 break; 215 break;
216 } 216 }
217 default: { 217 default: {
218 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; 218 LOG(ERROR) << "Unknown FormFieldData pickle version " << version;
219 return false; 219 return false;
220 } 220 }
(...skipping 10 matching lines...) Expand all
231 << " " << field.max_length << " " 231 << " " << field.max_length << " "
232 << (field.is_autofilled ? "true" : "false") << " " 232 << (field.is_autofilled ? "true" : "false") << " "
233 << (field.is_checked ? "true" : "false") << " " 233 << (field.is_checked ? "true" : "false") << " "
234 << (field.is_checkable ? "true" : "false") << " " 234 << (field.is_checkable ? "true" : "false") << " "
235 << (field.is_focusable ? "true" : "false") << " " 235 << (field.is_focusable ? "true" : "false") << " "
236 << (field.should_autocomplete ? "true" : "false") << " " 236 << (field.should_autocomplete ? "true" : "false") << " "
237 << field.role << " " << field.text_direction; 237 << field.role << " " << field.text_direction;
238 } 238 }
239 239
240 } // namespace autofill 240 } // namespace autofill
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698