Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/api/entity_data.h" | 5 #include "components/sync/api/entity_data.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "components/sync/base/unique_position.h" | |
| 13 #include "components/sync/protocol/proto_value_conversions.h" | |
| 10 | 14 |
| 11 namespace syncer_v2 { | 15 namespace syncer_v2 { |
| 12 | 16 |
| 17 namespace { | |
|
skym
2016/09/12 16:40:38
I don't think namespaces affect macros
Gang Wu
2016/09/12 22:38:02
Done.
| |
| 18 #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
| |
| 19 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.
| |
| 20 } | |
|
skym
2016/09/12 16:40:38
// namespace
Gang Wu
2016/09/12 22:38:02
Done.
| |
| 21 | |
| 13 EntityData::EntityData() {} | 22 EntityData::EntityData() {} |
| 14 EntityData::~EntityData() {} | 23 EntityData::~EntityData() {} |
| 15 | 24 |
| 16 void EntityData::Swap(EntityData* other) { | 25 void EntityData::Swap(EntityData* other) { |
| 17 id.swap(other->id); | 26 id.swap(other->id); |
| 18 client_tag_hash.swap(other->client_tag_hash); | 27 client_tag_hash.swap(other->client_tag_hash); |
| 19 non_unique_name.swap(other->non_unique_name); | 28 non_unique_name.swap(other->non_unique_name); |
| 20 | 29 |
| 21 specifics.Swap(&other->specifics); | 30 specifics.Swap(&other->specifics); |
| 22 | 31 |
| 23 std::swap(creation_time, other->creation_time); | 32 std::swap(creation_time, other->creation_time); |
| 24 std::swap(modification_time, other->modification_time); | 33 std::swap(modification_time, other->modification_time); |
| 25 | 34 |
| 26 parent_id.swap(other->parent_id); | 35 parent_id.swap(other->parent_id); |
| 27 unique_position.Swap(&other->unique_position); | 36 unique_position.Swap(&other->unique_position); |
| 28 } | 37 } |
| 29 | 38 |
| 30 EntityDataPtr EntityData::PassToPtr() { | 39 EntityDataPtr EntityData::PassToPtr() { |
| 31 EntityDataPtr target; | 40 EntityDataPtr target; |
| 32 target.swap_value(this); | 41 target.swap_value(this); |
| 33 return target; | 42 return target; |
| 34 } | 43 } |
| 35 | 44 |
| 45 // static | |
| 46 std::unique_ptr<base::DictionaryValue> EntityData::ToValue( | |
| 47 const EntityData& entity_data) { | |
| 48 std::unique_ptr<base::DictionaryValue> dict = | |
| 49 syncer::EntitySpecificsToValue(entity_data.specifics); | |
| 50 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.
| |
| 51 ADD_TO_DICT(dict, client_tag_hash, entity_data.client_tag_hash); | |
| 52 ADD_TO_DICT(dict, non_unique_name, entity_data.non_unique_name); | |
| 53 ADD_TO_DICT(dict, parent_id, entity_data.parent_id); | |
| 54 ADD_TO_DICT(dict, creation_time, | |
| 55 base::Int64ToString(entity_data.creation_time.ToInternalValue())); | |
| 56 ADD_TO_DICT( | |
| 57 dict, modification_time, | |
| 58 base::Int64ToString(entity_data.modification_time.ToInternalValue())); | |
| 59 ADD_TO_DICT(dict, unique_position, | |
| 60 syncer::UniquePosition::FromProto(entity_data.unique_position) | |
| 61 .ToDebugString()); | |
| 62 return dict; | |
| 63 } | |
| 64 | |
| 36 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { | 65 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { |
| 37 dest->Swap(src); | 66 dest->Swap(src); |
| 38 } | 67 } |
| 39 | 68 |
| 40 bool EntityDataTraits::HasValue(const EntityData& value) { | 69 bool EntityDataTraits::HasValue(const EntityData& value) { |
| 41 return !value.client_tag_hash.empty(); | 70 return !value.client_tag_hash.empty(); |
| 42 } | 71 } |
| 43 | 72 |
| 44 const EntityData& EntityDataTraits::DefaultValue() { | 73 const EntityData& EntityDataTraits::DefaultValue() { |
| 45 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); | 74 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); |
| 46 return default_instance; | 75 return default_instance; |
| 47 } | 76 } |
| 48 | 77 |
| 49 } // namespace syncer_v2 | 78 } // namespace syncer_v2 |
| OLD | NEW |