1 // Copyright 2012 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.
5 #ifndef SYNC_SYNCABLE_ENTRY_H_
6 #define SYNC_SYNCABLE_ENTRY_H_
8 #include "sync/base/sync_export.h"
9 #include "sync/syncable/entry_kernel.h"
18 class BaseTransaction
;
20 // A read-only meta entry
22 // Entry e = transaction.GetById(id);
24 // Entry e(transaction, GET_BY_ID, id);
26 // Why? The former would require a copy constructor, and it would be difficult
27 // to enforce that an entry never outlived its transaction if there were a copy
38 // Server tagged items are deprecated for all types but bookmarks.
50 class SYNC_EXPORT Entry
{
52 // After constructing, you must check good() to test whether the Get
54 Entry(BaseTransaction
* trans
, GetByHandle
, int64 handle
);
55 Entry(BaseTransaction
* trans
, GetById
, const Id
& id
);
56 Entry(BaseTransaction
* trans
, GetTypeRoot
, ModelType type
);
57 Entry(BaseTransaction
* trans
, GetByClientTag
, const std::string
& tag
);
59 // This lookup function is deprecated. All types except bookmarks can use
60 // the GetTypeRoot variant instead.
61 Entry(BaseTransaction
* trans
, GetByServerTag
, const std::string
& tag
);
63 bool good() const { return 0 != kernel_
; }
65 BaseTransaction
* trans() const { return basetrans_
; }
68 int64
GetMetahandle() const {
70 return kernel_
->ref(META_HANDLE
);
73 int64
GetBaseVersion() const {
75 return kernel_
->ref(BASE_VERSION
);
78 int64
GetServerVersion() const {
80 return kernel_
->ref(SERVER_VERSION
);
83 int64
GetLocalExternalId() const {
85 return kernel_
->ref(LOCAL_EXTERNAL_ID
);
88 int64
GetTransactionVersion() const {
90 return kernel_
->ref(TRANSACTION_VERSION
);
93 const base::Time
& GetMtime() const {
95 return kernel_
->ref(MTIME
);
98 const base::Time
& GetServerMtime() const {
100 return kernel_
->ref(SERVER_MTIME
);
103 const base::Time
& GetCtime() const {
105 return kernel_
->ref(CTIME
);
108 const base::Time
& GetServerCtime() const {
110 return kernel_
->ref(SERVER_CTIME
);
115 return kernel_
->ref(ID
);
118 Id
GetParentId() const {
120 return kernel_
->ref(PARENT_ID
);
123 Id
GetServerParentId() const {
125 return kernel_
->ref(SERVER_PARENT_ID
);
128 bool GetIsUnsynced() const {
130 return kernel_
->ref(IS_UNSYNCED
);
133 bool GetIsUnappliedUpdate() const {
135 return kernel_
->ref(IS_UNAPPLIED_UPDATE
);
138 bool GetIsDel() const {
140 return kernel_
->ref(IS_DEL
);
143 bool GetIsDir() const {
145 return kernel_
->ref(IS_DIR
);
148 bool GetServerIsDir() const {
150 return kernel_
->ref(SERVER_IS_DIR
);
153 bool GetServerIsDel() const {
155 return kernel_
->ref(SERVER_IS_DEL
);
158 const std::string
& GetNonUniqueName() const {
160 return kernel_
->ref(NON_UNIQUE_NAME
);
163 const std::string
& GetServerNonUniqueName() const {
165 return kernel_
->ref(SERVER_NON_UNIQUE_NAME
);
168 const std::string
& GetUniqueServerTag() const {
170 return kernel_
->ref(UNIQUE_SERVER_TAG
);
173 const std::string
& GetUniqueClientTag() const {
175 return kernel_
->ref(UNIQUE_CLIENT_TAG
);
178 const std::string
& GetUniqueBookmarkTag() const {
180 return kernel_
->ref(UNIQUE_BOOKMARK_TAG
);
183 const sync_pb::EntitySpecifics
& GetSpecifics() const {
185 return kernel_
->ref(SPECIFICS
);
188 const sync_pb::EntitySpecifics
& GetServerSpecifics() const {
190 return kernel_
->ref(SERVER_SPECIFICS
);
193 const sync_pb::EntitySpecifics
& GetBaseServerSpecifics() const {
195 return kernel_
->ref(BASE_SERVER_SPECIFICS
);
198 const UniquePosition
& GetServerUniquePosition() const {
200 return kernel_
->ref(SERVER_UNIQUE_POSITION
);
203 const UniquePosition
& GetUniquePosition() const {
205 return kernel_
->ref(UNIQUE_POSITION
);
208 const sync_pb::AttachmentMetadata
& GetAttachmentMetadata() const {
210 return kernel_
->ref(ATTACHMENT_METADATA
);
213 const sync_pb::AttachmentMetadata
& GetServerAttachmentMetadata() const {
215 return kernel_
->ref(SERVER_ATTACHMENT_METADATA
);
218 bool GetSyncing() const;
219 bool GetDirtySync() const ;
221 ModelType
GetServerModelType() const;
222 ModelType
GetModelType() const;
224 Id
GetPredecessorId() const;
225 Id
GetSuccessorId() const;
226 Id
GetFirstChildId() const;
227 int GetTotalNodeCount() const;
229 int GetPositionIndex() const;
231 // Returns a vector of this node's children's handles.
232 // Clears |result| if there are no children. If this node is of a type that
233 // supports user-defined ordering then the resulting vector will be in the
235 void GetChildHandles(std::vector
<int64
>* result
) const;
237 inline bool ExistsOnClientBecauseNameIsNonEmpty() const {
239 return !kernel_
->ref(NON_UNIQUE_NAME
).empty();
242 inline bool IsRoot() const {
244 return kernel_
->ref(ID
).IsRoot();
247 // Returns true if this is an entry that is expected to maintain a certain
248 // sort ordering relative to its siblings under the same parent.
249 bool ShouldMaintainPosition() const;
251 // Returns true if this is an entry that is expected to maintain hierarchy.
252 // ie. Whether or not the PARENT_ID field contains useful information.
253 bool ShouldMaintainHierarchy() const;
255 Directory
* dir() const;
257 const EntryKernel
GetKernelCopy() const {
261 // Dumps all entry info into a DictionaryValue and returns it.
262 // Transfers ownership of the DictionaryValue to the caller.
263 base::DictionaryValue
* ToValue(Cryptographer
* cryptographer
) const;
265 protected: // Don't allow creation on heap, except by sync API wrappers.
266 void* operator new(size_t size
) { return (::operator new)(size
); }
268 inline explicit Entry(BaseTransaction
* trans
)
273 BaseTransaction
* const basetrans_
;
275 EntryKernel
* kernel_
;
278 friend class Directory
;
279 friend class syncer::ReadNode
;
280 friend std::ostream
& operator << (std::ostream
& s
, const Entry
& e
);
282 DISALLOW_COPY_AND_ASSIGN(Entry
);
285 std::ostream
& operator<<(std::ostream
& os
, const Entry
& entry
);
287 } // namespace syncable
288 } // namespace syncer
290 #endif // SYNC_SYNCABLE_ENTRY_H_