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

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: Style fix 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 SerializeFormDataToBase64String(const FormData& form_data,
129 std::string* output) {
130 Pickle pickle;
131 SerializeFormData(form_data, &pickle);
132 Base64Encode(
133 base::StringPiece(static_cast<const char*>(pickle.data()), pickle.size()),
134 output);
135 }
136
127 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { 137 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) {
128 int version; 138 int version;
129 if (!iter->ReadInt(&version)) { 139 if (!iter->ReadInt(&version)) {
130 DVLOG(1) << "Bad pickle of FormData, no version present"; 140 DVLOG(1) << "Bad pickle of FormData, no version present";
131 return false; 141 return false;
132 } 142 }
133 143
134 if (version < 1 || version > kPickleVersion) { 144 if (version < 1 || version > kPickleVersion) {
135 DVLOG(1) << "Unknown FormData pickle version " << version; 145 DVLOG(1) << "Unknown FormData pickle version " << version;
136 return false; 146 return false;
(...skipping 25 matching lines...) Expand all
162 LogDeserializationError(version); 172 LogDeserializationError(version);
163 return false; 173 return false;
164 } 174 }
165 } else { 175 } else {
166 form_data->is_form_tag = true; 176 form_data->is_form_tag = true;
167 } 177 }
168 178
169 return true; 179 return true;
170 } 180 }
171 181
182 bool DeserializeFormDataFromBase64String(const base::StringPiece& input,
183 FormData* form_data) {
184 if (input.empty())
185 return false;
186 std::string pickle_data;
187 Base64Decode(input, &pickle_data);
188 Pickle pickle(pickle_data.data(), static_cast<int>(pickle_data.size()));
189 PickleIterator iter(pickle);
190 return DeserializeFormData(&iter, form_data);
191 }
192
172 } // namespace autofill 193 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/form_data.h ('k') | components/autofill/core/common/form_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698