| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/syncable/entry_kernel.h" | 5 #include "components/sync/syncable/entry_kernel.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/trace_event/memory_usage_estimators.h" |
| 13 #include "components/sync/base/cryptographer.h" | 14 #include "components/sync/base/cryptographer.h" |
| 15 #include "components/sync/protocol/proto_size_estimations.h" |
| 14 #include "components/sync/protocol/proto_value_conversions.h" | 16 #include "components/sync/protocol/proto_value_conversions.h" |
| 15 #include "components/sync/syncable/syncable_columns.h" | 17 #include "components/sync/syncable/syncable_columns.h" |
| 16 #include "components/sync/syncable/syncable_enum_conversions.h" | 18 #include "components/sync/syncable/syncable_enum_conversions.h" |
| 17 | 19 |
| 18 namespace syncer { | 20 namespace syncer { |
| 19 namespace syncable { | 21 namespace syncable { |
| 20 | 22 |
| 21 EntryKernel::EntryKernel() : dirty_(false) { | 23 EntryKernel::EntryKernel() : dirty_(false), memory_usage_(kMemoryUsageUnknown) { |
| 22 // Everything else should already be default-initialized. | 24 // Everything else should already be default-initialized. |
| 23 for (int i = 0; i < INT64_FIELDS_COUNT; ++i) { | 25 for (int i = 0; i < INT64_FIELDS_COUNT; ++i) { |
| 24 int64_fields[i] = 0; | 26 int64_fields[i] = 0; |
| 25 } | 27 } |
| 26 } | 28 } |
| 27 | 29 |
| 28 EntryKernel::EntryKernel(const EntryKernel& other) = default; | 30 EntryKernel::EntryKernel(const EntryKernel& other) = default; |
| 29 | 31 |
| 30 EntryKernel::~EntryKernel() {} | 32 EntryKernel::~EntryKernel() {} |
| 31 | 33 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 &AttachmentMetadataToValue, ATTACHMENT_METADATA_FIELDS_BEGIN, | 208 &AttachmentMetadataToValue, ATTACHMENT_METADATA_FIELDS_BEGIN, |
| 207 ATTACHMENT_METADATA_FIELDS_END - 1); | 209 ATTACHMENT_METADATA_FIELDS_END - 1); |
| 208 | 210 |
| 209 // Bit temps. | 211 // Bit temps. |
| 210 SetFieldValues(*this, kernel_info, &GetBitTempString, &BooleanToValue, | 212 SetFieldValues(*this, kernel_info, &GetBitTempString, &BooleanToValue, |
| 211 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); | 213 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); |
| 212 | 214 |
| 213 return kernel_info; | 215 return kernel_info; |
| 214 } | 216 } |
| 215 | 217 |
| 218 size_t EntryKernel::EstimateMemoryUsage() const { |
| 219 if (memory_usage_ == kMemoryUsageUnknown) { |
| 220 using base::trace_event::EstimateMemoryUsage; |
| 221 memory_usage_ = |
| 222 EstimateMemoryUsage(string_fields) + |
| 223 EstimateMemoryUsage(specifics_fields) + |
| 224 EstimateMemoryUsage(id_fields) + |
| 225 EstimateMemoryUsage(unique_position_fields) + |
| 226 EstimateMemoryUsage(attachment_metadata_fields); |
| 227 } |
| 228 return memory_usage_; |
| 229 } |
| 230 |
| 216 std::unique_ptr<base::ListValue> EntryKernelMutationMapToValue( | 231 std::unique_ptr<base::ListValue> EntryKernelMutationMapToValue( |
| 217 const EntryKernelMutationMap& mutations) { | 232 const EntryKernelMutationMap& mutations) { |
| 218 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 233 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 219 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); | 234 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); |
| 220 it != mutations.end(); ++it) { | 235 it != mutations.end(); ++it) { |
| 221 list->Append(EntryKernelMutationToValue(it->second)); | 236 list->Append(EntryKernelMutationToValue(it->second)); |
| 222 } | 237 } |
| 223 return list; | 238 return list; |
| 224 } | 239 } |
| 225 | 240 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 os << "TempFlags: "; | 290 os << "TempFlags: "; |
| 276 for (; i < BIT_TEMPS_END; ++i) { | 291 for (; i < BIT_TEMPS_END; ++i) { |
| 277 if (kernel->ref(static_cast<BitTemp>(i))) | 292 if (kernel->ref(static_cast<BitTemp>(i))) |
| 278 os << "#" << i - BIT_TEMPS_BEGIN << ", "; | 293 os << "#" << i - BIT_TEMPS_BEGIN << ", "; |
| 279 } | 294 } |
| 280 return os; | 295 return os; |
| 281 } | 296 } |
| 282 | 297 |
| 283 } // namespace syncable | 298 } // namespace syncable |
| 284 } // namespace syncer | 299 } // namespace syncer |
| OLD | NEW |