OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 // Construct an AttachmentServiceProxy that forwards calls to |wrapped| on the | 42 // Construct an AttachmentServiceProxy that forwards calls to |wrapped| on the |
43 // |wrapped_task_runner| thread. | 43 // |wrapped_task_runner| thread. |
44 // | 44 // |
45 // Note, this object does not own |wrapped|. When |wrapped| is destroyed, | 45 // Note, this object does not own |wrapped|. When |wrapped| is destroyed, |
46 // calls to this object become no-ops. | 46 // calls to this object become no-ops. |
47 AttachmentServiceProxy( | 47 AttachmentServiceProxy( |
48 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 48 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
49 const base::WeakPtr<syncer::AttachmentService>& wrapped); | 49 const base::WeakPtr<syncer::AttachmentService>& wrapped); |
50 | 50 |
51 virtual ~AttachmentServiceProxy(); | 51 ~AttachmentServiceProxy() override; |
52 | 52 |
53 // AttachmentService implementation. | 53 // AttachmentService implementation. |
54 // | 54 // |
55 // GetStore always returns NULL. | 55 // GetStore always returns NULL. |
56 virtual AttachmentStore* GetStore() override; | 56 AttachmentStore* GetStore() override; |
57 virtual void GetOrDownloadAttachments( | 57 void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, |
58 const AttachmentIdList& attachment_ids, | 58 const GetOrDownloadCallback& callback) override; |
59 const GetOrDownloadCallback& callback) override; | 59 void DropAttachments(const AttachmentIdList& attachment_ids, |
60 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | 60 const DropCallback& callback) override; |
61 const DropCallback& callback) override; | 61 void UploadAttachments(const AttachmentIdSet& attachment_ids) override; |
62 virtual void UploadAttachments( | |
63 const AttachmentIdSet& attachment_ids) override; | |
64 | 62 |
65 protected: | 63 protected: |
66 // Core does the work of proxying calls to AttachmentService methods from one | 64 // Core does the work of proxying calls to AttachmentService methods from one |
67 // thread to another so AttachmentServiceProxy can be an easy-to-use, | 65 // thread to another so AttachmentServiceProxy can be an easy-to-use, |
68 // non-ref-counted A ref-counted class. | 66 // non-ref-counted A ref-counted class. |
69 // | 67 // |
70 // Callback from AttachmentService are proxied back using free functions | 68 // Callback from AttachmentService are proxied back using free functions |
71 // defined in the .cc file (ProxyFooCallback functions). | 69 // defined in the .cc file (ProxyFooCallback functions). |
72 // | 70 // |
73 // Core is ref-counted because we want to allow AttachmentServiceProxy to be | 71 // Core is ref-counted because we want to allow AttachmentServiceProxy to be |
74 // copy-constructable while allowing for different implementations of Core | 72 // copy-constructable while allowing for different implementations of Core |
75 // (e.g. one type of core might own the wrapped AttachmentService). | 73 // (e.g. one type of core might own the wrapped AttachmentService). |
76 // | 74 // |
77 // Calls to objects of this class become no-ops once its wrapped object is | 75 // Calls to objects of this class become no-ops once its wrapped object is |
78 // destroyed. | 76 // destroyed. |
79 class SYNC_EXPORT Core : public AttachmentService, | 77 class SYNC_EXPORT Core : public AttachmentService, |
80 public base::RefCountedThreadSafe<Core> { | 78 public base::RefCountedThreadSafe<Core> { |
81 public: | 79 public: |
82 // Construct an AttachmentServiceProxyCore that forwards calls to |wrapped|. | 80 // Construct an AttachmentServiceProxyCore that forwards calls to |wrapped|. |
83 Core(const base::WeakPtr<syncer::AttachmentService>& wrapped); | 81 Core(const base::WeakPtr<syncer::AttachmentService>& wrapped); |
84 | 82 |
85 // AttachmentService implementation. | 83 // AttachmentService implementation. |
86 virtual AttachmentStore* GetStore() override; | 84 AttachmentStore* GetStore() override; |
87 virtual void GetOrDownloadAttachments( | 85 void GetOrDownloadAttachments( |
88 const AttachmentIdList& attachment_ids, | 86 const AttachmentIdList& attachment_ids, |
89 const GetOrDownloadCallback& callback) override; | 87 const GetOrDownloadCallback& callback) override; |
90 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | 88 void DropAttachments(const AttachmentIdList& attachment_ids, |
91 const DropCallback& callback) override; | 89 const DropCallback& callback) override; |
92 virtual void UploadAttachments( | 90 void UploadAttachments(const AttachmentIdSet& attachment_ids) override; |
93 const AttachmentIdSet& attachment_ids) override; | |
94 | 91 |
95 protected: | 92 protected: |
96 friend class base::RefCountedThreadSafe<Core>; | 93 friend class base::RefCountedThreadSafe<Core>; |
97 virtual ~Core(); | 94 ~Core() override; |
98 | 95 |
99 private: | 96 private: |
100 base::WeakPtr<AttachmentService> wrapped_; | 97 base::WeakPtr<AttachmentService> wrapped_; |
101 | 98 |
102 DISALLOW_COPY_AND_ASSIGN(Core); | 99 DISALLOW_COPY_AND_ASSIGN(Core); |
103 }; | 100 }; |
104 | 101 |
105 // Used in tests to create an AttachmentServiceProxy with a custom Core. | 102 // Used in tests to create an AttachmentServiceProxy with a custom Core. |
106 AttachmentServiceProxy( | 103 AttachmentServiceProxy( |
107 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 104 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
108 const scoped_refptr<Core>& core); | 105 const scoped_refptr<Core>& core); |
109 | 106 |
110 private: | 107 private: |
111 scoped_refptr<base::SequencedTaskRunner> wrapped_task_runner_; | 108 scoped_refptr<base::SequencedTaskRunner> wrapped_task_runner_; |
112 scoped_refptr<Core> core_; | 109 scoped_refptr<Core> core_; |
113 }; | 110 }; |
114 | 111 |
115 } // namespace syncer | 112 } // namespace syncer |
116 | 113 |
117 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | 114 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ |
OLD | NEW |