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