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 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_HANDLE_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_HANDLE_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/stl_util.h" |
| 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "sync/api/attachments/attachment_store.h" |
| 15 #include "sync/base/sync_export.h" |
| 16 |
| 17 namespace base { |
| 18 class SequencedTaskRunner; |
| 19 } // namespace base |
| 20 |
| 21 namespace sync_pb { |
| 22 class AttachmentId; |
| 23 } // namespace sync_pb |
| 24 |
| 25 namespace syncer { |
| 26 |
| 27 class Attachment; |
| 28 |
| 29 // AttachmentStoreHandle is helper to post AttachmentStore calls to backend on |
| 30 // different thread. Backend is expected to know on which thread to post |
| 31 // callbacks with results. |
| 32 // AttachmentStoreHandle takes ownership of backend. Backend is deleted on |
| 33 // backend thread. |
| 34 // AttachmentStoreHandle is not thread safe, it should only be accessed from |
| 35 // model thread. |
| 36 class SYNC_EXPORT AttachmentStoreHandle : public AttachmentStore, |
| 37 public base::NonThreadSafe { |
| 38 public: |
| 39 AttachmentStoreHandle( |
| 40 scoped_ptr<AttachmentStoreBase> backend, |
| 41 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner); |
| 42 |
| 43 // AttachmentStore implementation. |
| 44 virtual void Read(const AttachmentIdList& id, |
| 45 const ReadCallback& callback) OVERRIDE; |
| 46 virtual void Write(const AttachmentList& attachments, |
| 47 const WriteCallback& callback) OVERRIDE; |
| 48 virtual void Drop(const AttachmentIdList& id, |
| 49 const DropCallback& callback) OVERRIDE; |
| 50 |
| 51 private: |
| 52 virtual ~AttachmentStoreHandle(); |
| 53 |
| 54 // AttachmentStoreHandle controls backend's lifetime. It is safe for |
| 55 // AttachmentStoreHandle to bind backend through base::Unretained for posts. |
| 56 // Backend is deleted on backend_task_runner, after that backend_ pointer is |
| 57 // invalid. |
| 58 scoped_ptr<AttachmentStoreBase> backend_; |
| 59 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreHandle); |
| 62 }; |
| 63 |
| 64 } // namespace syncer |
| 65 |
| 66 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_HANDLE_H_ |
OLD | NEW |