File: sync_data.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (98 lines) | stat: -rw-r--r-- 3,306 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
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_MODEL_SYNC_DATA_H_
#define COMPONENTS_SYNC_MODEL_SYNC_DATA_H_

#include <iosfwd>
#include <string>
#include <string_view>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"

namespace sync_pb {
class EntitySpecifics;
}  // namespace sync_pb

namespace syncer {

// A light-weight container for immutable sync data. Pass-by-value and storage
// in STL containers are supported and encouraged if helpful.
class SyncData {
 public:
  // Creates an empty and invalid SyncData.
  SyncData();

  // Copyable and movable, all cheap.
  SyncData(const SyncData& other);
  SyncData(SyncData&& other);
  SyncData& operator=(const SyncData& other);
  SyncData& operator=(SyncData&& other);

  ~SyncData();

  // Helper methods for creating SyncData objects for local data.
  //
  // `client_tag_unhashed` Must be a non-empty string unique to this entity and
  // is used (in hashed form) as a node identifier server-side.
  //
  // For deletes: `datatype` must specify the datatype who node is being
  // deleted.
  //
  // For adds/updates: `specifics` must be valid and `non_unique_title` (can be
  // the same as `client_tag_unhashed`) must be specified.  Note:
  // `non_unique_title` is primarily for debug purposes, and will be overwritten
  // if the datatype is encrypted.
  static SyncData CreateLocalDelete(std::string_view client_tag_unhashed,
                                    DataType datatype);
  static SyncData CreateLocalData(std::string_view client_tag_unhashed,
                                  std::string_view non_unique_title,
                                  const sync_pb::EntitySpecifics& specifics);

  // Helper method for creating SyncData objects originating from the syncer.
  static SyncData CreateRemoteData(sync_pb::EntitySpecifics specifics,
                                   const ClientTagHash& client_tag_hash);

  // Whether this SyncData holds valid data. An instance can be invalid either
  // if the default value was used upon construction or if an instance was moved
  // away.
  bool IsValid() const;

  // Return the datatype we're holding information about. Derived from the sync
  // datatype specifics.
  DataType GetDataType() const;

  // Return the value of the unique client tag hash.
  ClientTagHash GetClientTagHash() const;

  // Return the current sync datatype specifics.
  const sync_pb::EntitySpecifics& GetSpecifics() const;

  // Return the non unique title (for debugging). Currently only set for data
  // going TO the syncer, not from.
  const std::string& GetTitle() const;

  std::string ToString() const;

 private:
  // Forward-declared to avoid includes for EntitySpecifics.
  struct InternalData;

  // Null if data invalid, i.e. default constructor used or moved-away instance.
  scoped_refptr<InternalData> ptr_;

  explicit SyncData(scoped_refptr<InternalData> ptr);
};

// gmock printer helper.
void PrintTo(const SyncData& sync_data, std::ostream* os);

using SyncDataList = std::vector<SyncData>;

}  // namespace syncer

#endif  // COMPONENTS_SYNC_MODEL_SYNC_DATA_H_