Fix for browser_plugin_host_browsertest when embedder is not yet available.
[chromium-blink-merge.git] / sync / syncable / entry.h
blob09ff9c7004f252e839734c84d96747417d254293
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 int64 GetMetahandle() const {
60 DCHECK(kernel_);
61 return kernel_->ref(META_HANDLE);
64 int64 GetBaseVersion() const {
65 DCHECK(kernel_);
66 return kernel_->ref(BASE_VERSION);
69 int64 GetServerVersion() const {
70 DCHECK(kernel_);
71 return kernel_->ref(SERVER_VERSION);
74 int64 GetLocalExternalId() const {
75 DCHECK(kernel_);
76 return kernel_->ref(LOCAL_EXTERNAL_ID);
79 int64 GetTransactionVersion() const {
80 DCHECK(kernel_);
81 return kernel_->ref(TRANSACTION_VERSION);
84 const base::Time& GetMtime() const {
85 DCHECK(kernel_);
86 return kernel_->ref(MTIME);
89 const base::Time& GetServerMtime() const {
90 DCHECK(kernel_);
91 return kernel_->ref(SERVER_MTIME);
94 const base::Time& GetCtime() const {
95 DCHECK(kernel_);
96 return kernel_->ref(CTIME);
99 const base::Time& GetServerCtime() const {
100 DCHECK(kernel_);
101 return kernel_->ref(SERVER_CTIME);
104 Id GetId() const {
105 DCHECK(kernel_);
106 return kernel_->ref(ID);
109 Id GetParentId() const {
110 DCHECK(kernel_);
111 return kernel_->ref(PARENT_ID);
114 Id GetServerParentId() const {
115 DCHECK(kernel_);
116 return kernel_->ref(SERVER_PARENT_ID);
119 bool GetIsUnsynced() const {
120 DCHECK(kernel_);
121 return kernel_->ref(IS_UNSYNCED);
124 bool GetIsUnappliedUpdate() const {
125 DCHECK(kernel_);
126 return kernel_->ref(IS_UNAPPLIED_UPDATE);
129 bool GetIsDel() const {
130 DCHECK(kernel_);
131 return kernel_->ref(IS_DEL);
134 bool GetIsDir() const {
135 DCHECK(kernel_);
136 return kernel_->ref(IS_DIR);
139 bool GetServerIsDir() const {
140 DCHECK(kernel_);
141 return kernel_->ref(SERVER_IS_DIR);
144 bool GetServerIsDel() const {
145 DCHECK(kernel_);
146 return kernel_->ref(SERVER_IS_DEL);
149 const std::string& GetNonUniqueName() const {
150 DCHECK(kernel_);
151 return kernel_->ref(NON_UNIQUE_NAME);
154 const std::string& GetServerNonUniqueName() const {
155 DCHECK(kernel_);
156 return kernel_->ref(SERVER_NON_UNIQUE_NAME);
159 const std::string& GetUniqueServerTag() const {
160 DCHECK(kernel_);
161 return kernel_->ref(UNIQUE_SERVER_TAG);
164 const std::string& GetUniqueClientTag() const {
165 DCHECK(kernel_);
166 return kernel_->ref(UNIQUE_CLIENT_TAG);
169 const std::string& GetUniqueBookmarkTag() const {
170 DCHECK(kernel_);
171 return kernel_->ref(UNIQUE_BOOKMARK_TAG);
174 const sync_pb::EntitySpecifics& GetSpecifics() const {
175 DCHECK(kernel_);
176 return kernel_->ref(SPECIFICS);
179 const sync_pb::EntitySpecifics& GetServerSpecifics() const {
180 DCHECK(kernel_);
181 return kernel_->ref(SERVER_SPECIFICS);
184 const sync_pb::EntitySpecifics& GetBaseServerSpecifics() const {
185 DCHECK(kernel_);
186 return kernel_->ref(BASE_SERVER_SPECIFICS);
189 const UniquePosition& GetServerUniquePosition() const {
190 DCHECK(kernel_);
191 return kernel_->ref(SERVER_UNIQUE_POSITION);
194 const UniquePosition& GetUniquePosition() const {
195 DCHECK(kernel_);
196 return kernel_->ref(UNIQUE_POSITION);
199 bool GetSyncing() const {
200 DCHECK(kernel_);
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
217 // proper order.
218 void GetChildHandles(std::vector<int64>* result) const;
220 inline bool ExistsOnClientBecauseNameIsNonEmpty() const {
221 DCHECK(kernel_);
222 return !kernel_->ref(NON_UNIQUE_NAME).empty();
225 inline bool IsRoot() const {
226 DCHECK(kernel_);
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 {
237 return *kernel_;
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)
248 : basetrans_(trans),
249 kernel_(NULL) { }
251 protected:
252 BaseTransaction* const basetrans_;
254 EntryKernel* kernel_;
256 private:
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_