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

Side by Side Diff: components/sync/protocol/proto_value_conversions.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync/protocol/proto_value_conversions.h" 5 #include "components/sync/protocol/proto_value_conversions.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // std::unique_ptr<base::DictionaryValue> ToValue( 77 // std::unique_ptr<base::DictionaryValue> ToValue(
78 // const sync_pb::GreenProto& proto) const { 78 // const sync_pb::GreenProto& proto) const {
79 // auto value = ToValueImpl(proto); 79 // auto value = ToValueImpl(proto);
80 // value->SetString("secret", "<clobbered>"); 80 // value->SetString("secret", "<clobbered>");
81 // return value; 81 // return value;
82 // } 82 // }
83 // 83 //
84 // ToValue() doesn't have to return base::DictionaryValue though. It might 84 // ToValue() doesn't have to return base::DictionaryValue though. It might
85 // be more appropriate to serialize GreenProto into a string instead: 85 // be more appropriate to serialize GreenProto into a string instead:
86 // 86 //
87 // std::unique_ptr<base::StringValue> ToValue( 87 // std::unique_ptr<base::Value> ToValue(
88 // const sync_pb::GreenProto& proto) const { 88 // const sync_pb::GreenProto& proto) const {
89 // return base::MakeUnique<base::StringValue>(proto.content()); 89 // return base::MakeUnique<base::Value>(proto.content());
90 // } 90 // }
91 // 91 //
92 class ToValueVisitor { 92 class ToValueVisitor {
93 public: 93 public:
94 ToValueVisitor(bool include_specifics = true, 94 ToValueVisitor(bool include_specifics = true,
95 base::DictionaryValue* value = nullptr) 95 base::DictionaryValue* value = nullptr)
96 : value_(value) 96 : value_(value)
97 , include_specifics_(include_specifics) {} 97 , include_specifics_(include_specifics) {}
98 98
99 template <class P> 99 template <class P>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (proto.type() != sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) { 211 if (proto.type() != sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
212 value->Remove("masked_card", nullptr); 212 value->Remove("masked_card", nullptr);
213 } 213 }
214 return value; 214 return value;
215 } 215 }
216 216
217 // UniquePosition 217 // UniquePosition
218 std::unique_ptr<base::Value> ToValue( 218 std::unique_ptr<base::Value> ToValue(
219 const sync_pb::UniquePosition& proto) const { 219 const sync_pb::UniquePosition& proto) const {
220 UniquePosition pos = UniquePosition::FromProto(proto); 220 UniquePosition pos = UniquePosition::FromProto(proto);
221 return base::MakeUnique<base::StringValue>(pos.ToDebugString()); 221 return base::MakeUnique<base::Value>(pos.ToDebugString());
222 } 222 }
223 223
224 private: 224 private:
225 template <class P> 225 template <class P>
226 std::unique_ptr<base::DictionaryValue> ToValueImpl(const P& proto) const { 226 std::unique_ptr<base::DictionaryValue> ToValueImpl(const P& proto) const {
227 auto value = base::MakeUnique<base::DictionaryValue>(); 227 auto value = base::MakeUnique<base::DictionaryValue>();
228 ToValueVisitor visitor(include_specifics_, value.get()); 228 ToValueVisitor visitor(include_specifics_, value.get());
229 VisitProtoFields(visitor, proto); 229 VisitProtoFields(visitor, proto);
230 return value; 230 return value;
231 } 231 }
232 232
233 static std::unique_ptr<base::Value> BytesToValue(const std::string& bytes) { 233 static std::unique_ptr<base::Value> BytesToValue(const std::string& bytes) {
234 std::string bytes_base64; 234 std::string bytes_base64;
235 base::Base64Encode(bytes, &bytes_base64); 235 base::Base64Encode(bytes, &bytes_base64);
236 return base::MakeUnique<base::StringValue>(bytes_base64); 236 return base::MakeUnique<base::Value>(bytes_base64);
237 } 237 }
238 238
239 template <class E> 239 template <class E>
240 static std::unique_ptr<base::Value> EnumToValue(E value) { 240 static std::unique_ptr<base::Value> EnumToValue(E value) {
241 return base::MakeUnique<base::StringValue>(ProtoEnumToString(value)); 241 return base::MakeUnique<base::Value>(ProtoEnumToString(value));
242 } 242 }
243 243
244 std::unique_ptr<base::Value> ToValue(const std::string& value) const { 244 std::unique_ptr<base::Value> ToValue(const std::string& value) const {
245 return base::MakeUnique<base::StringValue>(value); 245 return base::MakeUnique<base::Value>(value);
246 } 246 }
247 247
248 std::unique_ptr<base::Value> ToValue(int64_t value) const { 248 std::unique_ptr<base::Value> ToValue(int64_t value) const {
249 return base::MakeUnique<base::StringValue>(base::Int64ToString(value)); 249 return base::MakeUnique<base::Value>(base::Int64ToString(value));
250 } 250 }
251 std::unique_ptr<base::Value> ToValue(uint64_t value) const { 251 std::unique_ptr<base::Value> ToValue(uint64_t value) const {
252 return base::MakeUnique<base::StringValue>(base::Int64ToString(value)); 252 return base::MakeUnique<base::Value>(base::Int64ToString(value));
253 } 253 }
254 std::unique_ptr<base::Value> ToValue(uint32_t value) const { 254 std::unique_ptr<base::Value> ToValue(uint32_t value) const {
255 return base::MakeUnique<base::StringValue>(base::Int64ToString(value)); 255 return base::MakeUnique<base::Value>(base::Int64ToString(value));
256 } 256 }
257 std::unique_ptr<base::Value> ToValue(int32_t value) const { 257 std::unique_ptr<base::Value> ToValue(int32_t value) const {
258 return base::MakeUnique<base::StringValue>(base::Int64ToString(value)); 258 return base::MakeUnique<base::Value>(base::Int64ToString(value));
259 } 259 }
260 260
261 std::unique_ptr<base::Value> ToValue(bool value) const { 261 std::unique_ptr<base::Value> ToValue(bool value) const {
262 return base::MakeUnique<base::Value>(value); 262 return base::MakeUnique<base::Value>(value);
263 } 263 }
264 std::unique_ptr<base::Value> ToValue(float value) const { 264 std::unique_ptr<base::Value> ToValue(float value) const {
265 return base::MakeUnique<base::Value>(value); 265 return base::MakeUnique<base::Value>(value);
266 } 266 }
267 std::unique_ptr<base::Value> ToValue(double value) const { 267 std::unique_ptr<base::Value> ToValue(double value) const {
268 return base::MakeUnique<base::Value>(value); 268 return base::MakeUnique<base::Value>(value);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 IMPLEMENT_PROTO_TO_VALUE(WifiCredentialSpecifics) 353 IMPLEMENT_PROTO_TO_VALUE(WifiCredentialSpecifics)
354 354
355 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerMessage) 355 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerMessage)
356 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerResponse) 356 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerResponse)
357 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(SyncEntity) 357 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(SyncEntity)
358 358
359 #undef IMPLEMENT_PROTO_TO_VALUE 359 #undef IMPLEMENT_PROTO_TO_VALUE
360 #undef IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS 360 #undef IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS
361 361
362 } // namespace syncer 362 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/js_mutation_event_observer.cc ('k') | components/sync/syncable/entry_kernel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698