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

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

Issue 980583002: Serialize form_data in Gnome keyring password store service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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_data.h" 5 #include "components/autofill/core/common/form_data.h"
6 6
7 #include "base/base64.h"
7 #include "base/pickle.h" 8 #include "base/pickle.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/common/form_field_data.h" 11 #include "components/autofill/core/common/form_field_data.h"
11 12
12 namespace autofill { 13 namespace autofill {
13 14
14 namespace { 15 namespace {
15 16
16 const int kPickleVersion = 3; 17 const int kPickleVersion = 3;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void SerializeFormData(const FormData& form_data, Pickle* pickle) { 118 void SerializeFormData(const FormData& form_data, Pickle* pickle) {
118 pickle->WriteInt(kPickleVersion); 119 pickle->WriteInt(kPickleVersion);
119 pickle->WriteString16(form_data.name); 120 pickle->WriteString16(form_data.name);
120 pickle->WriteString(form_data.origin.spec()); 121 pickle->WriteString(form_data.origin.spec());
121 pickle->WriteString(form_data.action.spec()); 122 pickle->WriteString(form_data.action.spec());
122 pickle->WriteBool(form_data.user_submitted); 123 pickle->WriteBool(form_data.user_submitted);
123 SerializeFormFieldDataVector(form_data.fields, pickle); 124 SerializeFormFieldDataVector(form_data.fields, pickle);
124 pickle->WriteBool(form_data.is_form_tag); 125 pickle->WriteBool(form_data.is_form_tag);
125 } 126 }
126 127
128 void SerializeFormData(const FormData& form_data, std::string* output) {
129 Pickle pickle;
130 SerializeFormData(form_data, &pickle);
131 Base64Encode(
132 base::StringPiece(static_cast<const char*>(pickle.data()), pickle.size()),
133 output);
134 }
135
127 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { 136 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) {
128 int version; 137 int version;
129 if (!iter->ReadInt(&version)) { 138 if (!iter->ReadInt(&version)) {
130 DVLOG(1) << "Bad pickle of FormData, no version present"; 139 DVLOG(1) << "Bad pickle of FormData, no version present";
131 return false; 140 return false;
132 } 141 }
133 142
134 if (version < 1 || version > kPickleVersion) { 143 if (version < 1 || version > kPickleVersion) {
135 DVLOG(1) << "Unknown FormData pickle version " << version; 144 DVLOG(1) << "Unknown FormData pickle version " << version;
136 return false; 145 return false;
(...skipping 25 matching lines...) Expand all
162 LogDeserializationError(version); 171 LogDeserializationError(version);
163 return false; 172 return false;
164 } 173 }
165 } else { 174 } else {
166 form_data->is_form_tag = true; 175 form_data->is_form_tag = true;
167 } 176 }
168 177
169 return true; 178 return true;
170 } 179 }
171 180
181 bool DeserializeFormData(const char* input, FormData* form_data) {
Garrett Casto 2015/03/04 18:05:31 I would just take a StringPiece in the function in
dvadym 2015/03/05 10:38:19 Done.
182 if (input == nullptr || input[0] == '\0')
183 return false;
184 std::string pickle_data;
185 Base64Decode(base::StringPiece(input), &pickle_data);
186 Pickle pickle(pickle_data.data(), pickle_data.size());
187 PickleIterator iter(pickle);
188 return DeserializeFormData(&iter, form_data);
189 }
190
172 } // namespace autofill 191 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698