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