OLD | NEW |
| (Empty) |
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 | |
5 #ifndef COMPONENTS_SYNC_API_ENTITY_DATA_H_ | |
6 #define COMPONENTS_SYNC_API_ENTITY_DATA_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/time/time.h" | |
15 #include "base/values.h" | |
16 #include "components/sync/base/proto_value_ptr.h" | |
17 #include "components/sync/protocol/sync.pb.h" | |
18 | |
19 namespace syncer { | |
20 | |
21 struct EntityData; | |
22 | |
23 struct EntityDataTraits { | |
24 static void SwapValue(EntityData* dest, EntityData* src); | |
25 static bool HasValue(const EntityData& value); | |
26 static const EntityData& DefaultValue(); | |
27 }; | |
28 | |
29 typedef ProtoValuePtr<EntityData, EntityDataTraits> EntityDataPtr; | |
30 typedef std::vector<EntityDataPtr> EntityDataList; | |
31 typedef std::map<std::string, EntityDataPtr> EntityDataMap; | |
32 | |
33 // A light-weight container for sync entity data which represents either | |
34 // local data created on the ModelTypeService side or remote data created | |
35 // on ModelTypeWorker. | |
36 // EntityData is supposed to be wrapped and passed by reference. | |
37 struct EntityData { | |
38 public: | |
39 EntityData(); | |
40 ~EntityData(); | |
41 | |
42 // Typically this is a server assigned sync ID, although for a local change | |
43 // that represents a new entity this field might be either empty or contain | |
44 // a temporary client sync ID. | |
45 std::string id; | |
46 | |
47 // A hash based on the client tag and model type. | |
48 // Used for various map lookups. Should always be available. | |
49 // Sent to the server as SyncEntity::client_defined_unique_tag. | |
50 std::string client_tag_hash; | |
51 | |
52 // Entity name, used mostly for Debug purposes. | |
53 std::string non_unique_name; | |
54 | |
55 // Model type specific sync data. | |
56 sync_pb::EntitySpecifics specifics; | |
57 | |
58 // Entity creation and modification timestamps. | |
59 base::Time creation_time; | |
60 base::Time modification_time; | |
61 | |
62 // Sync ID of the parent entity. This is supposed to be set only for | |
63 // hierarchical datatypes (e.g. Bookmarks). | |
64 std::string parent_id; | |
65 | |
66 // Unique position of an entity among its siblings. This is supposed to be | |
67 // set only for datatypes that support positioning (e.g. Bookmarks). | |
68 sync_pb::UniquePosition unique_position; | |
69 | |
70 // True if EntityData represents deleted entity; otherwise false. | |
71 // Note that EntityData would be considered to represent a deletion if its | |
72 // specifics hasn't been set. | |
73 bool is_deleted() const { return specifics.ByteSize() == 0; } | |
74 | |
75 // Transfers this struct's data to EntityDataPtr. | |
76 // The return value must be assigned into another EntityDataPtr. | |
77 EntityDataPtr PassToPtr() WARN_UNUSED_RESULT; | |
78 | |
79 // Dumps all info into a DictionaryValue and returns it. | |
80 std::unique_ptr<base::DictionaryValue> ToDictionaryValue(); | |
81 | |
82 private: | |
83 friend struct EntityDataTraits; | |
84 // Used to transfer the data without copying. | |
85 void Swap(EntityData* other); | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(EntityData); | |
88 }; | |
89 | |
90 } // namespace syncer | |
91 | |
92 #endif // COMPONENTS_SYNC_API_ENTITY_DATA_H_ | |
OLD | NEW |