Infobar material design refresh: bg color
[chromium-blink-merge.git] / sync / internal_api / public / write_node.h
blobb79ae30d97b7321073acfc1da1085e64795d7347
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_WRITE_NODE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "sync/base/sync_export.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base_node.h"
17 namespace sync_pb {
18 class BookmarkSpecifics;
19 class EntitySpecifics;
20 class NigoriSpecifics;
21 class PasswordSpecificsData;
22 class TypedUrlSpecifics;
25 namespace syncer {
27 class Cryptographer;
28 class WriteTransaction;
30 namespace syncable {
31 class Id;
32 class Entry;
33 class MutableEntry;
36 // WriteNode extends BaseNode to add mutation, and wraps
37 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
38 class SYNC_EXPORT WriteNode : public BaseNode {
39 public:
40 enum InitUniqueByCreationResult {
41 INIT_SUCCESS,
42 // The tag passed into this method was empty.
43 INIT_FAILED_EMPTY_TAG,
44 // The constructor for a new MutableEntry with the specified data failed.
45 INIT_FAILED_COULD_NOT_CREATE_ENTRY,
46 // Setting the predecessor failed
47 INIT_FAILED_SET_PREDECESSOR,
50 // Create a WriteNode using the given transaction.
51 explicit WriteNode(WriteTransaction* transaction);
52 ~WriteNode() override;
54 // A client must use one (and only one) of the following Init variants to
55 // populate the node.
57 // BaseNode implementation.
58 InitByLookupResult InitByIdLookup(int64 id) override;
59 InitByLookupResult InitByClientTagLookup(ModelType model_type,
60 const std::string& tag) override;
62 // Create a new bookmark node with the specified parent and predecessor. Use
63 // a NULL |predecessor| to indicate that this is to be the first child.
64 // |predecessor| must be a child of |new_parent| or NULL. Returns false on
65 // failure.
66 bool InitBookmarkByCreation(const BaseNode& parent,
67 const BaseNode* predecessor);
69 // Create nodes using this function if they're unique items that
70 // you want to fetch using client_tag. Note that the behavior of these
71 // items is slightly different than that of normal items.
72 // Most importantly, if it exists locally but is deleted, this function will
73 // actually undelete it. Otherwise it will reuse the existing node.
74 // Client unique tagged nodes must NOT be folders.
75 InitUniqueByCreationResult InitUniqueByCreation(
76 ModelType model_type,
77 const BaseNode& parent,
78 const std::string& client_tag);
80 // InitUniqueByCreation overload for model types without hierarchy.
81 // The parent node isn't stored but is assumed to be the type root folder.
82 InitUniqueByCreationResult InitUniqueByCreation(
83 ModelType model_type,
84 const std::string& client_tag);
86 // Looks up the type's root folder. This is usually created by the sync
87 // server during initial sync, though we do eventually wish to remove it from
88 // the protocol and have the client "fake it" instead.
89 InitByLookupResult InitTypeRoot(ModelType type);
91 // These Set() functions correspond to the Get() functions of BaseNode.
92 void SetIsFolder(bool folder);
93 void SetTitle(const std::string& title);
95 // External ID is a client-only field, so setting it doesn't cause the item to
96 // be synced again.
97 void SetExternalId(int64 external_id);
99 // Remove this node and its children and sync deletion to server.
100 void Tombstone();
102 // If the node is known by server, remove it and its children but don't sync
103 // deletion to server. Do nothing if the node is not known by server so that
104 // server can have a record of the node.
105 void Drop();
107 // Set a new parent and position. Position is specified by |predecessor|; if
108 // it is NULL, the node is moved to the first position. |predecessor| must
109 // be a child of |new_parent| or NULL. Returns false on failure..
110 bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
112 // Set the bookmark specifics (url and favicon).
113 // Should only be called if GetModelType() == BOOKMARK.
114 void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
116 // Generic set specifics method. Will extract the model type from |specifics|.
117 void SetEntitySpecifics(const sync_pb::EntitySpecifics& specifics);
119 // Resets the EntitySpecifics for this node based on the unencrypted data.
120 // Will encrypt if necessary.
121 void ResetFromSpecifics();
123 // TODO(sync): Remove the setters below when the corresponding data
124 // types are ported to the new sync service API.
126 // Set the nigori specifics.
127 // Should only be called if GetModelType() == NIGORI.
128 void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
130 // Set the password specifics.
131 // Should only be called if GetModelType() == PASSWORD.
132 void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
134 // Set the typed_url specifics (url, title, typed_count, etc).
135 // Should only be called if GetModelType() == TYPED_URLS.
136 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
138 // Set the attachment metadata.
139 void SetAttachmentMetadata(
140 const sync_pb::AttachmentMetadata& attachment_metadata);
142 // Implementation of BaseNode's abstract virtual accessors.
143 const syncable::Entry* GetEntry() const override;
145 const BaseTransaction* GetTransaction() const override;
147 syncable::MutableEntry* GetMutableEntryForTest();
149 private:
150 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, EncryptBookmarksWithLegacyData);
152 void* operator new(size_t size); // Node is meant for stack use only.
154 InitUniqueByCreationResult InitUniqueByCreationImpl(
155 ModelType model_type,
156 const syncable::Id& parent_id,
157 const std::string& client_tag);
159 // Helper to set the previous node.
160 bool PutPredecessor(const BaseNode* predecessor) WARN_UNUSED_RESULT;
162 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
163 // upcoming commit pass.
164 void MarkForSyncing();
166 // The underlying syncable object which this class wraps.
167 syncable::MutableEntry* entry_;
169 // The sync API transaction that is the parent of this node.
170 WriteTransaction* transaction_;
172 DISALLOW_COPY_AND_ASSIGN(WriteNode);
175 } // namespace syncer
177 #endif // SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_