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

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

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check db on DB thread Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « sync/protocol/device_info_specifics.proto ('k') | sync/sync_internal_api.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sync/protocol/proto_value_conversions.h"
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/i18n/time_formatting.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/time/time.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "sync/internal_api/public/base/unique_position.h" 18 #include "sync/internal_api/public/base/unique_position.h"
17 #include "sync/protocol/app_list_specifics.pb.h" 19 #include "sync/protocol/app_list_specifics.pb.h"
18 #include "sync/protocol/app_notification_specifics.pb.h" 20 #include "sync/protocol/app_notification_specifics.pb.h"
19 #include "sync/protocol/app_setting_specifics.pb.h" 21 #include "sync/protocol/app_setting_specifics.pb.h"
20 #include "sync/protocol/app_specifics.pb.h" 22 #include "sync/protocol/app_specifics.pb.h"
21 #include "sync/protocol/autofill_specifics.pb.h" 23 #include "sync/protocol/autofill_specifics.pb.h"
22 #include "sync/protocol/bookmark_specifics.pb.h" 24 #include "sync/protocol/bookmark_specifics.pb.h"
23 #include "sync/protocol/dictionary_specifics.pb.h" 25 #include "sync/protocol/dictionary_specifics.pb.h"
24 #include "sync/protocol/encryption.pb.h" 26 #include "sync/protocol/encryption.pb.h"
25 #include "sync/protocol/experiments_specifics.pb.h" 27 #include "sync/protocol/experiments_specifics.pb.h"
26 #include "sync/protocol/extension_setting_specifics.pb.h" 28 #include "sync/protocol/extension_setting_specifics.pb.h"
27 #include "sync/protocol/extension_specifics.pb.h" 29 #include "sync/protocol/extension_specifics.pb.h"
28 #include "sync/protocol/favicon_image_specifics.pb.h" 30 #include "sync/protocol/favicon_image_specifics.pb.h"
29 #include "sync/protocol/favicon_tracking_specifics.pb.h" 31 #include "sync/protocol/favicon_tracking_specifics.pb.h"
30 #include "sync/protocol/history_delete_directive_specifics.pb.h" 32 #include "sync/protocol/history_delete_directive_specifics.pb.h"
31 #include "sync/protocol/nigori_specifics.pb.h" 33 #include "sync/protocol/nigori_specifics.pb.h"
32 #include "sync/protocol/password_specifics.pb.h" 34 #include "sync/protocol/password_specifics.pb.h"
33 #include "sync/protocol/preference_specifics.pb.h" 35 #include "sync/protocol/preference_specifics.pb.h"
34 #include "sync/protocol/priority_preference_specifics.pb.h" 36 #include "sync/protocol/priority_preference_specifics.pb.h"
35 #include "sync/protocol/proto_enum_conversions.h" 37 #include "sync/protocol/proto_enum_conversions.h"
36 #include "sync/protocol/search_engine_specifics.pb.h" 38 #include "sync/protocol/search_engine_specifics.pb.h"
37 #include "sync/protocol/session_specifics.pb.h" 39 #include "sync/protocol/session_specifics.pb.h"
38 #include "sync/protocol/sync.pb.h" 40 #include "sync/protocol/sync.pb.h"
39 #include "sync/protocol/synced_notification_app_info_specifics.pb.h" 41 #include "sync/protocol/synced_notification_app_info_specifics.pb.h"
40 #include "sync/protocol/synced_notification_specifics.pb.h" 42 #include "sync/protocol/synced_notification_specifics.pb.h"
41 #include "sync/protocol/theme_specifics.pb.h" 43 #include "sync/protocol/theme_specifics.pb.h"
42 #include "sync/protocol/typed_url_specifics.pb.h" 44 #include "sync/protocol/typed_url_specifics.pb.h"
43 #include "sync/protocol/unique_position.pb.h" 45 #include "sync/protocol/unique_position.pb.h"
46 #include "sync/util/time.h"
44 47
45 namespace syncer { 48 namespace syncer {
46 49
47 namespace { 50 namespace {
48 51
49 // Basic Type -> Value functions. 52 // Basic Type -> Value functions.
50 53
51 base::StringValue* MakeInt64Value(int64 x) { 54 base::StringValue* MakeInt64Value(int64 x) {
52 return new base::StringValue(base::Int64ToString(x)); 55 return new base::StringValue(base::Int64ToString(x));
53 } 56 }
(...skipping 21 matching lines...) Expand all
75 template <class T, class F, class V> 78 template <class T, class F, class V>
76 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { 79 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) {
77 base::ListValue* list = new base::ListValue(); 80 base::ListValue* list = new base::ListValue();
78 for (typename F::const_iterator it = fields.begin(); it != fields.end(); 81 for (typename F::const_iterator it = fields.begin(); it != fields.end();
79 ++it) { 82 ++it) {
80 list->Append(converter_fn(*it)); 83 list->Append(converter_fn(*it));
81 } 84 }
82 return list; 85 return list;
83 } 86 }
84 87
88 base::StringValue* MakeTimestampValue(int64 tm) {
89 return new base::StringValue(
90 base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)));
91 }
92
85 } // namespace 93 } // namespace
86 94
87 // Helper macros to reduce the amount of boilerplate. 95 // Helper macros to reduce the amount of boilerplate.
88 96
89 #define SET(field, fn) \ 97 #define SET(field, fn) \
90 if (proto.has_##field()) { \ 98 if (proto.has_##field()) { \
91 value->Set(#field, fn(proto.field())); \ 99 value->Set(#field, fn(proto.field())); \
92 } 100 }
93 #define SET_REP(field, fn) \ 101 #define SET_REP(field, fn) \
94 value->Set(#field, MakeRepeatedValue(proto.field(), fn)) 102 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
95 #define SET_ENUM(field, fn) \ 103 #define SET_ENUM(field, fn) \
96 value->Set(#field, MakeEnumValue(proto.field(), fn)) 104 value->Set(#field, MakeEnumValue(proto.field(), fn))
97 105
98 #define SET_BOOL(field) SET(field, new base::FundamentalValue) 106 #define SET_BOOL(field) SET(field, new base::FundamentalValue)
99 #define SET_BYTES(field) SET(field, MakeBytesValue) 107 #define SET_BYTES(field) SET(field, MakeBytesValue)
100 #define SET_INT32(field) SET(field, MakeInt64Value) 108 #define SET_INT32(field) SET(field, MakeInt64Value)
101 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value) 109 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
102 #define SET_INT64(field) SET(field, MakeInt64Value) 110 #define SET_INT64(field) SET(field, MakeInt64Value)
103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) 111 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
104 #define SET_STR(field) SET(field, new base::StringValue) 112 #define SET_STR(field) SET(field, new base::StringValue)
113 #define SET_TIME_STR(field) SET(field, MakeTimestampValue)
105 #define SET_STR_REP(field) \ 114 #define SET_STR_REP(field) \
106 value->Set(#field, \ 115 value->Set(#field, \
107 MakeRepeatedValue<const std::string&, \ 116 MakeRepeatedValue<const std::string&, \
108 google::protobuf::RepeatedPtrField< \ 117 google::protobuf::RepeatedPtrField< \
109 std::string >, \ 118 std::string >, \
110 base::StringValue>(proto.field(), \ 119 base::StringValue>(proto.field(), \
111 MakeStringValue)) 120 MakeStringValue))
112 #define SET_EXPERIMENT_ENABLED_FIELD(field) \ 121 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
113 do { \ 122 do { \
114 if (proto.has_##field() && \ 123 if (proto.has_##field() && \
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 491 }
483 492
484 base::DictionaryValue* DeviceInfoSpecificsToValue( 493 base::DictionaryValue* DeviceInfoSpecificsToValue(
485 const sync_pb::DeviceInfoSpecifics& proto) { 494 const sync_pb::DeviceInfoSpecifics& proto) {
486 base::DictionaryValue* value = new base::DictionaryValue(); 495 base::DictionaryValue* value = new base::DictionaryValue();
487 SET_STR(cache_guid); 496 SET_STR(cache_guid);
488 SET_STR(client_name); 497 SET_STR(client_name);
489 SET_ENUM(device_type, GetDeviceTypeString); 498 SET_ENUM(device_type, GetDeviceTypeString);
490 SET_STR(sync_user_agent); 499 SET_STR(sync_user_agent);
491 SET_STR(chrome_version); 500 SET_STR(chrome_version);
501 SET_TIME_STR(backup_timestamp);
492 return value; 502 return value;
493 } 503 }
494 504
495 base::DictionaryValue* DictionarySpecificsToValue( 505 base::DictionaryValue* DictionarySpecificsToValue(
496 const sync_pb::DictionarySpecifics& proto) { 506 const sync_pb::DictionarySpecifics& proto) {
497 base::DictionaryValue* value = new base::DictionaryValue(); 507 base::DictionaryValue* value = new base::DictionaryValue();
498 SET_STR(word); 508 SET_STR(word);
499 return value; 509 return value;
500 } 510 }
501 511
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 #undef SET_BYTES 1119 #undef SET_BYTES
1110 #undef SET_INT32 1120 #undef SET_INT32
1111 #undef SET_INT64 1121 #undef SET_INT64
1112 #undef SET_INT64_REP 1122 #undef SET_INT64_REP
1113 #undef SET_STR 1123 #undef SET_STR
1114 #undef SET_STR_REP 1124 #undef SET_STR_REP
1115 1125
1116 #undef SET_FIELD 1126 #undef SET_FIELD
1117 1127
1118 } // namespace syncer 1128 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/device_info_specifics.proto ('k') | sync/sync_internal_api.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698