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

Unified Diff: sync/api/sync_data.cc

Issue 264793007: Keep track of which attachments are referenced by which sync entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/api/sync_data.h ('k') | sync/engine/get_commit_ids.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/api/sync_data.cc
diff --git a/sync/api/sync_data.cc b/sync/api/sync_data.cc
index fa48ea5edc18a89a1c20d15325e9e58bcee727b6..35a21f90f8be52997a8de25ff2346342f17a5662 100644
--- a/sync/api/sync_data.cc
+++ b/sync/api/sync_data.cc
@@ -36,6 +36,21 @@ syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) {
return syncer::AttachmentId::CreateFromProto(proto);
}
+// Return true iff |attachments| contains one or more elements with the same
+// AttachmentId.
+bool ContainsDuplicateAttachments(const syncer::AttachmentList& attachments) {
+ std::set<syncer::AttachmentId> id_set;
+ AttachmentList::const_iterator iter = attachments.begin();
+ AttachmentList::const_iterator end = attachments.end();
+ for (; iter != end; ++iter) {
+ if (id_set.find(iter->GetId()) != id_set.end()) {
+ return true;
+ }
+ id_set.insert(iter->GetId());
+ }
+ return false;
+}
+
} // namespace
namespace syncer {
@@ -96,15 +111,13 @@ SyncData SyncData::CreateLocalData(const std::string& sync_tag,
sync_tag, non_unique_title, specifics, attachments);
}
-// TODO(maniscalco): What should happen if the same Attachment appears in the
-// list twice? Document the behavior and add a test case.
-//
// Static.
SyncData SyncData::CreateLocalDataWithAttachments(
const std::string& sync_tag,
const std::string& non_unique_title,
const sync_pb::EntitySpecifics& specifics,
const AttachmentList& attachments) {
+ DCHECK(!ContainsDuplicateAttachments(attachments));
sync_pb::SyncEntity entity;
entity.set_client_defined_unique_tag(sync_tag);
entity.set_non_unique_name(non_unique_title);
@@ -113,9 +126,6 @@ SyncData SyncData::CreateLocalDataWithAttachments(
attachments.end(),
RepeatedFieldBackInserter(entity.mutable_attachment_id()),
AttachmentToProto);
- // TODO(maniscalco): Actually pass the attachments to the ctor and make them
- // available to the AttachmentService once this SyncData gets passed into
- // GenericChangeProcesso::ProcessSyncChanges (bug 354530).
AttachmentList copy_of_attachments(attachments);
return SyncData(kInvalidId,
&entity,
« no previous file with comments | « sync/api/sync_data.h ('k') | sync/engine/get_commit_ids.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698