Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: sync/internal_api/public/write_node.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <string>
12 #include <vector>
13
14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h"
17 #include "sync/base/sync_export.h"
18 #include "sync/internal_api/public/base/model_type.h"
19 #include "sync/internal_api/public/base_node.h"
20
21 namespace sync_pb {
22 class BookmarkSpecifics;
23 class EntitySpecifics;
24 class NigoriSpecifics;
25 class PasswordSpecificsData;
26 class TypedUrlSpecifics;
27 }
28
29 namespace syncer {
30
31 class Cryptographer;
32 class WriteTransaction;
33
34 namespace syncable {
35 class Id;
36 class Entry;
37 class MutableEntry;
38 }
39
40 // WriteNode extends BaseNode to add mutation, and wraps
41 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
42 class SYNC_EXPORT WriteNode : public BaseNode {
43 public:
44 enum InitUniqueByCreationResult {
45 INIT_SUCCESS,
46 // The tag passed into this method was empty.
47 INIT_FAILED_EMPTY_TAG,
48 // The constructor for a new MutableEntry with the specified data failed.
49 INIT_FAILED_COULD_NOT_CREATE_ENTRY,
50 // Setting the predecessor failed
51 INIT_FAILED_SET_PREDECESSOR,
52 // Found existing entry, but was unable to decrypt.
53 INIT_FAILED_DECRYPT_EXISTING_ENTRY,
54 };
55
56 // Create a WriteNode using the given transaction.
57 explicit WriteNode(WriteTransaction* transaction);
58 ~WriteNode() override;
59
60 // A client must use one (and only one) of the following Init variants to
61 // populate the node.
62
63 // BaseNode implementation.
64 InitByLookupResult InitByIdLookup(int64_t id) override;
65 InitByLookupResult InitByClientTagLookup(ModelType model_type,
66 const std::string& tag) override;
67
68 // Create a new bookmark node with the specified parent and predecessor. Use
69 // a NULL |predecessor| to indicate that this is to be the first child.
70 // |predecessor| must be a child of |new_parent| or NULL. Returns false on
71 // failure.
72 bool InitBookmarkByCreation(const BaseNode& parent,
73 const BaseNode* predecessor);
74
75 // Create nodes using this function if they're unique items that
76 // you want to fetch using client_tag. Note that the behavior of these
77 // items is slightly different than that of normal items.
78 // Most importantly, if it exists locally but is deleted, this function will
79 // actually undelete it. Otherwise it will reuse the existing node.
80 // Client unique tagged nodes must NOT be folders.
81 InitUniqueByCreationResult InitUniqueByCreation(
82 ModelType model_type,
83 const BaseNode& parent,
84 const std::string& client_tag);
85
86 // InitUniqueByCreation overload for model types without hierarchy.
87 // The parent node isn't stored but is assumed to be the type root folder.
88 InitUniqueByCreationResult InitUniqueByCreation(
89 ModelType model_type,
90 const std::string& client_tag);
91
92 // Looks up the type's root folder. This is usually created by the sync
93 // server during initial sync, though we do eventually wish to remove it from
94 // the protocol and have the client "fake it" instead.
95 InitByLookupResult InitTypeRoot(ModelType type);
96
97 // These Set() functions correspond to the Get() functions of BaseNode.
98 void SetIsFolder(bool folder);
99 void SetTitle(const std::string& title);
100
101 // External ID is a client-only field, so setting it doesn't cause the item to
102 // be synced again.
103 void SetExternalId(int64_t external_id);
104
105 // Remove this node and its children and sync deletion to server.
106 void Tombstone();
107
108 // If the node is known by server, remove it and its children but don't sync
109 // deletion to server. Do nothing if the node is not known by server so that
110 // server can have a record of the node.
111 void Drop();
112
113 // Set a new parent and position. Position is specified by |predecessor|; if
114 // it is NULL, the node is moved to the first position. |predecessor| must
115 // be a child of |new_parent| or NULL. Returns false on failure..
116 bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
117
118 // Set the bookmark specifics (url and favicon).
119 // Should only be called if GetModelType() == BOOKMARK.
120 void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
121
122 // Generic set specifics method. Will extract the model type from |specifics|.
123 void SetEntitySpecifics(const sync_pb::EntitySpecifics& specifics);
124
125 // Resets the EntitySpecifics for this node based on the unencrypted data.
126 // Will encrypt if necessary.
127 void ResetFromSpecifics();
128
129 // TODO(sync): Remove the setters below when the corresponding data
130 // types are ported to the new sync service API.
131
132 // Set the nigori specifics.
133 // Should only be called if GetModelType() == NIGORI.
134 void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
135
136 // Set the password specifics.
137 // Should only be called if GetModelType() == PASSWORD.
138 void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
139
140 // Set the typed_url specifics (url, title, typed_count, etc).
141 // Should only be called if GetModelType() == TYPED_URLS.
142 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
143
144 // Set the attachment metadata.
145 void SetAttachmentMetadata(
146 const sync_pb::AttachmentMetadata& attachment_metadata);
147
148 // Implementation of BaseNode's abstract virtual accessors.
149 const syncable::Entry* GetEntry() const override;
150
151 const BaseTransaction* GetTransaction() const override;
152
153 syncable::MutableEntry* GetMutableEntryForTest();
154
155 private:
156 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, EncryptBookmarksWithLegacyData);
157
158 void* operator new(size_t size); // Node is meant for stack use only.
159
160 InitUniqueByCreationResult InitUniqueByCreationImpl(
161 ModelType model_type,
162 const syncable::Id& parent_id,
163 const std::string& client_tag);
164
165 // Helper to set the previous node.
166 bool PutPredecessor(const BaseNode* predecessor) WARN_UNUSED_RESULT;
167
168 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
169 // upcoming commit pass.
170 void MarkForSyncing();
171
172 // The underlying syncable object which this class wraps.
173 syncable::MutableEntry* entry_;
174
175 // The sync API transaction that is the parent of this node.
176 WriteTransaction* transaction_;
177
178 DISALLOW_COPY_AND_ASSIGN(WriteNode);
179 };
180
181 } // namespace syncer
182
183 #endif // SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/util/weak_handle_unittest.cc ('k') | sync/internal_api/public/write_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698