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

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 DeserializeCommonSection1(base::PickleIterator* iter,
vabr (Chromium) 2016/06/06 15:40:01 Sorry for nitpicking, but I would still suggest to
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 }
63 iter->ReadBool(&field_data->is_checkable) && 63
64 iter->ReadBool(&field_data->is_focusable) && 64 bool DeserializeCheckStaus(base::PickleIterator* iter,
vabr (Chromium) 2016/06/06 15:40:01 Actually, let's not split DeserializeCommonSection
vabr (Chromium) 2016/06/06 15:40:01 typo: Staus -> Status Having said that, this name
65 iter->ReadBool(&field_data->should_autocomplete); 65 FormFieldData* field_data) {
66 return iter->ReadBool(&field_data->is_checked) &&
67 iter->ReadBool(&field_data->is_checkable);
66 } 68 }
67 69
68 bool DeserializeCommonSection2(base::PickleIterator* iter, 70 bool DeserializeCommonSection2(base::PickleIterator* iter,
69 FormFieldData* field_data) { 71 FormFieldData* field_data) {
70 return ReadAsInt(iter, &field_data->text_direction) && 72 return iter->ReadBool(&field_data->is_focusable) &&
71 ReadStringVector(iter, &field_data->option_values) && 73 iter->ReadBool(&field_data->should_autocomplete);
72 ReadStringVector(iter, &field_data->option_contents);
73 } 74 }
74 75
75 bool DeserializeVersion2Specific(base::PickleIterator* iter, 76 bool DeserializeVersion2Specific(base::PickleIterator* iter,
76 FormFieldData* field_data) { 77 FormFieldData* field_data) {
77 return ReadAsInt(iter, &field_data->role); 78 return ReadAsInt(iter, &field_data->role);
78 } 79 }
79 80
81 bool DeserializeCommonSection3(base::PickleIterator* iter,
82 FormFieldData* field_data) {
83 return ReadAsInt(iter, &field_data->text_direction) &&
84 ReadStringVector(iter, &field_data->option_values) &&
85 ReadStringVector(iter, &field_data->option_contents);
86 }
87
80 bool DeserializeVersion3Specific(base::PickleIterator* iter, 88 bool DeserializeVersion3Specific(base::PickleIterator* iter,
81 FormFieldData* field_data) { 89 FormFieldData* field_data) {
82 return iter->ReadString16(&field_data->placeholder); 90 return iter->ReadString16(&field_data->placeholder);
83 } 91 }
84 92
85 } // namespace 93 } // namespace
86 94
87 FormFieldData::FormFieldData() 95 FormFieldData::FormFieldData()
88 : max_length(0), 96 : max_length(0),
89 is_autofilled(false), 97 is_autofilled(false),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 int version; 190 int version;
183 FormFieldData temp_form_field_data; 191 FormFieldData temp_form_field_data;
184 if (!iter->ReadInt(&version)) { 192 if (!iter->ReadInt(&version)) {
185 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; 193 LOG(ERROR) << "Bad pickle of FormFieldData, no version present";
186 return false; 194 return false;
187 } 195 }
188 196
189 switch (version) { 197 switch (version) {
190 case 1: { 198 case 1: {
191 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 199 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
192 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 200 !DeserializeCheckStaus(iter, &temp_form_field_data) ||
201 !DeserializeCommonSection2(iter, &temp_form_field_data) ||
202 !DeserializeCommonSection3(iter, &temp_form_field_data)) {
193 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 203 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
194 return false; 204 return false;
195 } 205 }
196 break; 206 break;
197 } 207 }
198 case 2: { 208 case 2: {
199 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 209 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
210 !DeserializeCheckStaus(iter, &temp_form_field_data) ||
211 !DeserializeCommonSection2(iter, &temp_form_field_data) ||
200 !DeserializeVersion2Specific(iter, &temp_form_field_data) || 212 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
201 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 213 !DeserializeCommonSection3(iter, &temp_form_field_data)) {
202 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 214 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
203 return false; 215 return false;
204 } 216 }
205 break; 217 break;
206 } 218 }
207 case 3: { 219 case 3: {
208 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 220 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
221 !DeserializeCheckStaus(iter, &temp_form_field_data) ||
222 !DeserializeCommonSection2(iter, &temp_form_field_data) ||
209 !DeserializeVersion2Specific(iter, &temp_form_field_data) || 223 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
210 !DeserializeCommonSection2(iter, &temp_form_field_data) || 224 !DeserializeCommonSection3(iter, &temp_form_field_data) ||
211 !DeserializeVersion3Specific(iter, &temp_form_field_data)) { 225 !DeserializeVersion3Specific(iter, &temp_form_field_data)) {
212 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 226 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
213 return false; 227 return false;
214 } 228 }
215 break; 229 break;
216 } 230 }
217 default: { 231 default: {
218 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; 232 LOG(ERROR) << "Unknown FormFieldData pickle version " << version;
219 return false; 233 return false;
220 } 234 }
(...skipping 10 matching lines...) Expand all
231 << " " << field.max_length << " " 245 << " " << field.max_length << " "
232 << (field.is_autofilled ? "true" : "false") << " " 246 << (field.is_autofilled ? "true" : "false") << " "
233 << (field.is_checked ? "true" : "false") << " " 247 << (field.is_checked ? "true" : "false") << " "
234 << (field.is_checkable ? "true" : "false") << " " 248 << (field.is_checkable ? "true" : "false") << " "
235 << (field.is_focusable ? "true" : "false") << " " 249 << (field.is_focusable ? "true" : "false") << " "
236 << (field.should_autocomplete ? "true" : "false") << " " 250 << (field.should_autocomplete ? "true" : "false") << " "
237 << field.role << " " << field.text_direction; 251 << field.role << " " << field.text_direction;
238 } 252 }
239 253
240 } // namespace autofill 254 } // 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