OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_SYNC_CORE_READ_NODE_H_ | |
6 #define COMPONENTS_SYNC_CORE_READ_NODE_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <string> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/macros.h" | |
15 #include "components/sync/base/model_type.h" | |
16 #include "components/sync/core/base_node.h" | |
17 | |
18 namespace syncer { | |
19 | |
20 // ReadNode wraps a syncable::Entry to provide the functionality of a | |
21 // read-only BaseNode. | |
22 class ReadNode : public BaseNode { | |
23 public: | |
24 // Create an unpopulated ReadNode on the given transaction. Call some flavor | |
25 // of Init to populate the ReadNode with a database entry. | |
26 explicit ReadNode(const BaseTransaction* transaction); | |
27 ~ReadNode() override; | |
28 | |
29 // A client must use one (and only one) of the following Init variants to | |
30 // populate the node. | |
31 | |
32 // BaseNode implementation. | |
33 InitByLookupResult InitByIdLookup(int64_t id) override; | |
34 InitByLookupResult InitByClientTagLookup(ModelType model_type, | |
35 const std::string& tag) override; | |
36 | |
37 // There is always a root node, so this can't fail. The root node is | |
38 // never mutable, so root lookup is only possible on a ReadNode. | |
39 void InitByRootLookup(); | |
40 | |
41 // Returns the type root node, if it exists. This is usually created by the | |
42 // server during first sync. Eventually, we plan to remove support for it | |
43 // from the protocol and have the client create the node instead. | |
44 InitByLookupResult InitTypeRoot(ModelType type); | |
45 | |
46 // Returns a server-created and unique-server-tagged item. | |
47 // | |
48 // This functionality is only useful for bookmarks because only bookmarks | |
49 // have server-tagged items. All other server-tagged items are type root | |
50 // nodes, which should be looked up with InitTypeRoot(). | |
51 InitByLookupResult InitByTagLookupForBookmarks(const std::string& tag); | |
52 | |
53 // Returns transaction version of the last transaction where this node has | |
54 // been modified. | |
55 int64_t GetTransactionVersion() const; | |
56 | |
57 // Implementation of BaseNode's abstract virtual accessors. | |
58 const syncable::Entry* GetEntry() const override; | |
59 const BaseTransaction* GetTransaction() const override; | |
60 | |
61 protected: | |
62 ReadNode(); | |
63 | |
64 private: | |
65 void* operator new(size_t size); // Node is meant for stack use only. | |
66 | |
67 // The underlying syncable object which this class wraps. | |
68 syncable::Entry* entry_; | |
69 | |
70 // The sync API transaction that is the parent of this node. | |
71 const BaseTransaction* transaction_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ReadNode); | |
74 }; | |
75 | |
76 } // namespace syncer | |
77 | |
78 #endif // COMPONENTS_SYNC_CORE_READ_NODE_H_ | |
OLD | NEW |