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.
5 #include "sync/internal_api/public/attachments/attachment_store_handle.h"
8 #include "base/location.h"
9 #include "base/sequenced_task_runner.h"
10 #include "sync/api/attachments/attachment.h"
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) {
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) {
28 DCHECK(backend_task_runner_.get());
31 AttachmentStoreHandle::~AttachmentStoreHandle() {
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
36 backend_task_runner_->PostTask(
37 FROM_HERE, base::Bind(&NoOp, base::Passed(&backend_)));
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()),
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()),
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()),