Index: components/sync/api/entity_data.cc |
diff --git a/components/sync/api/entity_data.cc b/components/sync/api/entity_data.cc |
index 59500fa3324b41cca4ce0b967f27ed811b73632c..4be8d715cb5726fecaed950588e1454f9acbc96b 100644 |
--- a/components/sync/api/entity_data.cc |
+++ b/components/sync/api/entity_data.cc |
@@ -7,9 +7,18 @@ |
#include <algorithm> |
#include "base/logging.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/strings/string_util.h" |
+#include "components/sync/base/unique_position.h" |
+#include "components/sync/protocol/proto_value_conversions.h" |
namespace syncer_v2 { |
+namespace { |
skym
2016/09/12 16:40:38
I don't think namespaces affect macros
Gang Wu
2016/09/12 22:38:02
Done.
|
+#define ADD_TO_DICT(dict, name, value) \ |
skym
2016/09/12 16:40:38
Why are you using a macro and not a function here?
pavely
2016/09/12 20:43:04
When you use one-off macros like this it is better
Gang Wu
2016/09/12 22:38:02
Done.
Gang Wu
2016/09/12 22:38:03
# can translate parameter to string, more general
|
+ dict->SetString(base::ToUpperASCII(#name), value); |
skym
2016/09/12 16:40:38
What does the # in "#name" do?
maxbogue
2016/09/12 17:44:26
I think it extracts the text of the variable name.
Gang Wu
2016/09/12 22:38:02
#name can translate parameter name to string "name
Gang Wu
2016/09/12 22:38:03
yes.
|
+} |
skym
2016/09/12 16:40:38
// namespace
Gang Wu
2016/09/12 22:38:02
Done.
|
+ |
EntityData::EntityData() {} |
EntityData::~EntityData() {} |
@@ -33,6 +42,26 @@ EntityDataPtr EntityData::PassToPtr() { |
return target; |
} |
+// static |
+std::unique_ptr<base::DictionaryValue> EntityData::ToValue( |
+ const EntityData& entity_data) { |
+ std::unique_ptr<base::DictionaryValue> dict = |
+ syncer::EntitySpecificsToValue(entity_data.specifics); |
+ ADD_TO_DICT(dict, id, entity_data.id); |
maxbogue
2016/09/12 17:44:26
Can you not just do dict->SetString("ID", entity_d
pavely
2016/09/12 20:43:04
You have two patterns here: simple string fields a
Gang Wu
2016/09/12 22:38:03
Done.
Gang Wu
2016/09/12 22:38:03
I copy this approach from proto_value_conversions.
|
+ ADD_TO_DICT(dict, client_tag_hash, entity_data.client_tag_hash); |
+ ADD_TO_DICT(dict, non_unique_name, entity_data.non_unique_name); |
+ ADD_TO_DICT(dict, parent_id, entity_data.parent_id); |
+ ADD_TO_DICT(dict, creation_time, |
+ base::Int64ToString(entity_data.creation_time.ToInternalValue())); |
+ ADD_TO_DICT( |
+ dict, modification_time, |
+ base::Int64ToString(entity_data.modification_time.ToInternalValue())); |
+ ADD_TO_DICT(dict, unique_position, |
+ syncer::UniquePosition::FromProto(entity_data.unique_position) |
+ .ToDebugString()); |
+ return dict; |
+} |
+ |
void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { |
dest->Swap(src); |
} |