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

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

Issue 800543009: autofill: bumped pickle version of FormFieldData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « no previous file | components/autofill/core/common/form_field_data_unittest.cc » ('j') | 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
11 namespace { 11 namespace {
12 12
13 const int kPickleVersion = 1; 13 const int kPickleVersion = 2;
vabr (Chromium) 2015/01/20 11:19:57 Please add a big fat warning to bump the version i
14 14
15 void AddVectorToPickle(std::vector<base::string16> strings, 15 void AddVectorToPickle(std::vector<base::string16> strings,
16 Pickle* pickle) { 16 Pickle* pickle) {
17 pickle->WriteInt(static_cast<int>(strings.size())); 17 pickle->WriteInt(static_cast<int>(strings.size()));
18 for (size_t i = 0; i < strings.size(); ++i) { 18 for (size_t i = 0; i < strings.size(); ++i) {
19 pickle->WriteString16(strings[i]); 19 pickle->WriteString16(strings[i]);
20 } 20 }
21 } 21 }
22 22
23 bool ReadStringVector(PickleIterator* iter, 23 bool ReadStringVector(PickleIterator* iter,
24 std::vector<base::string16>* strings) { 24 std::vector<base::string16>* strings) {
25 int size; 25 int size;
26 if (!iter->ReadInt(&size)) 26 if (!iter->ReadInt(&size))
27 return false; 27 return false;
28 28
29 base::string16 pickle_data; 29 base::string16 pickle_data;
30 for (int i = 0; i < size; i++) { 30 for (int i = 0; i < size; i++) {
31 if (!iter->ReadString16(&pickle_data)) 31 if (!iter->ReadString16(&pickle_data))
32 return false; 32 return false;
33 33
34 strings->push_back(pickle_data); 34 strings->push_back(pickle_data);
35 } 35 }
36 return true; 36 return true;
37 } 37 }
38 38
39 template <typename T> 39 template <typename T>
40 bool ReadAsInt(PickleIterator* iter, T* direction) { 40 bool ReadAsInt(PickleIterator* iter, T* direction) {
vabr (Chromium) 2015/01/20 11:19:57 optional nit: While at it, could you please rename
41 int pickle_data; 41 int pickle_data;
42 if (!iter->ReadInt(&pickle_data)) 42 if (!iter->ReadInt(&pickle_data))
43 return false; 43 return false;
44 44
45 *direction = static_cast<T>(pickle_data); 45 *direction = static_cast<T>(pickle_data);
46 return true; 46 return true;
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 !iter->ReadString16(&field_data->name) || 149 !iter->ReadString16(&field_data->name) ||
150 !iter->ReadString16(&field_data->value) || 150 !iter->ReadString16(&field_data->value) ||
151 !iter->ReadString(&field_data->form_control_type) || 151 !iter->ReadString(&field_data->form_control_type) ||
152 !iter->ReadString(&field_data->autocomplete_attribute) || 152 !iter->ReadString(&field_data->autocomplete_attribute) ||
153 !iter->ReadSizeT(&field_data->max_length) || 153 !iter->ReadSizeT(&field_data->max_length) ||
154 !iter->ReadBool(&field_data->is_autofilled) || 154 !iter->ReadBool(&field_data->is_autofilled) ||
155 !iter->ReadBool(&field_data->is_checked) || 155 !iter->ReadBool(&field_data->is_checked) ||
156 !iter->ReadBool(&field_data->is_checkable) || 156 !iter->ReadBool(&field_data->is_checkable) ||
157 !iter->ReadBool(&field_data->is_focusable) || 157 !iter->ReadBool(&field_data->is_focusable) ||
158 !iter->ReadBool(&field_data->should_autocomplete) || 158 !iter->ReadBool(&field_data->should_autocomplete) ||
159 !ReadAsInt(iter, &field_data->text_direction) ||
160 !ReadStringVector(iter, &field_data->option_values) ||
161 !ReadStringVector(iter, &field_data->option_contents)) {
162 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
163 return false;
164 }
165 break;
166 }
167 case 2: {
168 if (!iter->ReadString16(&field_data->label) ||
169 !iter->ReadString16(&field_data->name) ||
170 !iter->ReadString16(&field_data->value) ||
171 !iter->ReadString(&field_data->form_control_type) ||
172 !iter->ReadString(&field_data->autocomplete_attribute) ||
173 !iter->ReadSizeT(&field_data->max_length) ||
174 !iter->ReadBool(&field_data->is_autofilled) ||
175 !iter->ReadBool(&field_data->is_checked) ||
176 !iter->ReadBool(&field_data->is_checkable) ||
177 !iter->ReadBool(&field_data->is_focusable) ||
178 !iter->ReadBool(&field_data->should_autocomplete) ||
159 !ReadAsInt(iter, &field_data->role) || 179 !ReadAsInt(iter, &field_data->role) ||
160 !ReadAsInt(iter, &field_data->text_direction) || 180 !ReadAsInt(iter, &field_data->text_direction) ||
161 !ReadStringVector(iter, &field_data->option_values) || 181 !ReadStringVector(iter, &field_data->option_values) ||
162 !ReadStringVector(iter, &field_data->option_contents)) { 182 !ReadStringVector(iter, &field_data->option_contents)) {
163 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 183 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
164 return false; 184 return false;
165 } 185 }
166 break; 186 break;
167 } 187 }
168 default: { 188 default: {
(...skipping 11 matching lines...) Expand all
180 << " " << field.autocomplete_attribute << " " << field.max_length 200 << " " << field.autocomplete_attribute << " " << field.max_length
181 << " " << (field.is_autofilled ? "true" : "false") << " " 201 << " " << (field.is_autofilled ? "true" : "false") << " "
182 << (field.is_checked ? "true" : "false") << " " 202 << (field.is_checked ? "true" : "false") << " "
183 << (field.is_checkable ? "true" : "false") << " " 203 << (field.is_checkable ? "true" : "false") << " "
184 << (field.is_focusable ? "true" : "false") << " " 204 << (field.is_focusable ? "true" : "false") << " "
185 << (field.should_autocomplete ? "true" : "false") << " " 205 << (field.should_autocomplete ? "true" : "false") << " "
186 << field.role << " " << field.text_direction; 206 << field.role << " " << field.text_direction;
187 } 207 }
188 208
189 } // namespace autofill 209 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/common/form_field_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698