OLD | NEW |
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 Loading... |
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, | |
138 const AttachmentList& attachments, | 137 const AttachmentList& attachments, |
139 const AttachmentStore::WriteCallback& callback) { | 138 const AttachmentStore::WriteCallback& callback) { |
140 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
141 AttachmentStore::Result result_code = | 140 AttachmentStore::Result result_code = |
142 AttachmentStore::STORE_INITIALIZATION_FAILED; | 141 AttachmentStore::STORE_INITIALIZATION_FAILED; |
143 | 142 |
144 if (db_) { | 143 if (db_) { |
145 result_code = AttachmentStore::SUCCESS; | 144 result_code = AttachmentStore::SUCCESS; |
146 AttachmentList::const_iterator iter = attachments.begin(); | 145 AttachmentList::const_iterator iter = attachments.begin(); |
147 const AttachmentList::const_iterator end = attachments.end(); | 146 const AttachmentList::const_iterator end = attachments.end(); |
148 for (; iter != end; ++iter) { | 147 for (; iter != end; ++iter) { |
149 if (!WriteSingleAttachment(*iter)) | 148 if (!WriteSingleAttachment(*iter)) |
150 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 149 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
151 } | 150 } |
152 } | 151 } |
153 PostCallback(base::Bind(callback, result_code)); | 152 PostCallback(base::Bind(callback, result_code)); |
154 } | 153 } |
155 | 154 |
156 void OnDiskAttachmentStore::Drop( | 155 void OnDiskAttachmentStore::Drop( |
157 AttachmentStore::AttachmentReferrer referrer, | |
158 const AttachmentIdList& ids, | 156 const AttachmentIdList& ids, |
159 const AttachmentStore::DropCallback& callback) { | 157 const AttachmentStore::DropCallback& callback) { |
160 DCHECK(CalledOnValidThread()); | 158 DCHECK(CalledOnValidThread()); |
161 AttachmentStore::Result result_code = | 159 AttachmentStore::Result result_code = |
162 AttachmentStore::STORE_INITIALIZATION_FAILED; | 160 AttachmentStore::STORE_INITIALIZATION_FAILED; |
163 if (db_) { | 161 if (db_) { |
164 result_code = AttachmentStore::SUCCESS; | 162 result_code = AttachmentStore::SUCCESS; |
165 leveldb::WriteOptions write_options = MakeWriteOptions(); | 163 leveldb::WriteOptions write_options = MakeWriteOptions(); |
166 AttachmentIdList::const_iterator iter = ids.begin(); | 164 AttachmentIdList::const_iterator iter = ids.begin(); |
167 const AttachmentIdList::const_iterator end = ids.end(); | 165 const AttachmentIdList::const_iterator end = ids.end(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 MakeAttachmentMetadata(*iter, record_metadata)); | 199 MakeAttachmentMetadata(*iter, record_metadata)); |
202 } else { | 200 } else { |
203 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 201 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
204 } | 202 } |
205 } | 203 } |
206 } | 204 } |
207 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); | 205 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); |
208 } | 206 } |
209 | 207 |
210 void OnDiskAttachmentStore::ReadAllMetadata( | 208 void OnDiskAttachmentStore::ReadAllMetadata( |
211 AttachmentStore::AttachmentReferrer referrer, | |
212 const AttachmentStore::ReadMetadataCallback& callback) { | 209 const AttachmentStore::ReadMetadataCallback& callback) { |
213 DCHECK(CalledOnValidThread()); | 210 DCHECK(CalledOnValidThread()); |
214 AttachmentStore::Result result_code = | 211 AttachmentStore::Result result_code = |
215 AttachmentStore::STORE_INITIALIZATION_FAILED; | 212 AttachmentStore::STORE_INITIALIZATION_FAILED; |
216 scoped_ptr<AttachmentMetadataList> metadata_list( | 213 scoped_ptr<AttachmentMetadataList> metadata_list( |
217 new AttachmentMetadataList()); | 214 new AttachmentMetadataList()); |
218 | 215 |
219 if (db_) { | 216 if (db_) { |
220 result_code = AttachmentStore::SUCCESS; | 217 result_code = AttachmentStore::SUCCESS; |
221 scoped_ptr<leveldb::Iterator> db_iterator( | 218 scoped_ptr<leveldb::Iterator> db_iterator( |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return key; | 397 return key; |
401 } | 398 } |
402 | 399 |
403 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( | 400 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( |
404 const AttachmentId& attachment_id, | 401 const AttachmentId& attachment_id, |
405 const attachment_store_pb::RecordMetadata& record_metadata) { | 402 const attachment_store_pb::RecordMetadata& record_metadata) { |
406 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); | 403 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); |
407 } | 404 } |
408 | 405 |
409 } // namespace syncer | 406 } // namespace syncer |
OLD | NEW |