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