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