OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "sync/engine/commit_util.h" | 5 #include "sync/engine/commit_util.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 143 |
144 if (meta_entry.ShouldMaintainHierarchy()) { | 144 if (meta_entry.ShouldMaintainHierarchy()) { |
145 sync_entry->set_parent_id_string(SyncableIdToProto(new_parent_id)); | 145 sync_entry->set_parent_id_string(SyncableIdToProto(new_parent_id)); |
146 } | 146 } |
147 | 147 |
148 // If our parent has changed, send up the old one so the server | 148 // If our parent has changed, send up the old one so the server |
149 // can correctly deal with multiple parents. | 149 // can correctly deal with multiple parents. |
150 // TODO(nick): With the server keeping track of the primary sync parent, | 150 // TODO(nick): With the server keeping track of the primary sync parent, |
151 // it should not be necessary to provide the old_parent_id: the version | 151 // it should not be necessary to provide the old_parent_id: the version |
152 // number should suffice. | 152 // number should suffice. |
153 if (new_parent_id != meta_entry.GetServerParentId() && | 153 Id server_parent_id = meta_entry.GetServerParentId(); |
154 if (new_parent_id != server_parent_id && !server_parent_id.IsNull() && | |
pavely
2014/12/22 21:38:09
Could you give examples when server_parent_id will
stanisc
2014/12/22 21:56:01
Currently parent IDs are never nulls (empty) so th
pavely
2014/12/22 22:00:48
sgtm
| |
154 0 != meta_entry.GetBaseVersion() && | 155 0 != meta_entry.GetBaseVersion() && |
155 syncable::CHANGES_VERSION != meta_entry.GetBaseVersion()) { | 156 syncable::CHANGES_VERSION != meta_entry.GetBaseVersion()) { |
156 sync_entry->set_old_parent_id( | 157 sync_entry->set_old_parent_id(SyncableIdToProto(server_parent_id)); |
157 SyncableIdToProto(meta_entry.GetServerParentId())); | |
158 } | 158 } |
159 | 159 |
160 int64 version = meta_entry.GetBaseVersion(); | 160 int64 version = meta_entry.GetBaseVersion(); |
161 if (syncable::CHANGES_VERSION == version || 0 == version) { | 161 if (syncable::CHANGES_VERSION == version || 0 == version) { |
162 // Undeletions are only supported for items that have a client tag. | 162 // Undeletions are only supported for items that have a client tag. |
163 DCHECK(!id.ServerKnows() || | 163 DCHECK(!id.ServerKnows() || |
164 !meta_entry.GetUniqueClientTag().empty()) | 164 !meta_entry.GetUniqueClientTag().empty()) |
165 << meta_entry; | 165 << meta_entry; |
166 | 166 |
167 // Version 0 means to create or undelete an object. | 167 // Version 0 means to create or undelete an object. |
168 sync_entry->set_version(0); | 168 sync_entry->set_version(0); |
169 } else { | 169 } else { |
170 DCHECK(id.ServerKnows()) << meta_entry; | 170 DCHECK(id.ServerKnows()) << meta_entry; |
171 sync_entry->set_version(meta_entry.GetBaseVersion()); | 171 sync_entry->set_version(meta_entry.GetBaseVersion()); |
172 } | 172 } |
173 sync_entry->set_ctime(TimeToProtoTime(meta_entry.GetCtime())); | 173 sync_entry->set_ctime(TimeToProtoTime(meta_entry.GetCtime())); |
174 sync_entry->set_mtime(TimeToProtoTime(meta_entry.GetMtime())); | 174 sync_entry->set_mtime(TimeToProtoTime(meta_entry.GetMtime())); |
175 | 175 |
176 SetAttachmentIds(meta_entry, sync_entry); | 176 SetAttachmentIds(meta_entry, sync_entry); |
177 | 177 |
178 // Handle bookmarks separately. | 178 // Handle bookmarks separately. |
179 if (meta_entry.GetSpecifics().has_bookmark()) { | 179 if (meta_entry.GetSpecifics().has_bookmark()) { |
180 if (meta_entry.GetIsDel()) { | 180 if (meta_entry.GetIsDel()) { |
181 sync_entry->set_deleted(true); | 181 sync_entry->set_deleted(true); |
182 } else { | 182 } else { |
183 // Both insert_after_item_id and position_in_parent fields are set only | 183 // Both insert_after_item_id and position_in_parent fields are set only |
184 // for legacy reasons. See comments in sync.proto for more information. | 184 // for legacy reasons. See comments in sync.proto for more information. |
185 const Id& prev_id = meta_entry.GetPredecessorId(); | 185 const Id& prev_id = meta_entry.GetPredecessorId(); |
186 string prev_id_string = | 186 string prev_id_string = |
187 prev_id.IsRoot() ? string() : prev_id.GetServerId(); | 187 prev_id.IsNull() ? string() : prev_id.GetServerId(); |
188 sync_entry->set_insert_after_item_id(prev_id_string); | 188 sync_entry->set_insert_after_item_id(prev_id_string); |
189 sync_entry->set_position_in_parent( | 189 sync_entry->set_position_in_parent( |
190 meta_entry.GetUniquePosition().ToInt64()); | 190 meta_entry.GetUniquePosition().ToInt64()); |
191 meta_entry.GetUniquePosition().ToProto( | 191 meta_entry.GetUniquePosition().ToProto( |
192 sync_entry->mutable_unique_position()); | 192 sync_entry->mutable_unique_position()); |
193 } | 193 } |
194 // Always send specifics for bookmarks. | 194 // Always send specifics for bookmarks. |
195 SetEntrySpecifics(meta_entry, sync_entry); | 195 SetEntrySpecifics(meta_entry, sync_entry); |
196 return; | 196 return; |
197 } | 197 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 } | 462 } |
463 | 463 |
464 ProcessSuccessfulCommitResponse(commit_request_entry, server_entry, | 464 ProcessSuccessfulCommitResponse(commit_request_entry, server_entry, |
465 local_entry.GetId(), &local_entry, syncing_was_set, deleted_folders); | 465 local_entry.GetId(), &local_entry, syncing_was_set, deleted_folders); |
466 return response; | 466 return response; |
467 } | 467 } |
468 | 468 |
469 } // namespace commit_util | 469 } // namespace commit_util |
470 | 470 |
471 } // namespace syncer | 471 } // namespace syncer |
OLD | NEW |