Chromium Code Reviews| 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_API_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | |
| 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "base/task_runner.h" | |
| 14 #include "sync/api/attachments/attachment.h" | |
| 15 #include "sync/api/attachments/attachment_service.h" | |
| 16 #include "sync/base/sync_export.h" | |
| 17 | |
| 18 namespace syncer { | |
| 19 | |
| 20 class SyncData; | |
| 21 | |
| 22 // AttachmentServiceProxy wraps an AttachmentService allowing multiple threads | |
| 23 // to share the wrapped AttachmentService. | |
| 24 // | |
| 25 // Callbacks passed to methods on this class will be invoked in the same thread | |
| 26 // from which the method was called. | |
| 27 // | |
| 28 // This class does not own its wrapped AttachmentService object. This class | |
| 29 // holds a WeakPtr to the wrapped object. Once the the wrapped object is | |
| 30 // destroyed, method calls on this object will be no-ops. | |
| 31 // | |
| 32 // Users of this class should take care to destroy the wrapped object on the | |
| 33 // correct thread (wrapped_task_runner). | |
| 34 // | |
| 35 // This class is thread-safe. | |
| 36 class SYNC_EXPORT AttachmentServiceProxy | |
| 37 : public AttachmentService, | |
| 38 public base::RefCountedThreadSafe<AttachmentServiceProxy> { | |
|
tim (not reviewing)
2014/03/27 17:01:44
I still think having a hidden ref-counted core obj
tim (not reviewing)
2014/03/27 17:02:09
Ignore this comment. It was stale from before a f
| |
| 39 public: | |
| 40 // Construct an AttachmentServiceProxy that forwards calls to |wrapped| on the | |
| 41 // |wrapped_task_runner| thread. | |
| 42 AttachmentServiceProxy( | |
| 43 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | |
| 44 base::WeakPtr<syncer::AttachmentService> wrapped); | |
| 45 | |
| 46 // AttachmentService implementation. | |
| 47 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, | |
| 48 const GetOrDownloadCallback& callback) | |
| 49 OVERRIDE; | |
| 50 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | |
| 51 const DropCallback& callback) OVERRIDE; | |
| 52 virtual void OnSyncDataAdd(const SyncData& sync_data) OVERRIDE; | |
| 53 virtual void OnSyncDataDelete(const SyncData& sync_data) OVERRIDE; | |
| 54 virtual void OnSyncDataUpdate(const AttachmentIdList& old_attachment_ids, | |
| 55 const SyncData& updated_sync_data) OVERRIDE; | |
| 56 virtual base::WeakPtr<AttachmentService> AsWeakPtr() OVERRIDE; | |
| 57 | |
| 58 private: | |
| 59 friend class base::RefCountedThreadSafe<AttachmentServiceProxy>; | |
| 60 | |
| 61 scoped_refptr<base::SequencedTaskRunner> wrapped_task_runner_; | |
| 62 // wrapped_ must only be dereferenced on the wrapped_task_runner_ thread. | |
| 63 base::WeakPtr<AttachmentService> wrapped_; | |
| 64 | |
| 65 // Must be last data member. | |
| 66 base::WeakPtrFactory<AttachmentService> weak_ptr_factory_; | |
| 67 | |
| 68 virtual ~AttachmentServiceProxy(); | |
| 69 }; | |
| 70 | |
| 71 } // namespace syncer | |
| 72 | |
| 73 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_H_ | |
| OLD | NEW |