File: entity_data.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 4,011 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync/protocol/entity_data.h"

#include <optional>
#include <ostream>
#include <string>
#include <utility>

#include "base/json/json_writer.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/values.h"
#include "components/sync/base/time.h"
#include "components/sync/protocol/proto_memory_estimations.h"
#include "components/sync/protocol/proto_value_conversions.h"

namespace syncer {

EntityData::EntityData() = default;

EntityData::EntityData(EntityData&& other) = default;

EntityData::~EntityData() = default;

EntityData& EntityData::operator=(EntityData&& other) = default;

base::Value::Dict EntityData::ToDictionaryValue() const {
  // This is used when debugging at sync-internals page. The code in
  // sync_node_browser.js is expecting certain fields names. e.g. CTIME, MTIME,
  // and IS_DIR.
  base::Value::Dict value =
      base::Value::Dict()
          .Set("SPECIFICS", EntitySpecificsToValue(specifics))
          .Set("ID", id)
          .Set("CLIENT_TAG_HASH", client_tag_hash.value())
          .Set("ORIGINATOR_CACHE_GUID", originator_cache_guid)
          .Set("ORIGINATOR_CLIENT_ITEM_ID", originator_client_item_id)
          .Set("SERVER_DEFINED_UNIQUE_TAG", server_defined_unique_tag)
          // The string "NON_UNIQUE_NAME" is used in sync-internals to identify
          // the node title.
          .Set("NON_UNIQUE_NAME", name)
          .Set("NAME", name)
          // The string "PARENT_ID" is used in sync-internals to build the node
          // tree.
          .Set("PARENT_ID", legacy_parent_id)
          .Set("CTIME", GetTimeDebugString(creation_time))
          .Set("MTIME", GetTimeDebugString(modification_time))
          .Set("RECIPIENT_PUBLIC_KEY",
               CrossUserSharingPublicKeyToValue(recipient_public_key));
  if (collaboration_metadata.has_value()) {
    value.Set("COLLABORATION_ID",
              collaboration_metadata->collaboration_id().value());
    value.Set("CREATED_BY", collaboration_metadata->created_by().ToString());
    value.Set("LAST_UPDATED_BY",
              collaboration_metadata->last_updated_by().ToString());
  }
  return value;
}

size_t EntityData::EstimateMemoryUsage() const {
  using base::trace_event::EstimateMemoryUsage;
  size_t memory_usage = 0;
  memory_usage += EstimateMemoryUsage(id);
  memory_usage += EstimateMemoryUsage(client_tag_hash);
  memory_usage += EstimateMemoryUsage(originator_cache_guid);
  memory_usage += EstimateMemoryUsage(originator_client_item_id);
  memory_usage += EstimateMemoryUsage(server_defined_unique_tag);
  memory_usage += EstimateMemoryUsage(name);
  memory_usage += EstimateMemoryUsage(specifics);
  memory_usage += EstimateMemoryUsage(legacy_parent_id);
  memory_usage += EstimateMemoryUsage(recipient_public_key);
  if (collaboration_metadata.has_value()) {
    memory_usage += EstimateMemoryUsage(collaboration_metadata.value());
  }
  if (deletion_origin.has_value()) {
    memory_usage += EstimateMemoryUsage(*deletion_origin);
  }
  return memory_usage;
}

void PrintTo(const EntityData& entity_data, std::ostream* os) {
  std::string specifics;
  base::JSONWriter::WriteWithOptions(
      syncer::EntitySpecificsToValue(entity_data.specifics),
      base::JSONWriter::OPTIONS_PRETTY_PRINT, &specifics);
  *os << "{ id: '" << entity_data.id << "', client_tag_hash: '"
      << entity_data.client_tag_hash << "', originator_cache_guid: '"
      << entity_data.originator_cache_guid << "', originator_client_item_id: '"
      << entity_data.originator_client_item_id
      << "', server_defined_unique_tag: '"
      << entity_data.server_defined_unique_tag << "', specifics: " << specifics;
  if (entity_data.collaboration_metadata.has_value()) {
    *os << ", collaboration_metadata: ";
    PrintTo(entity_data.collaboration_metadata.value(), os);
  }
  *os << "}";
}

}  // namespace syncer