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

Side by Side Diff: sync/internal_api/attachments/on_disk_attachment_store.cc

Issue 1002263005: [Sync] Introduce AttachmentStoreForSync class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/internal_api/public/attachments/on_disk_attachment_store.h" 5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 : AttachmentStore::UNSPECIFIED_ERROR; 127 : AttachmentStore::UNSPECIFIED_ERROR;
128 } else { 128 } else {
129 *unavailable_attachments = ids; 129 *unavailable_attachments = ids;
130 } 130 }
131 131
132 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map), 132 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map),
133 base::Passed(&unavailable_attachments))); 133 base::Passed(&unavailable_attachments)));
134 } 134 }
135 135
136 void OnDiskAttachmentStore::Write( 136 void OnDiskAttachmentStore::Write(
137 AttachmentStore::AttachmentReferrer referrer, 137 AttachmentStore::Component component,
138 const AttachmentList& attachments, 138 const AttachmentList& attachments,
139 const AttachmentStore::WriteCallback& callback) { 139 const AttachmentStore::WriteCallback& callback) {
140 DCHECK(CalledOnValidThread()); 140 DCHECK(CalledOnValidThread());
141 AttachmentStore::Result result_code = 141 AttachmentStore::Result result_code =
142 AttachmentStore::STORE_INITIALIZATION_FAILED; 142 AttachmentStore::STORE_INITIALIZATION_FAILED;
143 143
144 if (db_) { 144 if (db_) {
145 result_code = AttachmentStore::SUCCESS; 145 result_code = AttachmentStore::SUCCESS;
146 AttachmentList::const_iterator iter = attachments.begin(); 146 AttachmentList::const_iterator iter = attachments.begin();
147 const AttachmentList::const_iterator end = attachments.end(); 147 const AttachmentList::const_iterator end = attachments.end();
148 for (; iter != end; ++iter) { 148 for (; iter != end; ++iter) {
149 if (!WriteSingleAttachment(*iter)) 149 if (!WriteSingleAttachment(*iter))
150 result_code = AttachmentStore::UNSPECIFIED_ERROR; 150 result_code = AttachmentStore::UNSPECIFIED_ERROR;
151 } 151 }
152 } 152 }
153 PostCallback(base::Bind(callback, result_code)); 153 PostCallback(base::Bind(callback, result_code));
154 } 154 }
155 155
156 void OnDiskAttachmentStore::Drop( 156 void OnDiskAttachmentStore::SetReference(AttachmentStore::Component component,
157 AttachmentStore::AttachmentReferrer referrer, 157 const AttachmentIdList& ids) {
158 DCHECK(CalledOnValidThread());
159 DCHECK_EQ(AttachmentStore::SYNC, component);
160 }
161
162 void OnDiskAttachmentStore::DropReference(
163 AttachmentStore::Component component,
158 const AttachmentIdList& ids, 164 const AttachmentIdList& ids,
159 const AttachmentStore::DropCallback& callback) { 165 const AttachmentStore::DropCallback& callback) {
160 DCHECK(CalledOnValidThread()); 166 DCHECK(CalledOnValidThread());
167 if (component == AttachmentStore::SYNC) {
168 // TODO(pavely): There is no reference handling implementation yet. All
169 // calls to AddReferrer are ignored. Calls to Drop coming from sync should
170 // be ignored too.
171 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS));
172 return;
173 }
161 AttachmentStore::Result result_code = 174 AttachmentStore::Result result_code =
162 AttachmentStore::STORE_INITIALIZATION_FAILED; 175 AttachmentStore::STORE_INITIALIZATION_FAILED;
163 if (db_) { 176 if (db_) {
164 result_code = AttachmentStore::SUCCESS; 177 result_code = AttachmentStore::SUCCESS;
165 leveldb::WriteOptions write_options = MakeWriteOptions(); 178 leveldb::WriteOptions write_options = MakeWriteOptions();
166 AttachmentIdList::const_iterator iter = ids.begin(); 179 AttachmentIdList::const_iterator iter = ids.begin();
167 const AttachmentIdList::const_iterator end = ids.end(); 180 const AttachmentIdList::const_iterator end = ids.end();
168 for (; iter != end; ++iter) { 181 for (; iter != end; ++iter) {
169 leveldb::WriteBatch write_batch; 182 leveldb::WriteBatch write_batch;
170 write_batch.Delete(MakeDataKeyFromAttachmentId(*iter)); 183 write_batch.Delete(MakeDataKeyFromAttachmentId(*iter));
(...skipping 30 matching lines...) Expand all
201 MakeAttachmentMetadata(*iter, record_metadata)); 214 MakeAttachmentMetadata(*iter, record_metadata));
202 } else { 215 } else {
203 result_code = AttachmentStore::UNSPECIFIED_ERROR; 216 result_code = AttachmentStore::UNSPECIFIED_ERROR;
204 } 217 }
205 } 218 }
206 } 219 }
207 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); 220 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list)));
208 } 221 }
209 222
210 void OnDiskAttachmentStore::ReadAllMetadata( 223 void OnDiskAttachmentStore::ReadAllMetadata(
211 AttachmentStore::AttachmentReferrer referrer, 224 AttachmentStore::Component component,
212 const AttachmentStore::ReadMetadataCallback& callback) { 225 const AttachmentStore::ReadMetadataCallback& callback) {
213 DCHECK(CalledOnValidThread()); 226 DCHECK(CalledOnValidThread());
214 AttachmentStore::Result result_code = 227 AttachmentStore::Result result_code =
215 AttachmentStore::STORE_INITIALIZATION_FAILED; 228 AttachmentStore::STORE_INITIALIZATION_FAILED;
216 scoped_ptr<AttachmentMetadataList> metadata_list( 229 scoped_ptr<AttachmentMetadataList> metadata_list(
217 new AttachmentMetadataList()); 230 new AttachmentMetadataList());
218 231
219 if (db_) { 232 if (db_) {
220 result_code = AttachmentStore::SUCCESS; 233 result_code = AttachmentStore::SUCCESS;
221 scoped_ptr<leveldb::Iterator> db_iterator( 234 scoped_ptr<leveldb::Iterator> db_iterator(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 return key; 419 return key;
407 } 420 }
408 421
409 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( 422 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata(
410 const AttachmentId& attachment_id, 423 const AttachmentId& attachment_id,
411 const attachment_store_pb::RecordMetadata& record_metadata) { 424 const attachment_store_pb::RecordMetadata& record_metadata) {
412 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); 425 return AttachmentMetadata(attachment_id, record_metadata.attachment_size());
413 } 426 }
414 427
415 } // namespace syncer 428 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698