Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: sync/internal_api/attachments/attachment_store_frontend.cc

Issue 996473005: Revert of [Sync] Refactor AttachmentStore classes. Introduce concept of referrer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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_frontend.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 #include "sync/api/attachments/attachment_store_backend.h"
12
13 namespace syncer {
14
15 namespace {
16
17 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreFrontend dtor.
18 // It doesn't need to do anything.
19 void NoOp(scoped_ptr<AttachmentStoreBackend> backend) {
20 }
21
22 } // namespace
23
24 AttachmentStoreFrontend::AttachmentStoreFrontend(
25 scoped_ptr<AttachmentStoreBackend> backend,
26 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner)
27 : backend_(backend.Pass()), backend_task_runner_(backend_task_runner) {
28 DCHECK(backend_);
29 DCHECK(backend_task_runner_.get());
30 }
31
32 AttachmentStoreFrontend::~AttachmentStoreFrontend() {
33 DCHECK(backend_);
34 // To delete backend post task that doesn't do anything, but binds backend
35 // through base::Passed. This way backend will be deleted regardless whether
36 // task runs or not.
37 backend_task_runner_->PostTask(FROM_HERE,
38 base::Bind(&NoOp, base::Passed(&backend_)));
39 }
40
41 void AttachmentStoreFrontend::Init(
42 const AttachmentStore::InitCallback& callback) {
43 DCHECK(CalledOnValidThread());
44 backend_task_runner_->PostTask(
45 FROM_HERE, base::Bind(&AttachmentStoreBackend::Init,
46 base::Unretained(backend_.get()), callback));
47 }
48
49 void AttachmentStoreFrontend::Read(
50 const AttachmentIdList& ids,
51 const AttachmentStore::ReadCallback& callback) {
52 DCHECK(CalledOnValidThread());
53 backend_task_runner_->PostTask(
54 FROM_HERE, base::Bind(&AttachmentStoreBackend::Read,
55 base::Unretained(backend_.get()), ids, callback));
56 }
57
58 void AttachmentStoreFrontend::Write(
59 AttachmentStore::AttachmentReferrer referrer,
60 const AttachmentList& attachments,
61 const AttachmentStore::WriteCallback& callback) {
62 DCHECK(CalledOnValidThread());
63 backend_task_runner_->PostTask(
64 FROM_HERE, base::Bind(&AttachmentStoreBackend::Write,
65 base::Unretained(backend_.get()), referrer,
66 attachments, callback));
67 }
68
69 void AttachmentStoreFrontend::Drop(
70 AttachmentStore::AttachmentReferrer referrer,
71 const AttachmentIdList& ids,
72 const AttachmentStore::DropCallback& callback) {
73 DCHECK(CalledOnValidThread());
74 backend_task_runner_->PostTask(
75 FROM_HERE,
76 base::Bind(&AttachmentStoreBackend::Drop,
77 base::Unretained(backend_.get()), referrer, ids, callback));
78 }
79
80 void AttachmentStoreFrontend::ReadMetadata(
81 const AttachmentIdList& ids,
82 const AttachmentStore::ReadMetadataCallback& callback) {
83 DCHECK(CalledOnValidThread());
84 backend_task_runner_->PostTask(
85 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadMetadata,
86 base::Unretained(backend_.get()), ids, callback));
87 }
88
89 void AttachmentStoreFrontend::ReadAllMetadata(
90 AttachmentStore::AttachmentReferrer referrer,
91 const AttachmentStore::ReadMetadataCallback& callback) {
92 DCHECK(CalledOnValidThread());
93 backend_task_runner_->PostTask(
94 FROM_HERE,
95 base::Bind(&AttachmentStoreBackend::ReadAllMetadata,
96 base::Unretained(backend_.get()), referrer, callback));
97 }
98
99 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698