Fix build break
[chromium-blink-merge.git] / sync / syncable / entry.h
blobf9d3f90cc97bef33414c8d690f89b0bec246ad53
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"
11 namespace syncer {
12 class Cryptographer;
13 class ReadNode;
15 namespace syncable {
17 class Directory;
18 class BaseTransaction;
20 // A read-only meta entry
21 // Instead of:
22 // Entry e = transaction.GetById(id);
23 // use:
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
28 // constructor.
29 enum GetById {
30 GET_BY_ID
33 enum GetByClientTag {
34 GET_BY_CLIENT_TAG
37 enum GetByServerTag {
38 GET_BY_SERVER_TAG
41 enum GetByHandle {
42 GET_BY_HANDLE
45 class SYNC_EXPORT Entry {
46 public:
47 // After constructing, you must check good() to test whether the Get
48 // succeeded.
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_; }
58 // Field accessors.
59 inline int64 Get(MetahandleField field) const {
60 DCHECK(kernel_);
61 return kernel_->ref(field);
63 inline Id Get(IdField field) const {
64 DCHECK(kernel_);
65 return kernel_->ref(field);
67 inline int64 Get(Int64Field field) const {
68 DCHECK(kernel_);
69 return kernel_->ref(field);
71 inline const base::Time& Get(TimeField field) const {
72 DCHECK(kernel_);
73 return kernel_->ref(field);
75 inline int64 Get(BaseVersion field) const {
76 DCHECK(kernel_);
77 return kernel_->ref(field);
79 inline bool Get(IndexedBitField field) const {
80 DCHECK(kernel_);
81 return kernel_->ref(field);
83 inline bool Get(IsDelField field) const {
84 DCHECK(kernel_);
85 return kernel_->ref(field);
87 inline bool Get(BitField field) const {
88 DCHECK(kernel_);
89 return kernel_->ref(field);
91 const std::string& Get(StringField field) const;
92 inline const sync_pb::EntitySpecifics& Get(ProtoField field) const {
93 DCHECK(kernel_);
94 return kernel_->ref(field);
96 inline const UniquePosition& Get(UniquePositionField field) const {
97 DCHECK(kernel_);
98 return kernel_->ref(field);
100 inline bool Get(BitTemp field) const {
101 DCHECK(kernel_);
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 {
113 DCHECK(kernel_);
114 return !kernel_->ref(NON_UNIQUE_NAME).empty();
117 inline bool IsRoot() const {
118 DCHECK(kernel_);
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 {
129 return *kernel_;
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)
140 : basetrans_(trans),
141 kernel_(NULL) { }
143 protected:
144 BaseTransaction* const basetrans_;
146 EntryKernel* kernel_;
148 private:
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_