OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sync/internal_api/public/attachments/attachment_store_handle.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/sequenced_task_runner.h" |
| 10 #include "sync/api/attachments/attachment.h" |
| 11 |
| 12 namespace syncer { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreHandle dtor. |
| 17 // It doesn't need to do anything. |
| 18 void NoOp(scoped_ptr<AttachmentStoreBase> backend) { |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 AttachmentStoreHandle::AttachmentStoreHandle( |
| 24 scoped_ptr<AttachmentStoreBase> backend, |
| 25 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner) |
| 26 : backend_(backend.Pass()), backend_task_runner_(backend_task_runner) { |
| 27 DCHECK(backend_); |
| 28 DCHECK(backend_task_runner_.get()); |
| 29 } |
| 30 |
| 31 AttachmentStoreHandle::~AttachmentStoreHandle() { |
| 32 DCHECK(backend_); |
| 33 // To delete backend post task that doesn't do anything, but binds backend |
| 34 // through base::Passed. This way backend will be deleted regardless whether |
| 35 // task runs or not. |
| 36 backend_task_runner_->PostTask( |
| 37 FROM_HERE, base::Bind(&NoOp, base::Passed(&backend_))); |
| 38 } |
| 39 |
| 40 void AttachmentStoreHandle::Read(const AttachmentIdList& ids, |
| 41 const ReadCallback& callback) { |
| 42 DCHECK(CalledOnValidThread()); |
| 43 backend_task_runner_->PostTask(FROM_HERE, |
| 44 base::Bind(&AttachmentStoreBase::Read, |
| 45 base::Unretained(backend_.get()), |
| 46 ids, |
| 47 callback)); |
| 48 } |
| 49 |
| 50 void AttachmentStoreHandle::Write(const AttachmentList& attachments, |
| 51 const WriteCallback& callback) { |
| 52 DCHECK(CalledOnValidThread()); |
| 53 backend_task_runner_->PostTask(FROM_HERE, |
| 54 base::Bind(&AttachmentStoreBase::Write, |
| 55 base::Unretained(backend_.get()), |
| 56 attachments, |
| 57 callback)); |
| 58 } |
| 59 |
| 60 void AttachmentStoreHandle::Drop(const AttachmentIdList& ids, |
| 61 const DropCallback& callback) { |
| 62 DCHECK(CalledOnValidThread()); |
| 63 backend_task_runner_->PostTask(FROM_HERE, |
| 64 base::Bind(&AttachmentStoreBase::Drop, |
| 65 base::Unretained(backend_.get()), |
| 66 ids, |
| 67 callback)); |
| 68 } |
| 69 |
| 70 } // namespace syncer |
OLD | NEW |