Chromium Code Reviews| 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 LOG(ERROR) << "Could not deserialize version " << version | |
| 53 << " FormData from pickle."; | |
|
Ilya Sherman
2014/08/07 19:23:31
nit: Please use DVLOG(1) here. (I do see that the
| |
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 LOG(ERROR) << "Bad pickle of FormData, no version present"; |
| 117 return false; | 122 return false; |
| 118 } | 123 } |
| 119 | |
|
Ilya Sherman
2014/08/07 19:23:31
nit: Please preserve this newline.
| |
| 120 switch (version) { | 124 switch (version) { |
| 121 case 1: { | 125 case 1: { |
| 126 base::string16 method; | |
| 127 if (!iter->ReadString16(&form_data->name) || | |
| 128 !iter->ReadString16(&method) || | |
| 129 !ReadGURL(iter, &form_data->origin) || | |
| 130 !ReadGURL(iter, &form_data->action) || | |
| 131 !iter->ReadBool(&form_data->user_submitted) || | |
| 132 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { | |
| 133 LogDeserializationError(version); | |
| 134 return false; | |
| 135 } | |
| 136 break; | |
| 137 } | |
| 138 case 2: { | |
| 122 if (!iter->ReadString16(&form_data->name) || | 139 if (!iter->ReadString16(&form_data->name) || |
| 123 !ReadGURL(iter, &form_data->origin) || | 140 !ReadGURL(iter, &form_data->origin) || |
| 124 !ReadGURL(iter, &form_data->action) || | 141 !ReadGURL(iter, &form_data->action) || |
| 125 !iter->ReadBool(&form_data->user_submitted) || | 142 !iter->ReadBool(&form_data->user_submitted) || |
| 126 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { | 143 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { |
| 127 LOG(ERROR) << "Could not deserialize FormData from pickle"; | 144 LogDeserializationError(version); |
| 128 return false; | 145 return false; |
| 129 } | 146 } |
| 130 break; | 147 break; |
| 131 } | 148 } |
|
Ilya Sherman
2014/08/07 19:23:31
nit: No need for these curly braces.
| |
| 132 default: { | 149 default: { |
| 133 LOG(ERROR) << "Unknown FormData pickle version " << version; | 150 LOG(ERROR) << "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 |