OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_SYNCABLE_ENTRY_H_ | 5 #ifndef COMPONENTS_SYNC_SYNCABLE_ENTRY_H_ |
6 #define SYNC_SYNCABLE_ENTRY_H_ | 6 #define COMPONENTS_SYNC_SYNCABLE_ENTRY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "sync/base/sync_export.h" | 15 #include "components/sync/base/sync_export.h" |
16 #include "sync/syncable/entry_kernel.h" | 16 #include "components/sync/syncable/entry_kernel.h" |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 class Cryptographer; | 19 class Cryptographer; |
20 class ReadNode; | 20 class ReadNode; |
21 | 21 |
22 namespace syncable { | 22 namespace syncable { |
23 | 23 |
24 class Directory; | 24 class Directory; |
25 class BaseTransaction; | 25 class BaseTransaction; |
26 | 26 |
27 // A read-only meta entry | 27 // A read-only meta entry |
28 // Instead of: | 28 // Instead of: |
29 // Entry e = transaction.GetById(id); | 29 // Entry e = transaction.GetById(id); |
30 // use: | 30 // use: |
31 // Entry e(transaction, GET_BY_ID, id); | 31 // Entry e(transaction, GET_BY_ID, id); |
32 // | 32 // |
33 // Why? The former would require a copy constructor, and it would be difficult | 33 // Why? The former would require a copy constructor, and it would be difficult |
34 // to enforce that an entry never outlived its transaction if there were a copy | 34 // to enforce that an entry never outlived its transaction if there were a copy |
35 // constructor. | 35 // constructor. |
36 enum GetById { | 36 enum GetById { GET_BY_ID }; |
37 GET_BY_ID | |
38 }; | |
39 | 37 |
40 enum GetByClientTag { | 38 enum GetByClientTag { GET_BY_CLIENT_TAG }; |
41 GET_BY_CLIENT_TAG | |
42 }; | |
43 | 39 |
44 enum GetByServerTag { | 40 enum GetByServerTag { |
45 // Server tagged items are deprecated for all types but bookmarks. | 41 // Server tagged items are deprecated for all types but bookmarks. |
46 GET_BY_SERVER_TAG | 42 GET_BY_SERVER_TAG |
47 }; | 43 }; |
48 | 44 |
49 enum GetTypeRoot { | 45 enum GetTypeRoot { GET_TYPE_ROOT }; |
50 GET_TYPE_ROOT | |
51 }; | |
52 | 46 |
53 enum GetByHandle { | 47 enum GetByHandle { GET_BY_HANDLE }; |
54 GET_BY_HANDLE | |
55 }; | |
56 | 48 |
57 class SYNC_EXPORT Entry { | 49 class SYNC_EXPORT Entry { |
58 public: | 50 public: |
59 // After constructing, you must check good() to test whether the Get | 51 // After constructing, you must check good() to test whether the Get |
60 // succeeded. | 52 // succeeded. |
61 Entry(BaseTransaction* trans, GetByHandle, int64_t handle); | 53 Entry(BaseTransaction* trans, GetByHandle, int64_t handle); |
62 Entry(BaseTransaction* trans, GetById, const Id& id); | 54 Entry(BaseTransaction* trans, GetById, const Id& id); |
63 Entry(BaseTransaction* trans, GetTypeRoot, ModelType type); | 55 Entry(BaseTransaction* trans, GetTypeRoot, ModelType type); |
64 Entry(BaseTransaction* trans, GetByClientTag, const std::string& tag); | 56 Entry(BaseTransaction* trans, GetByClientTag, const std::string& tag); |
65 | 57 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Returns true if this is an entry that is expected to maintain a certain | 246 // Returns true if this is an entry that is expected to maintain a certain |
255 // sort ordering relative to its siblings under the same parent. | 247 // sort ordering relative to its siblings under the same parent. |
256 bool ShouldMaintainPosition() const; | 248 bool ShouldMaintainPosition() const; |
257 | 249 |
258 // Returns true if this is an entry that is expected to maintain hierarchy. | 250 // Returns true if this is an entry that is expected to maintain hierarchy. |
259 // ie. Whether or not the PARENT_ID field contains useful information. | 251 // ie. Whether or not the PARENT_ID field contains useful information. |
260 bool ShouldMaintainHierarchy() const; | 252 bool ShouldMaintainHierarchy() const; |
261 | 253 |
262 Directory* dir() const; | 254 Directory* dir() const; |
263 | 255 |
264 const EntryKernel GetKernelCopy() const { | 256 const EntryKernel GetKernelCopy() const { return *kernel_; } |
265 return *kernel_; | |
266 } | |
267 | 257 |
268 // Dumps all entry info into a DictionaryValue and returns it. | 258 // Dumps all entry info into a DictionaryValue and returns it. |
269 // Transfers ownership of the DictionaryValue to the caller. | 259 // Transfers ownership of the DictionaryValue to the caller. |
270 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; | 260 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; |
271 | 261 |
272 protected: // Don't allow creation on heap, except by sync API wrappers. | 262 protected: // Don't allow creation on heap, except by sync API wrappers. |
273 void* operator new(size_t size) { return (::operator new)(size); } | 263 void* operator new(size_t size) { return (::operator new)(size); } |
274 | 264 |
275 inline explicit Entry(BaseTransaction* trans) | 265 inline explicit Entry(BaseTransaction* trans) |
276 : basetrans_(trans), | 266 : basetrans_(trans), kernel_(NULL) {} |
277 kernel_(NULL) { } | |
278 | 267 |
279 protected: | 268 protected: |
280 BaseTransaction* const basetrans_; | 269 BaseTransaction* const basetrans_; |
281 | 270 |
282 EntryKernel* kernel_; | 271 EntryKernel* kernel_; |
283 | 272 |
284 private: | 273 private: |
285 friend class Directory; | 274 friend class Directory; |
286 friend class syncer::ReadNode; | 275 friend class syncer::ReadNode; |
287 friend std::ostream& operator << (std::ostream& s, const Entry& e); | 276 friend std::ostream& operator<<(std::ostream& s, const Entry& e); |
288 | 277 |
289 DISALLOW_COPY_AND_ASSIGN(Entry); | 278 DISALLOW_COPY_AND_ASSIGN(Entry); |
290 }; | 279 }; |
291 | 280 |
292 std::ostream& operator<<(std::ostream& os, const Entry& entry); | 281 std::ostream& operator<<(std::ostream& os, const Entry& entry); |
293 | 282 |
294 } // namespace syncable | 283 } // namespace syncable |
295 } // namespace syncer | 284 } // namespace syncer |
296 | 285 |
297 #endif // SYNC_SYNCABLE_ENTRY_H_ | 286 #endif // COMPONENTS_SYNC_SYNCABLE_ENTRY_H_ |
OLD | NEW |