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

Side by Side Diff: sync/engine/commit_util.cc

Issue 393083004: Update Commit and GetUpdatesResponse messages to include attachment ids. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update SyncManagerImpl to detect attachment metadata changes. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sync/engine/conflict_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "sync/engine/syncer_proto_util.h" 13 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/internal_api/public/base/attachment_id_proto.h"
14 #include "sync/internal_api/public/base/unique_position.h" 15 #include "sync/internal_api/public/base/unique_position.h"
15 #include "sync/protocol/bookmark_specifics.pb.h" 16 #include "sync/protocol/bookmark_specifics.pb.h"
16 #include "sync/protocol/sync.pb.h" 17 #include "sync/protocol/sync.pb.h"
17 #include "sync/sessions/sync_session.h" 18 #include "sync/sessions/sync_session.h"
18 #include "sync/syncable/directory.h" 19 #include "sync/syncable/directory.h"
19 #include "sync/syncable/entry.h" 20 #include "sync/syncable/entry.h"
20 #include "sync/syncable/model_neutral_mutable_entry.h" 21 #include "sync/syncable/model_neutral_mutable_entry.h"
21 #include "sync/syncable/syncable_base_transaction.h" 22 #include "sync/syncable/syncable_base_transaction.h"
22 #include "sync/syncable/syncable_base_write_transaction.h" 23 #include "sync/syncable/syncable_base_write_transaction.h"
23 #include "sync/syncable/syncable_changes_version.h" 24 #include "sync/syncable/syncable_changes_version.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (ProxyTypes().Has(it.Get())) 77 if (ProxyTypes().Has(it.Get()))
77 continue; 78 continue;
78 int field_number = GetSpecificsFieldNumberFromModelType(it.Get()); 79 int field_number = GetSpecificsFieldNumberFromModelType(it.Get());
79 config_params->mutable_enabled_type_ids()->Add(field_number); 80 config_params->mutable_enabled_type_ids()->Add(field_number);
80 } 81 }
81 config_params->set_tabs_datatype_enabled( 82 config_params->set_tabs_datatype_enabled(
82 enabled_types.Has(syncer::PROXY_TABS)); 83 enabled_types.Has(syncer::PROXY_TABS));
83 } 84 }
84 85
85 namespace { 86 namespace {
87
86 void SetEntrySpecifics(const Entry& meta_entry, 88 void SetEntrySpecifics(const Entry& meta_entry,
87 sync_pb::SyncEntity* sync_entry) { 89 sync_pb::SyncEntity* sync_entry) {
88 // Add the new style extension and the folder bit. 90 // Add the new style extension and the folder bit.
89 sync_entry->mutable_specifics()->CopyFrom(meta_entry.GetSpecifics()); 91 sync_entry->mutable_specifics()->CopyFrom(meta_entry.GetSpecifics());
90 sync_entry->set_folder(meta_entry.GetIsDir()); 92 sync_entry->set_folder(meta_entry.GetIsDir());
91 93
92 CHECK(!sync_entry->specifics().password().has_client_only_encrypted_data()); 94 CHECK(!sync_entry->specifics().password().has_client_only_encrypted_data());
93 DCHECK_EQ(meta_entry.GetModelType(), GetModelType(*sync_entry)); 95 DCHECK_EQ(meta_entry.GetModelType(), GetModelType(*sync_entry));
94 } 96 }
97
98 void SetAttachmentIds(const Entry& meta_entry,
99 sync_pb::SyncEntity* sync_entry) {
100 const sync_pb::AttachmentMetadata& attachment_metadata =
101 meta_entry.GetAttachmentMetadata();
102 for (int i = 0; i < attachment_metadata.record_size(); ++i) {
103 *sync_entry->add_attachment_id() = attachment_metadata.record(i).id();
104 }
105 }
106
95 } // namespace 107 } // namespace
96 108
97 void BuildCommitItem( 109 void BuildCommitItem(
98 const syncable::Entry& meta_entry, 110 const syncable::Entry& meta_entry,
99 sync_pb::SyncEntity* sync_entry) { 111 sync_pb::SyncEntity* sync_entry) {
100 syncable::Id id = meta_entry.GetId(); 112 syncable::Id id = meta_entry.GetId();
101 sync_entry->set_id_string(SyncableIdToProto(id)); 113 sync_entry->set_id_string(SyncableIdToProto(id));
102 114
103 string name = meta_entry.GetNonUniqueName(); 115 string name = meta_entry.GetNonUniqueName();
104 CHECK(!name.empty()); // Make sure this isn't an update. 116 CHECK(!name.empty()); // Make sure this isn't an update.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 166
155 // Version 0 means to create or undelete an object. 167 // Version 0 means to create or undelete an object.
156 sync_entry->set_version(0); 168 sync_entry->set_version(0);
157 } else { 169 } else {
158 DCHECK(id.ServerKnows()) << meta_entry; 170 DCHECK(id.ServerKnows()) << meta_entry;
159 sync_entry->set_version(meta_entry.GetBaseVersion()); 171 sync_entry->set_version(meta_entry.GetBaseVersion());
160 } 172 }
161 sync_entry->set_ctime(TimeToProtoTime(meta_entry.GetCtime())); 173 sync_entry->set_ctime(TimeToProtoTime(meta_entry.GetCtime()));
162 sync_entry->set_mtime(TimeToProtoTime(meta_entry.GetMtime())); 174 sync_entry->set_mtime(TimeToProtoTime(meta_entry.GetMtime()));
163 175
176 SetAttachmentIds(meta_entry, sync_entry);
177
164 // Handle bookmarks separately. 178 // Handle bookmarks separately.
165 if (meta_entry.GetSpecifics().has_bookmark()) { 179 if (meta_entry.GetSpecifics().has_bookmark()) {
166 if (meta_entry.GetIsDel()) { 180 if (meta_entry.GetIsDel()) {
167 sync_entry->set_deleted(true); 181 sync_entry->set_deleted(true);
168 } else { 182 } else {
169 // 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
170 // for legacy reasons. See comments in sync.proto for more information. 184 // for legacy reasons. See comments in sync.proto for more information.
171 const Id& prev_id = meta_entry.GetPredecessorId(); 185 const Id& prev_id = meta_entry.GetPredecessorId();
172 string prev_id_string = 186 string prev_id_string =
173 prev_id.IsRoot() ? string() : prev_id.GetServerId(); 187 prev_id.IsRoot() ? string() : prev_id.GetServerId();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 local_entry->PutServerIsDel(committed_entry.deleted()); 312 local_entry->PutServerIsDel(committed_entry.deleted());
299 if (committed_entry.deleted()) { 313 if (committed_entry.deleted()) {
300 // Don't clobber any other fields of deleted objects. 314 // Don't clobber any other fields of deleted objects.
301 return; 315 return;
302 } 316 }
303 317
304 local_entry->PutServerIsDir( 318 local_entry->PutServerIsDir(
305 (committed_entry.folder() || 319 (committed_entry.folder() ||
306 committed_entry.bookmarkdata().bookmark_folder())); 320 committed_entry.bookmarkdata().bookmark_folder()));
307 local_entry->PutServerSpecifics(committed_entry.specifics()); 321 local_entry->PutServerSpecifics(committed_entry.specifics());
322 local_entry->PutServerAttachmentMetadata(
323 CreateAttachmentMetadata(committed_entry.attachment_id()));
308 local_entry->PutServerMtime(ProtoTimeToTime(committed_entry.mtime())); 324 local_entry->PutServerMtime(ProtoTimeToTime(committed_entry.mtime()));
309 local_entry->PutServerCtime(ProtoTimeToTime(committed_entry.ctime())); 325 local_entry->PutServerCtime(ProtoTimeToTime(committed_entry.ctime()));
310 if (committed_entry.has_unique_position()) { 326 if (committed_entry.has_unique_position()) {
311 local_entry->PutServerUniquePosition( 327 local_entry->PutServerUniquePosition(
312 UniquePosition::FromProto( 328 UniquePosition::FromProto(
313 committed_entry.unique_position())); 329 committed_entry.unique_position()));
314 } 330 }
315 331
316 // TODO(nick): The server doesn't set entry_response.server_parent_id in 332 // TODO(nick): The server doesn't set entry_response.server_parent_id in
317 // practice; to update SERVER_PARENT_ID appropriately here we'd need to 333 // practice; to update SERVER_PARENT_ID appropriately here we'd need to
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 462 }
447 463
448 ProcessSuccessfulCommitResponse(commit_request_entry, server_entry, 464 ProcessSuccessfulCommitResponse(commit_request_entry, server_entry,
449 local_entry.GetId(), &local_entry, syncing_was_set, deleted_folders); 465 local_entry.GetId(), &local_entry, syncing_was_set, deleted_folders);
450 return response; 466 return response;
451 } 467 }
452 468
453 } // namespace commit_util 469 } // namespace commit_util
454 470
455 } // namespace syncer 471 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/engine/conflict_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698