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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 // Keep this file in sync with the .proto files in this directory. 5 // Keep this file in sync with the .proto files in this directory.
6 6
7 #include "sync/protocol/proto_value_conversions.h" 7 #include "components/sync/protocol/proto_value_conversions.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <string> 12 #include <string>
13 13
14 #include "base/base64.h" 14 #include "base/base64.h"
15 #include "base/i18n/time_formatting.h" 15 #include "base/i18n/time_formatting.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "sync/internal_api/public/base/unique_position.h" 21 #include "components/sync/base/time.h"
22 #include "sync/protocol/app_list_specifics.pb.h" 22 #include "components/sync/base/unique_position.h"
23 #include "sync/protocol/app_notification_specifics.pb.h" 23 #include "components/sync/protocol/app_list_specifics.pb.h"
24 #include "sync/protocol/app_setting_specifics.pb.h" 24 #include "components/sync/protocol/app_notification_specifics.pb.h"
25 #include "sync/protocol/app_specifics.pb.h" 25 #include "components/sync/protocol/app_setting_specifics.pb.h"
26 #include "sync/protocol/arc_package_specifics.pb.h" 26 #include "components/sync/protocol/app_specifics.pb.h"
27 #include "sync/protocol/autofill_specifics.pb.h" 27 #include "components/sync/protocol/arc_package_specifics.pb.h"
28 #include "sync/protocol/bookmark_specifics.pb.h" 28 #include "components/sync/protocol/autofill_specifics.pb.h"
29 #include "sync/protocol/dictionary_specifics.pb.h" 29 #include "components/sync/protocol/bookmark_specifics.pb.h"
30 #include "sync/protocol/encryption.pb.h" 30 #include "components/sync/protocol/dictionary_specifics.pb.h"
31 #include "sync/protocol/experiments_specifics.pb.h" 31 #include "components/sync/protocol/encryption.pb.h"
32 #include "sync/protocol/extension_setting_specifics.pb.h" 32 #include "components/sync/protocol/experiments_specifics.pb.h"
33 #include "sync/protocol/extension_specifics.pb.h" 33 #include "components/sync/protocol/extension_setting_specifics.pb.h"
34 #include "sync/protocol/favicon_image_specifics.pb.h" 34 #include "components/sync/protocol/extension_specifics.pb.h"
35 #include "sync/protocol/favicon_tracking_specifics.pb.h" 35 #include "components/sync/protocol/favicon_image_specifics.pb.h"
36 #include "sync/protocol/history_delete_directive_specifics.pb.h" 36 #include "components/sync/protocol/favicon_tracking_specifics.pb.h"
37 #include "sync/protocol/nigori_specifics.pb.h" 37 #include "components/sync/protocol/history_delete_directive_specifics.pb.h"
38 #include "sync/protocol/password_specifics.pb.h" 38 #include "components/sync/protocol/nigori_specifics.pb.h"
39 #include "sync/protocol/preference_specifics.pb.h" 39 #include "components/sync/protocol/password_specifics.pb.h"
40 #include "sync/protocol/priority_preference_specifics.pb.h" 40 #include "components/sync/protocol/preference_specifics.pb.h"
41 #include "sync/protocol/proto_enum_conversions.h" 41 #include "components/sync/protocol/priority_preference_specifics.pb.h"
42 #include "sync/protocol/search_engine_specifics.pb.h" 42 #include "components/sync/protocol/proto_enum_conversions.h"
43 #include "sync/protocol/session_specifics.pb.h" 43 #include "components/sync/protocol/search_engine_specifics.pb.h"
44 #include "sync/protocol/sync.pb.h" 44 #include "components/sync/protocol/session_specifics.pb.h"
45 #include "sync/protocol/theme_specifics.pb.h" 45 #include "components/sync/protocol/sync.pb.h"
46 #include "sync/protocol/typed_url_specifics.pb.h" 46 #include "components/sync/protocol/theme_specifics.pb.h"
47 #include "sync/protocol/unique_position.pb.h" 47 #include "components/sync/protocol/typed_url_specifics.pb.h"
48 #include "sync/util/time.h" 48 #include "components/sync/protocol/unique_position.pb.h"
49 49
50 namespace syncer { 50 namespace syncer {
51 51
52 namespace { 52 namespace {
53 53
54 // Basic Type -> Value functions. 54 // Basic Type -> Value functions.
55 55
56 std::unique_ptr<base::StringValue> MakeInt64Value(int64_t x) { 56 std::unique_ptr<base::StringValue> MakeInt64Value(int64_t x) {
57 return base::WrapUnique(new base::StringValue(base::Int64ToString(x))); 57 return base::WrapUnique(new base::StringValue(base::Int64ToString(x)));
58 } 58 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) 103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
104 #define SET_STR(field) SET_TYPE(field, SetString, ) 104 #define SET_STR(field) SET_TYPE(field, SetString, )
105 #define SET_TIME_STR(field) SET_TYPE(field, SetString, TimestampToString) 105 #define SET_TIME_STR(field) SET_TYPE(field, SetString, TimestampToString)
106 #define SET_STR_REP(field) \ 106 #define SET_STR_REP(field) \
107 value->Set( \ 107 value->Set( \
108 #field, \ 108 #field, \
109 MakeRepeatedValue<const std::string&, \ 109 MakeRepeatedValue<const std::string&, \
110 google::protobuf::RepeatedPtrField<std::string>, \ 110 google::protobuf::RepeatedPtrField<std::string>, \
111 std::unique_ptr<base::StringValue>>(proto.field(), \ 111 std::unique_ptr<base::StringValue>>(proto.field(), \
112 MakeStringValue)) 112 MakeStringValue))
113 #define SET_EXPERIMENT_ENABLED_FIELD(field) \ 113 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
114 do { \ 114 do { \
115 if (proto.has_##field() && \ 115 if (proto.has_##field() && proto.field().has_enabled()) { \
116 proto.field().has_enabled()) { \ 116 value->Set(#field, new base::FundamentalValue(proto.field().enabled())); \
117 value->Set(#field, \ 117 } \
118 new base::FundamentalValue( \
119 proto.field().enabled())); \
120 } \
121 } while (0) 118 } while (0)
122 119
123 #define SET_FIELD(field, fn) \ 120 #define SET_FIELD(field, fn) \
124 do { \ 121 do { \
125 if (specifics.has_##field()) { \ 122 if (specifics.has_##field()) { \
126 value->Set(#field, fn(specifics.field())); \ 123 value->Set(#field, fn(specifics.field())); \
127 } \ 124 } \
128 } while (0) 125 } while (0)
129 126
130 // If you add another macro, don't forget to add an #undef at the end 127 // If you add another macro, don't forget to add an #undef at the end
131 // of this file, too. 128 // of this file, too.
132 129
133 std::unique_ptr<base::DictionaryValue> EncryptedDataToValue( 130 std::unique_ptr<base::DictionaryValue> EncryptedDataToValue(
134 const sync_pb::EncryptedData& proto) { 131 const sync_pb::EncryptedData& proto) {
135 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 132 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
136 SET_STR(key_name); 133 SET_STR(key_name);
137 // TODO(akalin): Shouldn't blob be of type bytes instead of string? 134 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 377
381 std::unique_ptr<base::DictionaryValue> AutofillWalletSpecificsToValue( 378 std::unique_ptr<base::DictionaryValue> AutofillWalletSpecificsToValue(
382 const sync_pb::AutofillWalletSpecifics& proto) { 379 const sync_pb::AutofillWalletSpecifics& proto) {
383 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 380 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
384 381
385 SET_ENUM(type, GetWalletInfoTypeString); 382 SET_ENUM(type, GetWalletInfoTypeString);
386 if (proto.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) { 383 if (proto.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
387 value->Set("masked_card", 384 value->Set("masked_card",
388 WalletMaskedCreditCardToValue(proto.masked_card())); 385 WalletMaskedCreditCardToValue(proto.masked_card()));
389 } else if (proto.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS) { 386 } else if (proto.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS) {
390 value->Set("address", 387 value->Set("address", WalletPostalAddressToValue(proto.address()));
391 WalletPostalAddressToValue(proto.address()));
392 } 388 }
393 return value; 389 return value;
394 } 390 }
395 391
396 std::unique_ptr<base::DictionaryValue> MetaInfoToValue( 392 std::unique_ptr<base::DictionaryValue> MetaInfoToValue(
397 const sync_pb::MetaInfo& proto) { 393 const sync_pb::MetaInfo& proto) {
398 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 394 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
399 SET_STR(key); 395 SET_STR(key);
400 SET_STR(value); 396 SET_STR(value);
401 return value; 397 return value;
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 #undef SET_BYTES 1089 #undef SET_BYTES
1094 #undef SET_INT32 1090 #undef SET_INT32
1095 #undef SET_INT64 1091 #undef SET_INT64
1096 #undef SET_INT64_REP 1092 #undef SET_INT64_REP
1097 #undef SET_STR 1093 #undef SET_STR
1098 #undef SET_STR_REP 1094 #undef SET_STR_REP
1099 1095
1100 #undef SET_FIELD 1096 #undef SET_FIELD
1101 1097
1102 } // namespace syncer 1098 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/protocol/proto_value_conversions.h ('k') | components/sync/protocol/proto_value_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698