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

Side by Side Diff: sync/api/sync_data.cc

Issue 265853004: Revert of Keep track of which attachments are referenced by which sync entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « sync/api/sync_data.h ('k') | sync/engine/get_commit_ids.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/sync_data.h" 5 #include "sync/api/sync_data.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 29
30 sync_pb::AttachmentIdProto IdToProto( 30 sync_pb::AttachmentIdProto IdToProto(
31 const syncer::AttachmentId& attachment_id) { 31 const syncer::AttachmentId& attachment_id) {
32 return attachment_id.GetProto(); 32 return attachment_id.GetProto();
33 } 33 }
34 34
35 syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) { 35 syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) {
36 return syncer::AttachmentId::CreateFromProto(proto); 36 return syncer::AttachmentId::CreateFromProto(proto);
37 } 37 }
38 38
39 // Return true iff |attachments| contains one or more elements with the same
40 // AttachmentId.
41 bool ContainsDuplicateAttachments(const syncer::AttachmentList& attachments) {
42 std::set<syncer::AttachmentId> id_set;
43 AttachmentList::const_iterator iter = attachments.begin();
44 AttachmentList::const_iterator end = attachments.end();
45 for (; iter != end; ++iter) {
46 if (id_set.find(iter->GetId()) != id_set.end()) {
47 return true;
48 }
49 id_set.insert(iter->GetId());
50 }
51 return false;
52 }
53
54 } // namespace 39 } // namespace
55 40
56 namespace syncer { 41 namespace syncer {
57 42
58 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(Wrapper* wrapper) { 43 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(Wrapper* wrapper) {
59 *wrapper = new sync_pb::SyncEntity(); 44 *wrapper = new sync_pb::SyncEntity();
60 } 45 }
61 46
62 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(Wrapper* wrapper) { 47 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(Wrapper* wrapper) {
63 delete *wrapper; 48 delete *wrapper;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 89
105 // Static. 90 // Static.
106 SyncData SyncData::CreateLocalData(const std::string& sync_tag, 91 SyncData SyncData::CreateLocalData(const std::string& sync_tag,
107 const std::string& non_unique_title, 92 const std::string& non_unique_title,
108 const sync_pb::EntitySpecifics& specifics) { 93 const sync_pb::EntitySpecifics& specifics) {
109 syncer::AttachmentList attachments; 94 syncer::AttachmentList attachments;
110 return CreateLocalDataWithAttachments( 95 return CreateLocalDataWithAttachments(
111 sync_tag, non_unique_title, specifics, attachments); 96 sync_tag, non_unique_title, specifics, attachments);
112 } 97 }
113 98
99 // TODO(maniscalco): What should happen if the same Attachment appears in the
100 // list twice? Document the behavior and add a test case.
101 //
114 // Static. 102 // Static.
115 SyncData SyncData::CreateLocalDataWithAttachments( 103 SyncData SyncData::CreateLocalDataWithAttachments(
116 const std::string& sync_tag, 104 const std::string& sync_tag,
117 const std::string& non_unique_title, 105 const std::string& non_unique_title,
118 const sync_pb::EntitySpecifics& specifics, 106 const sync_pb::EntitySpecifics& specifics,
119 const AttachmentList& attachments) { 107 const AttachmentList& attachments) {
120 DCHECK(!ContainsDuplicateAttachments(attachments));
121 sync_pb::SyncEntity entity; 108 sync_pb::SyncEntity entity;
122 entity.set_client_defined_unique_tag(sync_tag); 109 entity.set_client_defined_unique_tag(sync_tag);
123 entity.set_non_unique_name(non_unique_title); 110 entity.set_non_unique_name(non_unique_title);
124 entity.mutable_specifics()->CopyFrom(specifics); 111 entity.mutable_specifics()->CopyFrom(specifics);
125 std::transform(attachments.begin(), 112 std::transform(attachments.begin(),
126 attachments.end(), 113 attachments.end(),
127 RepeatedFieldBackInserter(entity.mutable_attachment_id()), 114 RepeatedFieldBackInserter(entity.mutable_attachment_id()),
128 AttachmentToProto); 115 AttachmentToProto);
116 // TODO(maniscalco): Actually pass the attachments to the ctor and make them
117 // available to the AttachmentService once this SyncData gets passed into
118 // GenericChangeProcesso::ProcessSyncChanges (bug 354530).
129 AttachmentList copy_of_attachments(attachments); 119 AttachmentList copy_of_attachments(attachments);
130 return SyncData(kInvalidId, 120 return SyncData(kInvalidId,
131 &entity, 121 &entity,
132 &copy_of_attachments, 122 &copy_of_attachments,
133 base::Time(), 123 base::Time(),
134 AttachmentServiceProxy()); 124 AttachmentServiceProxy());
135 } 125 }
136 126
137 // Static. 127 // Static.
138 SyncData SyncData::CreateRemoteData( 128 SyncData SyncData::CreateRemoteData(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback); 234 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback);
245 } 235 }
246 236
247 void SyncDataRemote::DropAttachments( 237 void SyncDataRemote::DropAttachments(
248 const AttachmentIdList& attachment_ids, 238 const AttachmentIdList& attachment_ids,
249 const AttachmentService::DropCallback& callback) { 239 const AttachmentService::DropCallback& callback) {
250 attachment_service_.DropAttachments(attachment_ids, callback); 240 attachment_service_.DropAttachments(attachment_ids, callback);
251 } 241 }
252 242
253 } // namespace syncer 243 } // namespace syncer
OLDNEW
« 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