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_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" |
11 | 11 |
12 namespace autofill { | 12 namespace autofill { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const int kPickleVersion = 1; | 16 const int kPickleVersion = 2; |
17 | 17 |
18 bool ReadGURL(PickleIterator* iter, GURL* url) { | 18 bool ReadGURL(PickleIterator* iter, GURL* url) { |
19 std::string spec; | 19 std::string spec; |
20 if (!iter->ReadString(&spec)) | 20 if (!iter->ReadString(&spec)) |
21 return false; | 21 return false; |
22 | 22 |
23 *url = GURL(spec); | 23 *url = GURL(spec); |
24 return true; | 24 return true; |
25 } | 25 } |
26 | 26 |
(...skipping 14 matching lines...) Expand all Loading... |
41 FormFieldData temp; | 41 FormFieldData temp; |
42 for (int i = 0; i < size; ++i) { | 42 for (int i = 0; i < size; ++i) { |
43 if (!DeserializeFormFieldData(iter, &temp)) | 43 if (!DeserializeFormFieldData(iter, &temp)) |
44 return false; | 44 return false; |
45 | 45 |
46 fields->push_back(temp); | 46 fields->push_back(temp); |
47 } | 47 } |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
| 51 void LogDeserializationError(int version) { |
| 52 DVLOG(1) << "Could not deserialize version " << version |
| 53 << " FormData from pickle."; |
| 54 } |
| 55 |
51 } // namespace | 56 } // namespace |
52 | 57 |
53 FormData::FormData() | 58 FormData::FormData() |
54 : user_submitted(false) { | 59 : user_submitted(false) { |
55 } | 60 } |
56 | 61 |
57 FormData::FormData(const FormData& data) | 62 FormData::FormData(const FormData& data) |
58 : name(data.name), | 63 : name(data.name), |
59 origin(data.origin), | 64 origin(data.origin), |
60 action(data.action), | 65 action(data.action), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 pickle->WriteString16(form_data.name); | 111 pickle->WriteString16(form_data.name); |
107 pickle->WriteString(form_data.origin.spec()); | 112 pickle->WriteString(form_data.origin.spec()); |
108 pickle->WriteString(form_data.action.spec()); | 113 pickle->WriteString(form_data.action.spec()); |
109 pickle->WriteBool(form_data.user_submitted); | 114 pickle->WriteBool(form_data.user_submitted); |
110 SerializeFormFieldDataVector(form_data.fields, pickle); | 115 SerializeFormFieldDataVector(form_data.fields, pickle); |
111 } | 116 } |
112 | 117 |
113 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { | 118 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { |
114 int version; | 119 int version; |
115 if (!iter->ReadInt(&version)) { | 120 if (!iter->ReadInt(&version)) { |
116 LOG(ERROR) << "Bad pickle of FormData, no version present"; | 121 DVLOG(1) << "Bad pickle of FormData, no version present"; |
117 return false; | 122 return false; |
118 } | 123 } |
119 | 124 |
120 switch (version) { | 125 switch (version) { |
121 case 1: { | 126 case 1: { |
| 127 base::string16 method; |
| 128 if (!iter->ReadString16(&form_data->name) || |
| 129 !iter->ReadString16(&method) || |
| 130 !ReadGURL(iter, &form_data->origin) || |
| 131 !ReadGURL(iter, &form_data->action) || |
| 132 !iter->ReadBool(&form_data->user_submitted) || |
| 133 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { |
| 134 LogDeserializationError(version); |
| 135 return false; |
| 136 } |
| 137 break; |
| 138 } |
| 139 case 2: |
122 if (!iter->ReadString16(&form_data->name) || | 140 if (!iter->ReadString16(&form_data->name) || |
123 !ReadGURL(iter, &form_data->origin) || | 141 !ReadGURL(iter, &form_data->origin) || |
124 !ReadGURL(iter, &form_data->action) || | 142 !ReadGURL(iter, &form_data->action) || |
125 !iter->ReadBool(&form_data->user_submitted) || | 143 !iter->ReadBool(&form_data->user_submitted) || |
126 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { | 144 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { |
127 LOG(ERROR) << "Could not deserialize FormData from pickle"; | 145 LogDeserializationError(version); |
128 return false; | 146 return false; |
129 } | 147 } |
130 break; | 148 break; |
131 } | |
132 default: { | 149 default: { |
133 LOG(ERROR) << "Unknown FormData pickle version " << version; | 150 DVLOG(1) << "Unknown FormData pickle version " << version; |
134 return false; | 151 return false; |
135 } | 152 } |
136 } | 153 } |
137 return true; | 154 return true; |
138 } | 155 } |
139 | 156 |
140 } // namespace autofill | 157 } // namespace autofill |
OLD | NEW |