| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/internal_api/public/attachments/attachment_store_handle.h" | 5 #include "sync/internal_api/public/attachments/attachment_store_frontend.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "sync/api/attachments/attachment.h" | 10 #include "sync/api/attachments/attachment.h" |
| 11 #include "sync/api/attachments/attachment_store_backend.h" |
| 11 | 12 |
| 12 namespace syncer { | 13 namespace syncer { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreHandle dtor. | 17 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreFrontend dtor. |
| 17 // It doesn't need to do anything. | 18 // It doesn't need to do anything. |
| 18 void NoOp(scoped_ptr<AttachmentStoreBackend> backend) { | 19 void NoOp(scoped_ptr<AttachmentStoreBackend> backend) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 } // namespace | 22 } // namespace |
| 22 | 23 |
| 23 AttachmentStoreHandle::AttachmentStoreHandle( | 24 AttachmentStoreFrontend::AttachmentStoreFrontend( |
| 24 scoped_ptr<AttachmentStoreBackend> backend, | 25 scoped_ptr<AttachmentStoreBackend> backend, |
| 25 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner) | 26 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner) |
| 26 : backend_(backend.Pass()), backend_task_runner_(backend_task_runner) { | 27 : backend_(backend.Pass()), backend_task_runner_(backend_task_runner) { |
| 27 DCHECK(backend_); | 28 DCHECK(backend_); |
| 28 DCHECK(backend_task_runner_.get()); | 29 DCHECK(backend_task_runner_.get()); |
| 29 } | 30 } |
| 30 | 31 |
| 31 AttachmentStoreHandle::~AttachmentStoreHandle() { | 32 AttachmentStoreFrontend::~AttachmentStoreFrontend() { |
| 32 DCHECK(backend_); | 33 DCHECK(backend_); |
| 33 // To delete backend post task that doesn't do anything, but binds backend | 34 // 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 // through base::Passed. This way backend will be deleted regardless whether |
| 35 // task runs or not. | 36 // task runs or not. |
| 36 backend_task_runner_->PostTask( | 37 backend_task_runner_->PostTask(FROM_HERE, |
| 37 FROM_HERE, base::Bind(&NoOp, base::Passed(&backend_))); | 38 base::Bind(&NoOp, base::Passed(&backend_))); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void AttachmentStoreHandle::Init(const InitCallback& callback) { | 41 void AttachmentStoreFrontend::Init( |
| 42 const AttachmentStore::InitCallback& callback) { |
| 41 DCHECK(CalledOnValidThread()); | 43 DCHECK(CalledOnValidThread()); |
| 42 backend_task_runner_->PostTask( | 44 backend_task_runner_->PostTask( |
| 43 FROM_HERE, base::Bind(&AttachmentStoreBackend::Init, | 45 FROM_HERE, base::Bind(&AttachmentStoreBackend::Init, |
| 44 base::Unretained(backend_.get()), callback)); | 46 base::Unretained(backend_.get()), callback)); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void AttachmentStoreHandle::Read(const AttachmentIdList& ids, | 49 void AttachmentStoreFrontend::Read( |
| 48 const ReadCallback& callback) { | 50 const AttachmentIdList& ids, |
| 51 const AttachmentStore::ReadCallback& callback) { |
| 49 DCHECK(CalledOnValidThread()); | 52 DCHECK(CalledOnValidThread()); |
| 50 backend_task_runner_->PostTask( | 53 backend_task_runner_->PostTask( |
| 51 FROM_HERE, base::Bind(&AttachmentStoreBackend::Read, | 54 FROM_HERE, base::Bind(&AttachmentStoreBackend::Read, |
| 52 base::Unretained(backend_.get()), ids, callback)); | 55 base::Unretained(backend_.get()), ids, callback)); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void AttachmentStoreHandle::Write(const AttachmentList& attachments, | 58 void AttachmentStoreFrontend::Write( |
| 56 const WriteCallback& callback) { | 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) { |
| 57 DCHECK(CalledOnValidThread()); | 73 DCHECK(CalledOnValidThread()); |
| 58 backend_task_runner_->PostTask( | 74 backend_task_runner_->PostTask( |
| 59 FROM_HERE, | 75 FROM_HERE, |
| 60 base::Bind(&AttachmentStoreBackend::Write, | 76 base::Bind(&AttachmentStoreBackend::Drop, |
| 61 base::Unretained(backend_.get()), attachments, callback)); | 77 base::Unretained(backend_.get()), referrer, ids, callback)); |
| 62 } | 78 } |
| 63 | 79 |
| 64 void AttachmentStoreHandle::Drop(const AttachmentIdList& ids, | 80 void AttachmentStoreFrontend::ReadMetadata( |
| 65 const DropCallback& callback) { | 81 const AttachmentIdList& ids, |
| 66 DCHECK(CalledOnValidThread()); | 82 const AttachmentStore::ReadMetadataCallback& callback) { |
| 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()); | 83 DCHECK(CalledOnValidThread()); |
| 75 backend_task_runner_->PostTask( | 84 backend_task_runner_->PostTask( |
| 76 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadMetadata, | 85 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadMetadata, |
| 77 base::Unretained(backend_.get()), ids, callback)); | 86 base::Unretained(backend_.get()), ids, callback)); |
| 78 } | 87 } |
| 79 | 88 |
| 80 void AttachmentStoreHandle::ReadAllMetadata( | 89 void AttachmentStoreFrontend::ReadAllMetadata( |
| 81 const ReadMetadataCallback& callback) { | 90 AttachmentStore::AttachmentReferrer referrer, |
| 91 const AttachmentStore::ReadMetadataCallback& callback) { |
| 82 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
| 83 backend_task_runner_->PostTask( | 93 backend_task_runner_->PostTask( |
| 84 FROM_HERE, base::Bind(&AttachmentStoreBackend::ReadAllMetadata, | 94 FROM_HERE, |
| 85 base::Unretained(backend_.get()), callback)); | 95 base::Bind(&AttachmentStoreBackend::ReadAllMetadata, |
| 96 base::Unretained(backend_.get()), referrer, callback)); |
| 86 } | 97 } |
| 87 | 98 |
| 88 } // namespace syncer | 99 } // namespace syncer |
| OLD | NEW |