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/model/entity_data.h" | 5 #include "components/sync/model/entity_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/trace_event/memory_usage_estimator.h" |
13 #include "components/sync/base/time.h" | 14 #include "components/sync/base/time.h" |
14 #include "components/sync/base/unique_position.h" | 15 #include "components/sync/base/unique_position.h" |
| 16 #include "components/sync/protocol/proto_memory_estimations.h" |
15 #include "components/sync/protocol/proto_value_conversions.h" | 17 #include "components/sync/protocol/proto_value_conversions.h" |
16 | 18 |
17 namespace syncer { | 19 namespace syncer { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 std::string UniquePositionToString( | 23 std::string UniquePositionToString( |
22 const sync_pb::UniquePosition& unique_position) { | 24 const sync_pb::UniquePosition& unique_position) { |
23 return UniquePosition::FromProto(unique_position).ToDebugString(); | 25 return UniquePosition::FromProto(unique_position).ToDebugString(); |
24 } | 26 } |
(...skipping 16 matching lines...) Expand all Loading... |
41 parent_id.swap(other->parent_id); | 43 parent_id.swap(other->parent_id); |
42 unique_position.Swap(&other->unique_position); | 44 unique_position.Swap(&other->unique_position); |
43 } | 45 } |
44 | 46 |
45 EntityDataPtr EntityData::PassToPtr() { | 47 EntityDataPtr EntityData::PassToPtr() { |
46 EntityDataPtr target; | 48 EntityDataPtr target; |
47 target.swap_value(this); | 49 target.swap_value(this); |
48 return target; | 50 return target; |
49 } | 51 } |
50 | 52 |
51 #define ADD_TO_DICT(dict, value, transform) \ | 53 #define ADD_TO_DICT(dict, value) \ |
| 54 dict->SetString(base::ToUpperASCII(#value), value); |
| 55 |
| 56 #define ADD_TO_DICT_WITH_TRANSFORM(dict, value, transform) \ |
52 dict->SetString(base::ToUpperASCII(#value), transform(value)); | 57 dict->SetString(base::ToUpperASCII(#value), transform(value)); |
53 | 58 |
54 std::unique_ptr<base::DictionaryValue> EntityData::ToDictionaryValue() { | 59 std::unique_ptr<base::DictionaryValue> EntityData::ToDictionaryValue() { |
55 std::unique_ptr<base::DictionaryValue> dict = | 60 std::unique_ptr<base::DictionaryValue> dict = |
56 EntitySpecificsToValue(specifics); | 61 EntitySpecificsToValue(specifics); |
57 ADD_TO_DICT(dict, id, ); | 62 ADD_TO_DICT(dict, id); |
58 ADD_TO_DICT(dict, client_tag_hash, ); | 63 ADD_TO_DICT(dict, client_tag_hash); |
59 ADD_TO_DICT(dict, non_unique_name, ); | 64 ADD_TO_DICT(dict, non_unique_name); |
60 ADD_TO_DICT(dict, parent_id, ); | 65 ADD_TO_DICT(dict, parent_id); |
61 ADD_TO_DICT(dict, creation_time, GetTimeDebugString); | 66 ADD_TO_DICT_WITH_TRANSFORM(dict, creation_time, GetTimeDebugString); |
62 ADD_TO_DICT(dict, modification_time, GetTimeDebugString); | 67 ADD_TO_DICT_WITH_TRANSFORM(dict, modification_time, GetTimeDebugString); |
63 ADD_TO_DICT(dict, unique_position, UniquePositionToString); | 68 ADD_TO_DICT_WITH_TRANSFORM(dict, unique_position, UniquePositionToString); |
64 return dict; | 69 return dict; |
65 } | 70 } |
66 | 71 |
67 #undef ADD_TO_DICT | 72 #undef ADD_TO_DICT |
| 73 #undef ADD_TO_DICT_WITH_TRANSFORM |
| 74 |
| 75 size_t EntityData::EstimateMemoryUsage() const { |
| 76 using base::trace_event::EstimateMemoryUsage; |
| 77 size_t memory_usage = 0; |
| 78 memory_usage += EstimateMemoryUsage(id); |
| 79 memory_usage += EstimateMemoryUsage(client_tag_hash); |
| 80 memory_usage += EstimateMemoryUsage(non_unique_name); |
| 81 memory_usage += EstimateMemoryUsage(specifics); |
| 82 memory_usage += EstimateMemoryUsage(parent_id); |
| 83 memory_usage += EstimateMemoryUsage(unique_position); |
| 84 return memory_usage; |
| 85 } |
68 | 86 |
69 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { | 87 void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { |
70 dest->Swap(src); | 88 dest->Swap(src); |
71 } | 89 } |
72 | 90 |
73 bool EntityDataTraits::HasValue(const EntityData& value) { | 91 bool EntityDataTraits::HasValue(const EntityData& value) { |
74 return !value.client_tag_hash.empty(); | 92 return !value.client_tag_hash.empty(); |
75 } | 93 } |
76 | 94 |
77 const EntityData& EntityDataTraits::DefaultValue() { | 95 const EntityData& EntityDataTraits::DefaultValue() { |
78 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); | 96 CR_DEFINE_STATIC_LOCAL(EntityData, default_instance, ()); |
79 return default_instance; | 97 return default_instance; |
80 } | 98 } |
81 | 99 |
82 } // namespace syncer | 100 } // namespace syncer |
OLD | NEW |