OLD | NEW |
---|---|
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 // Increment this anytime pickle format is modified as well as provide |
14 // deserialization routine from previous kPickleVersion format. | |
15 const int kPickleVersion = 2; | |
14 | 16 |
15 void AddVectorToPickle(std::vector<base::string16> strings, | 17 void AddVectorToPickle(std::vector<base::string16> strings, |
16 Pickle* pickle) { | 18 Pickle* pickle) { |
17 pickle->WriteInt(static_cast<int>(strings.size())); | 19 pickle->WriteInt(static_cast<int>(strings.size())); |
18 for (size_t i = 0; i < strings.size(); ++i) { | 20 for (size_t i = 0; i < strings.size(); ++i) { |
19 pickle->WriteString16(strings[i]); | 21 pickle->WriteString16(strings[i]); |
20 } | 22 } |
21 } | 23 } |
22 | 24 |
23 bool ReadStringVector(PickleIterator* iter, | 25 bool ReadStringVector(PickleIterator* iter, |
24 std::vector<base::string16>* strings) { | 26 std::vector<base::string16>* strings) { |
25 int size; | 27 int size; |
26 if (!iter->ReadInt(&size)) | 28 if (!iter->ReadInt(&size)) |
27 return false; | 29 return false; |
28 | 30 |
29 base::string16 pickle_data; | 31 base::string16 pickle_data; |
30 for (int i = 0; i < size; i++) { | 32 for (int i = 0; i < size; i++) { |
31 if (!iter->ReadString16(&pickle_data)) | 33 if (!iter->ReadString16(&pickle_data)) |
32 return false; | 34 return false; |
33 | 35 |
34 strings->push_back(pickle_data); | 36 strings->push_back(pickle_data); |
35 } | 37 } |
36 return true; | 38 return true; |
37 } | 39 } |
38 | 40 |
39 template <typename T> | 41 template <typename T> |
40 bool ReadAsInt(PickleIterator* iter, T* direction) { | 42 bool ReadAsInt(PickleIterator* iter, T* target_value) { |
41 int pickle_data; | 43 int pickle_data; |
42 if (!iter->ReadInt(&pickle_data)) | 44 if (!iter->ReadInt(&pickle_data)) |
43 return false; | 45 return false; |
44 | 46 |
45 *direction = static_cast<T>(pickle_data); | 47 *target_value = static_cast<T>(pickle_data); |
46 return true; | 48 return true; |
47 } | 49 } |
48 | 50 |
49 } // namespace | 51 } // namespace |
50 | 52 |
51 namespace autofill { | 53 namespace autofill { |
52 | 54 |
53 FormFieldData::FormFieldData() | 55 FormFieldData::FormFieldData() |
54 : max_length(0), | 56 : max_length(0), |
55 is_autofilled(false), | 57 is_autofilled(false), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 !iter->ReadString16(&field_data->name) || | 151 !iter->ReadString16(&field_data->name) || |
150 !iter->ReadString16(&field_data->value) || | 152 !iter->ReadString16(&field_data->value) || |
151 !iter->ReadString(&field_data->form_control_type) || | 153 !iter->ReadString(&field_data->form_control_type) || |
152 !iter->ReadString(&field_data->autocomplete_attribute) || | 154 !iter->ReadString(&field_data->autocomplete_attribute) || |
153 !iter->ReadSizeT(&field_data->max_length) || | 155 !iter->ReadSizeT(&field_data->max_length) || |
154 !iter->ReadBool(&field_data->is_autofilled) || | 156 !iter->ReadBool(&field_data->is_autofilled) || |
155 !iter->ReadBool(&field_data->is_checked) || | 157 !iter->ReadBool(&field_data->is_checked) || |
156 !iter->ReadBool(&field_data->is_checkable) || | 158 !iter->ReadBool(&field_data->is_checkable) || |
157 !iter->ReadBool(&field_data->is_focusable) || | 159 !iter->ReadBool(&field_data->is_focusable) || |
158 !iter->ReadBool(&field_data->should_autocomplete) || | 160 !iter->ReadBool(&field_data->should_autocomplete) || |
161 !ReadAsInt(iter, &field_data->text_direction) || | |
162 !ReadStringVector(iter, &field_data->option_values) || | |
163 !ReadStringVector(iter, &field_data->option_contents)) { | |
164 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; | |
165 return false; | |
166 } | |
167 break; | |
168 } | |
169 case 2: { | |
170 if (!iter->ReadString16(&field_data->label) || | |
171 !iter->ReadString16(&field_data->name) || | |
172 !iter->ReadString16(&field_data->value) || | |
173 !iter->ReadString(&field_data->form_control_type) || | |
174 !iter->ReadString(&field_data->autocomplete_attribute) || | |
175 !iter->ReadSizeT(&field_data->max_length) || | |
176 !iter->ReadBool(&field_data->is_autofilled) || | |
177 !iter->ReadBool(&field_data->is_checked) || | |
178 !iter->ReadBool(&field_data->is_checkable) || | |
179 !iter->ReadBool(&field_data->is_focusable) || | |
180 !iter->ReadBool(&field_data->should_autocomplete) || | |
159 !ReadAsInt(iter, &field_data->role) || | 181 !ReadAsInt(iter, &field_data->role) || |
Lei Zhang
2015/01/23 06:43:01
I wish you put "role" at the end, so (de)serializi
| |
160 !ReadAsInt(iter, &field_data->text_direction) || | 182 !ReadAsInt(iter, &field_data->text_direction) || |
161 !ReadStringVector(iter, &field_data->option_values) || | 183 !ReadStringVector(iter, &field_data->option_values) || |
162 !ReadStringVector(iter, &field_data->option_contents)) { | 184 !ReadStringVector(iter, &field_data->option_contents)) { |
163 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; | 185 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; |
164 return false; | 186 return false; |
165 } | 187 } |
166 break; | 188 break; |
167 } | 189 } |
168 default: { | 190 default: { |
169 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; | 191 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; |
(...skipping 10 matching lines...) Expand all Loading... | |
180 << " " << field.autocomplete_attribute << " " << field.max_length | 202 << " " << field.autocomplete_attribute << " " << field.max_length |
181 << " " << (field.is_autofilled ? "true" : "false") << " " | 203 << " " << (field.is_autofilled ? "true" : "false") << " " |
182 << (field.is_checked ? "true" : "false") << " " | 204 << (field.is_checked ? "true" : "false") << " " |
183 << (field.is_checkable ? "true" : "false") << " " | 205 << (field.is_checkable ? "true" : "false") << " " |
184 << (field.is_focusable ? "true" : "false") << " " | 206 << (field.is_focusable ? "true" : "false") << " " |
185 << (field.should_autocomplete ? "true" : "false") << " " | 207 << (field.should_autocomplete ? "true" : "false") << " " |
186 << field.role << " " << field.text_direction; | 208 << field.role << " " << field.text_direction; |
187 } | 209 } |
188 | 210 |
189 } // namespace autofill | 211 } // namespace autofill |
OLD | NEW |