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/time.h" |
| 13 #include "components/sync/base/unique_position.h" |
| 14 #include "components/sync/protocol/proto_value_conversions.h" |
10 | 15 |
11 namespace syncer_v2 { | 16 namespace syncer_v2 { |
12 | 17 |
| 18 namespace { |
| 19 |
| 20 std::string UniquePositionToString( |
| 21 const sync_pb::UniquePosition& unique_position) { |
| 22 return syncer::UniquePosition::FromProto(unique_position).ToDebugString(); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
13 EntityData::EntityData() {} | 27 EntityData::EntityData() {} |
14 EntityData::~EntityData() {} | 28 EntityData::~EntityData() {} |
15 | 29 |
16 void EntityData::Swap(EntityData* other) { | 30 void EntityData::Swap(EntityData* other) { |
17 id.swap(other->id); | 31 id.swap(other->id); |
18 client_tag_hash.swap(other->client_tag_hash); | 32 client_tag_hash.swap(other->client_tag_hash); |
19 non_unique_name.swap(other->non_unique_name); | 33 non_unique_name.swap(other->non_unique_name); |
20 | 34 |
21 specifics.Swap(&other->specifics); | 35 specifics.Swap(&other->specifics); |
22 | 36 |
23 std::swap(creation_time, other->creation_time); | 37 std::swap(creation_time, other->creation_time); |
24 std::swap(modification_time, other->modification_time); | 38 std::swap(modification_time, other->modification_time); |
25 | 39 |
26 parent_id.swap(other->parent_id); | 40 parent_id.swap(other->parent_id); |
27 unique_position.Swap(&other->unique_position); | 41 unique_position.Swap(&other->unique_position); |
28 } | 42 } |
29 | 43 |
30 EntityDataPtr EntityData::PassToPtr() { | 44 EntityDataPtr EntityData::PassToPtr() { |
31 EntityDataPtr target; | 45 EntityDataPtr target; |
32 target.swap_value(this); | 46 target.swap_value(this); |
33 return target; | 47 return target; |
34 } | 48 } |
35 | 49 |
| 50 #define ADD_TO_DICT(dict, value, transform) \ |
| 51 dict->SetString(base::ToUpperASCII(#value), transform(value)); |
| 52 |
| 53 std::unique_ptr<base::DictionaryValue> EntityData::ToDictionaryValue() { |
| 54 std::unique_ptr<base::DictionaryValue> dict = |
| 55 syncer::EntitySpecificsToValue(specifics); |
| 56 ADD_TO_DICT(dict, id, ); |
| 57 ADD_TO_DICT(dict, client_tag_hash, ); |
| 58 ADD_TO_DICT(dict, non_unique_name, ); |
| 59 ADD_TO_DICT(dict, parent_id, ); |
| 60 ADD_TO_DICT(dict, creation_time, syncer::GetTimeDebugString); |
| 61 ADD_TO_DICT(dict, modification_time, syncer::GetTimeDebugString); |
| 62 ADD_TO_DICT(dict, unique_position, UniquePositionToString); |
| 63 return dict; |
| 64 } |
| 65 |
| 66 #undef ADD_TO_DICT |
| 67 |
36 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { | 68 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { |
37 dest->Swap(src); | 69 dest->Swap(src); |
38 } | 70 } |
39 | 71 |
40 bool EntityDataTraits::HasValue(const EntityData& value) { | 72 bool EntityDataTraits::HasValue(const EntityData& value) { |
41 return !value.client_tag_hash.empty(); | 73 return !value.client_tag_hash.empty(); |
42 } | 74 } |
43 | 75 |
44 const EntityData& EntityDataTraits::DefaultValue() { | 76 const EntityData& EntityDataTraits::DefaultValue() { |
45 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); | 77 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); |
46 return default_instance; | 78 return default_instance; |
47 } | 79 } |
48 | 80 |
49 } // namespace syncer_v2 | 81 } // namespace syncer_v2 |
OLD | NEW |