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