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<AttachmentStoreBackend> backend) { | |
19 } | |
20 | |
21 } // namespace | |
22 | |
23 AttachmentStoreHandle::AttachmentStoreHandle( | |
24 scoped_ptr<AttachmentStoreBackend> 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::Init(const InitCallback& callback) { | |
41 DCHECK(CalledOnValidThread()); | |
42 backend_task_runner_->PostTask( | |
43 FROM_HERE, base::Bind(&AttachmentStoreBackend::Init, | |
44 base::Unretained(backend_.get()), callback)); | |
45 } | |
46 | |
47 void AttachmentStoreHandle::Read(const AttachmentIdList& ids, | |
48 const ReadCallback& callback) { | |
49 DCHECK(CalledOnValidThread()); | |
50 backend_task_runner_->PostTask( | |
51 FROM_HERE, base::Bind(&AttachmentStoreBackend::Read, | |
52 base::Unretained(backend_.get()), ids, callback)); | |
53 } | |
54 | |
55 void AttachmentStoreHandle::Write(const AttachmentList& attachments, | |
56 const WriteCallback& callback) { | |
57 DCHECK(CalledOnValidThread()); | |
58 backend_task_runner_->PostTask( | |
59 FROM_HERE, | |
60 base::Bind(&AttachmentStoreBackend::Write, | |
61 base::Unretained(backend_.get()), attachments, callback)); | |
62 } | |
63 | |
64 void AttachmentStoreHandle::Drop(const AttachmentIdList& ids, | |
65 const DropCallback& callback) { | |
66 DCHECK(CalledOnValidThread()); | |
67 backend_task_runner_->PostTask( | |
68 FROM_HERE, base::Bind(&AttachmentStoreBackend::Drop, | |
69 base::Unretained(backend_.get()), ids, callback)); | |
70 } | |
71 | |
72 void AttachmentStoreHandle::ReadMetadata(const AttachmentIdList& ids, | |
73 const ReadMetadataCallback& callback) { | |
74 DCHECK(CalledOnValidThread()); | |
75 backend_task_runner_->PostTask( | |
76 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadMetadata, | |
77 base::Unretained(backend_.get()), ids, callback)); | |
78 } | |
79 | |
80 void AttachmentStoreHandle::ReadAllMetadata( | |
81 const ReadMetadataCallback& callback) { | |
82 DCHECK(CalledOnValidThread()); | |
83 backend_task_runner_->PostTask( | |
84 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadAllMetadata, | |
85 base::Unretained(backend_.get()), callback)); | |
86 } | |
87 | |
88 } // namespace syncer | |
OLD | NEW |