entity_data.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_SYNC_PROTOCOL_ENTITY_DATA_H_
  5. #define COMPONENTS_SYNC_PROTOCOL_ENTITY_DATA_H_
  6. #include <iosfwd>
  7. #include <memory>
  8. #include <string>
  9. #include "base/time/time.h"
  10. #include "base/values.h"
  11. #include "components/sync/base/client_tag_hash.h"
  12. #include "components/sync/protocol/entity_specifics.pb.h"
  13. namespace base {
  14. class DictionaryValue;
  15. }
  16. namespace syncer {
  17. // A light-weight container for sync entity data which represents either
  18. // local data created on the local model side or remote data created on
  19. // ModelTypeWorker.
  20. // EntityData is supposed to be wrapped and passed by reference.
  21. struct EntityData {
  22. public:
  23. EntityData();
  24. EntityData& operator=(const EntityData&) = delete;
  25. EntityData(EntityData&&);
  26. EntityData& operator=(EntityData&&);
  27. ~EntityData();
  28. // Typically this is a server assigned sync ID, although for a local change
  29. // that represents a new entity this field might be either empty or contain
  30. // a temporary client sync ID.
  31. std::string id;
  32. // A hash based on the client tag and model type.
  33. // Used for various map lookups. Should always be available for all data types
  34. // except bookmarks. Sent to the server as
  35. // SyncEntity::client_defined_unique_tag.
  36. ClientTagHash client_tag_hash;
  37. // A GUID that identifies the the sync client who initially committed this
  38. // entity. It's relevant only for bookmarks. See the definition in sync.proto
  39. // for more details.
  40. std::string originator_cache_guid;
  41. // The local item id of this entry from the client that initially committed
  42. // this entity. It's relevant only for bookmarks. See the definition in
  43. // sync.proto for more details.
  44. std::string originator_client_item_id;
  45. // This tag identifies this item as being a uniquely instanced item. An item
  46. // can't have both a client_defined_unique_tag and a
  47. // server_defined_unique_tag. Sent to the server as
  48. // SyncEntity::server_defined_unique_tag.
  49. std::string server_defined_unique_tag;
  50. // Entity name, used mostly for Debug purposes.
  51. std::string name;
  52. // Model type specific sync data.
  53. sync_pb::EntitySpecifics specifics;
  54. // Entity creation and modification timestamps.
  55. base::Time creation_time;
  56. base::Time modification_time;
  57. // Server-provided sync ID of the parent entity, used for legacy bookmarks
  58. // only. Unused for modern data created or reuploaded by M94 or above, which
  59. // relies exclusively on the parent's GUID in BookmarkSpecifics.
  60. // WARNING: Avoid references to this field outside
  61. // components/sync_bookmarks/parent_guid_preprocessing.cc.
  62. std::string legacy_parent_id;
  63. // Indicate whether bookmark's |unique_position| was missing in the original
  64. // specifics during GetUpdates. If the |unique_position| in specifics was
  65. // evaluated by AdaptUniquePositionForBookmark(), this field will be set to
  66. // true. Relevant only for bookmarks.
  67. bool is_bookmark_unique_position_in_specifics_preprocessed = false;
  68. // True if EntityData represents deleted entity; otherwise false.
  69. // Note that EntityData would be considered to represent a deletion if its
  70. // specifics hasn't been set.
  71. bool is_deleted() const { return specifics.ByteSize() == 0; }
  72. // Dumps all info into a DictionaryValue and returns it.
  73. base::Value::Dict ToDictionaryValue();
  74. // Returns the estimate of dynamically allocated memory in bytes.
  75. size_t EstimateMemoryUsage() const;
  76. };
  77. // gMock printer helper.
  78. void PrintTo(const EntityData& entity_data, std::ostream* os);
  79. } // namespace syncer
  80. #endif // COMPONENTS_SYNC_PROTOCOL_ENTITY_DATA_H_