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
45 class SYNC_EXPORT Entry
{
47 // After constructing, you must check good() to test whether the Get
49 Entry(BaseTransaction
* trans
, GetByHandle
, int64 handle
);
50 Entry(BaseTransaction
* trans
, GetById
, const Id
& id
);
51 Entry(BaseTransaction
* trans
, GetByServerTag
, const std::string
& tag
);
52 Entry(BaseTransaction
* trans
, GetByClientTag
, const std::string
& tag
);
54 bool good() const { return 0 != kernel_
; }
56 BaseTransaction
* trans() const { return basetrans_
; }
59 int64
GetMetahandle() const {
61 return kernel_
->ref(META_HANDLE
);
64 int64
GetBaseVersion() const {
66 return kernel_
->ref(BASE_VERSION
);
69 int64
GetServerVersion() const {
71 return kernel_
->ref(SERVER_VERSION
);
74 int64
GetLocalExternalId() const {
76 return kernel_
->ref(LOCAL_EXTERNAL_ID
);
79 int64
GetTransactionVersion() const {
81 return kernel_
->ref(TRANSACTION_VERSION
);
84 const base::Time
& GetMtime() const {
86 return kernel_
->ref(MTIME
);
89 const base::Time
& GetServerMtime() const {
91 return kernel_
->ref(SERVER_MTIME
);
94 const base::Time
& GetCtime() const {
96 return kernel_
->ref(CTIME
);
99 const base::Time
& GetServerCtime() const {
101 return kernel_
->ref(SERVER_CTIME
);
106 return kernel_
->ref(ID
);
109 Id
GetParentId() const {
111 return kernel_
->ref(PARENT_ID
);
114 Id
GetServerParentId() const {
116 return kernel_
->ref(SERVER_PARENT_ID
);
119 bool GetIsUnsynced() const {
121 return kernel_
->ref(IS_UNSYNCED
);
124 bool GetIsUnappliedUpdate() const {
126 return kernel_
->ref(IS_UNAPPLIED_UPDATE
);
129 bool GetIsDel() const {
131 return kernel_
->ref(IS_DEL
);
134 bool GetIsDir() const {
136 return kernel_
->ref(IS_DIR
);
139 bool GetServerIsDir() const {
141 return kernel_
->ref(SERVER_IS_DIR
);
144 bool GetServerIsDel() const {
146 return kernel_
->ref(SERVER_IS_DEL
);
149 const std::string
& GetNonUniqueName() const {
151 return kernel_
->ref(NON_UNIQUE_NAME
);
154 const std::string
& GetServerNonUniqueName() const {
156 return kernel_
->ref(SERVER_NON_UNIQUE_NAME
);
159 const std::string
& GetUniqueServerTag() const {
161 return kernel_
->ref(UNIQUE_SERVER_TAG
);
164 const std::string
& GetUniqueClientTag() const {
166 return kernel_
->ref(UNIQUE_CLIENT_TAG
);
169 const std::string
& GetUniqueBookmarkTag() const {
171 return kernel_
->ref(UNIQUE_BOOKMARK_TAG
);
174 const sync_pb::EntitySpecifics
& GetSpecifics() const {
176 return kernel_
->ref(SPECIFICS
);
179 const sync_pb::EntitySpecifics
& GetServerSpecifics() const {
181 return kernel_
->ref(SERVER_SPECIFICS
);
184 const sync_pb::EntitySpecifics
& GetBaseServerSpecifics() const {
186 return kernel_
->ref(BASE_SERVER_SPECIFICS
);
189 const UniquePosition
& GetServerUniquePosition() const {
191 return kernel_
->ref(SERVER_UNIQUE_POSITION
);
194 const UniquePosition
& GetUniquePosition() const {
196 return kernel_
->ref(UNIQUE_POSITION
);
199 bool GetSyncing() const {
201 return kernel_
->ref(SYNCING
);
204 ModelType
GetServerModelType() const;
205 ModelType
GetModelType() const;
207 Id
GetPredecessorId() const;
208 Id
GetSuccessorId() const;
209 Id
GetFirstChildId() const;
210 int GetTotalNodeCount() const;
212 int GetPositionIndex() const;
214 // Returns a vector of this node's children's handles.
215 // Clears |result| if there are no children. If this node is of a type that
216 // supports user-defined ordering then the resulting vector will be in the
218 void GetChildHandles(std::vector
<int64
>* result
) const;
220 inline bool ExistsOnClientBecauseNameIsNonEmpty() const {
222 return !kernel_
->ref(NON_UNIQUE_NAME
).empty();
225 inline bool IsRoot() const {
227 return kernel_
->ref(ID
).IsRoot();
230 // Returns true if this is an entry that is expected to maintain a certain
231 // sort ordering relative to its siblings under the same parent.
232 bool ShouldMaintainPosition() const;
234 Directory
* dir() const;
236 const EntryKernel
GetKernelCopy() const {
240 // Dumps all entry info into a DictionaryValue and returns it.
241 // Transfers ownership of the DictionaryValue to the caller.
242 base::DictionaryValue
* ToValue(Cryptographer
* cryptographer
) const;
244 protected: // Don't allow creation on heap, except by sync API wrappers.
245 void* operator new(size_t size
) { return (::operator new)(size
); }
247 inline explicit Entry(BaseTransaction
* trans
)
252 BaseTransaction
* const basetrans_
;
254 EntryKernel
* kernel_
;
257 friend class Directory
;
258 friend class syncer::ReadNode
;
259 friend std::ostream
& operator << (std::ostream
& s
, const Entry
& e
);
261 DISALLOW_COPY_AND_ASSIGN(Entry
);
264 std::ostream
& operator<<(std::ostream
& os
, const Entry
& entry
);
266 } // namespace syncable
267 } // namespace syncer
269 #endif // SYNC_SYNCABLE_ENTRY_H_