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::Init(const InitCallback
& callback
) {
41 DCHECK(CalledOnValidThread());
42 backend_task_runner_
->PostTask(
43 FROM_HERE
, base::Bind(&AttachmentStoreBase::Init
,
44 base::Unretained(backend_
.get()), callback
));
47 void AttachmentStoreHandle::Read(const AttachmentIdList
& ids
,
48 const ReadCallback
& callback
) {
49 DCHECK(CalledOnValidThread());
50 backend_task_runner_
->PostTask(FROM_HERE
,
51 base::Bind(&AttachmentStoreBase::Read
,
52 base::Unretained(backend_
.get()),
57 void AttachmentStoreHandle::Write(const AttachmentList
& attachments
,
58 const WriteCallback
& callback
) {
59 DCHECK(CalledOnValidThread());
60 backend_task_runner_
->PostTask(FROM_HERE
,
61 base::Bind(&AttachmentStoreBase::Write
,
62 base::Unretained(backend_
.get()),
67 void AttachmentStoreHandle::Drop(const AttachmentIdList
& ids
,
68 const DropCallback
& callback
) {
69 DCHECK(CalledOnValidThread());
70 backend_task_runner_
->PostTask(FROM_HERE
,
71 base::Bind(&AttachmentStoreBase::Drop
,
72 base::Unretained(backend_
.get()),
77 void AttachmentStoreHandle::ReadMetadata(const AttachmentIdList
& ids
,
78 const ReadMetadataCallback
& callback
) {
79 DCHECK(CalledOnValidThread());
80 backend_task_runner_
->PostTask(
81 FROM_HERE
, base::Bind(&AttachmentStoreBase::ReadMetadata
,
82 base::Unretained(backend_
.get()), ids
, callback
));
85 void AttachmentStoreHandle::ReadAllMetadata(
86 const ReadMetadataCallback
& callback
) {
87 DCHECK(CalledOnValidThread());
88 backend_task_runner_
->PostTask(
89 FROM_HERE
, base::Bind(&AttachmentStoreBase::ReadAllMetadata
,
90 base::Unretained(backend_
.get()), callback
));