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 inline int64
Get(MetahandleField field
) const {
61 return kernel_
->ref(field
);
63 inline Id
Get(IdField field
) const {
65 return kernel_
->ref(field
);
67 inline int64
Get(Int64Field field
) const {
69 return kernel_
->ref(field
);
71 inline const base::Time
& Get(TimeField field
) const {
73 return kernel_
->ref(field
);
75 inline int64
Get(BaseVersion field
) const {
77 return kernel_
->ref(field
);
79 inline bool Get(IndexedBitField field
) const {
81 return kernel_
->ref(field
);
83 inline bool Get(IsDelField field
) const {
85 return kernel_
->ref(field
);
87 inline bool Get(BitField field
) const {
89 return kernel_
->ref(field
);
91 const std::string
& Get(StringField field
) const;
92 inline const sync_pb::EntitySpecifics
& Get(ProtoField field
) const {
94 return kernel_
->ref(field
);
96 inline const UniquePosition
& Get(UniquePositionField field
) const {
98 return kernel_
->ref(field
);
100 inline bool Get(BitTemp field
) const {
102 return kernel_
->ref(field
);
105 ModelType
GetServerModelType() const;
106 ModelType
GetModelType() const;
108 Id
GetPredecessorId() const;
109 Id
GetSuccessorId() const;
110 Id
GetFirstChildId() const;
112 inline bool ExistsOnClientBecauseNameIsNonEmpty() const {
114 return !kernel_
->ref(NON_UNIQUE_NAME
).empty();
117 inline bool IsRoot() const {
119 return kernel_
->ref(ID
).IsRoot();
122 // Returns true if this is an entry that is expected to maintain a certain
123 // sort ordering relative to its siblings under the same parent.
124 bool ShouldMaintainPosition() const;
126 Directory
* dir() const;
128 const EntryKernel
GetKernelCopy() const {
132 // Dumps all entry info into a DictionaryValue and returns it.
133 // Transfers ownership of the DictionaryValue to the caller.
134 base::DictionaryValue
* ToValue(Cryptographer
* cryptographer
) const;
136 protected: // Don't allow creation on heap, except by sync API wrappers.
137 void* operator new(size_t size
) { return (::operator new)(size
); }
139 inline explicit Entry(BaseTransaction
* trans
)
144 BaseTransaction
* const basetrans_
;
146 EntryKernel
* kernel_
;
149 friend class Directory
;
150 friend class syncer::ReadNode
;
151 friend std::ostream
& operator << (std::ostream
& s
, const Entry
& e
);
153 DISALLOW_COPY_AND_ASSIGN(Entry
);
156 std::ostream
& operator<<(std::ostream
& os
, const Entry
& entry
);
158 } // namespace syncable
159 } // namespace syncer
161 #endif // SYNC_SYNCABLE_ENTRY_H_