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_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
7 | 7 |
| 8 #include "base/memory/ref_counted.h" |
8 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
9 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "sync/api/attachments/attachment_downloader.h" |
10 #include "sync/api/attachments/attachment_service.h" | 12 #include "sync/api/attachments/attachment_service.h" |
11 #include "sync/api/attachments/attachment_service_proxy.h" | 13 #include "sync/api/attachments/attachment_service_proxy.h" |
12 #include "sync/api/attachments/attachment_store.h" | 14 #include "sync/api/attachments/attachment_store.h" |
13 #include "sync/api/attachments/attachment_uploader.h" | 15 #include "sync/api/attachments/attachment_uploader.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 | 18 |
17 // Implementation of AttachmentService. | 19 // Implementation of AttachmentService. |
18 class SYNC_EXPORT AttachmentServiceImpl : public AttachmentService, | 20 class SYNC_EXPORT AttachmentServiceImpl : public AttachmentService, |
19 public base::NonThreadSafe { | 21 public base::NonThreadSafe { |
20 public: | 22 public: |
21 // |delegate| is optional delegate for AttachmentService to notify about | 23 // |delegate| is optional delegate for AttachmentService to notify about |
22 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not | 24 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not |
23 // provided. AttachmentService doesn't take ownership of delegate, the pointer | 25 // provided. AttachmentService doesn't take ownership of delegate, the pointer |
24 // must be valid throughout AttachmentService lifetime. | 26 // must be valid throughout AttachmentService lifetime. |
25 AttachmentServiceImpl(scoped_ptr<AttachmentStore> attachment_store, | 27 AttachmentServiceImpl(scoped_ptr<AttachmentStore> attachment_store, |
26 scoped_ptr<AttachmentUploader> attachment_uploader, | 28 scoped_ptr<AttachmentUploader> attachment_uploader, |
| 29 scoped_ptr<AttachmentDownloader> attachment_downloader, |
27 Delegate* delegate); | 30 Delegate* delegate); |
28 virtual ~AttachmentServiceImpl(); | 31 virtual ~AttachmentServiceImpl(); |
29 | 32 |
30 // Create an AttachmentServiceImpl suitable for use in tests. | 33 // Create an AttachmentServiceImpl suitable for use in tests. |
31 static scoped_ptr<syncer::AttachmentService> CreateForTest(); | 34 static scoped_ptr<syncer::AttachmentService> CreateForTest(); |
32 | 35 |
33 // AttachmentService implementation. | 36 // AttachmentService implementation. |
34 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, | 37 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, |
35 const GetOrDownloadCallback& callback) | 38 const GetOrDownloadCallback& callback) |
36 OVERRIDE; | 39 OVERRIDE; |
37 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | 40 virtual void DropAttachments(const AttachmentIdList& attachment_ids, |
38 const DropCallback& callback) OVERRIDE; | 41 const DropCallback& callback) OVERRIDE; |
39 virtual void StoreAttachments(const AttachmentList& attachments, | 42 virtual void StoreAttachments(const AttachmentList& attachments, |
40 const StoreCallback& callback) OVERRIDE; | 43 const StoreCallback& callback) OVERRIDE; |
41 virtual void OnSyncDataDelete(const SyncData& sync_data) OVERRIDE; | 44 virtual void OnSyncDataDelete(const SyncData& sync_data) OVERRIDE; |
42 virtual void OnSyncDataUpdate(const AttachmentIdList& old_attachment_ids, | 45 virtual void OnSyncDataUpdate(const AttachmentIdList& old_attachment_ids, |
43 const SyncData& updated_sync_data) OVERRIDE; | 46 const SyncData& updated_sync_data) OVERRIDE; |
44 | 47 |
45 private: | 48 private: |
46 void ReadDone(const GetOrDownloadCallback& callback, | 49 class GetOrDownloadState; |
| 50 |
| 51 void ReadDone(const scoped_refptr<GetOrDownloadState>& state, |
47 const AttachmentStore::Result& result, | 52 const AttachmentStore::Result& result, |
48 scoped_ptr<AttachmentMap> attachments, | 53 scoped_ptr<AttachmentMap> attachments, |
49 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); | 54 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); |
50 void DropDone(const DropCallback& callback, | 55 void DropDone(const DropCallback& callback, |
51 const AttachmentStore::Result& result); | 56 const AttachmentStore::Result& result); |
52 void WriteDone(const StoreCallback& callback, | 57 void WriteDone(const StoreCallback& callback, |
53 const AttachmentStore::Result& result); | 58 const AttachmentStore::Result& result); |
54 void UploadDone(const AttachmentUploader::UploadResult& result, | 59 void UploadDone(const AttachmentUploader::UploadResult& result, |
55 const AttachmentId& attachment_id); | 60 const AttachmentId& attachment_id); |
| 61 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, |
| 62 const AttachmentId& attachment_id, |
| 63 const AttachmentDownloader::DownloadResult& result, |
| 64 scoped_ptr<Attachment> attachment); |
56 | 65 |
57 const scoped_ptr<AttachmentStore> attachment_store_; | 66 const scoped_ptr<AttachmentStore> attachment_store_; |
58 const scoped_ptr<AttachmentUploader> attachment_uploader_; | 67 const scoped_ptr<AttachmentUploader> attachment_uploader_; |
| 68 const scoped_ptr<AttachmentDownloader> attachment_downloader_; |
59 Delegate* delegate_; | 69 Delegate* delegate_; |
60 // Must be last data member. | 70 // Must be last data member. |
61 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; | 71 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; |
62 | 72 |
63 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); | 73 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); |
64 }; | 74 }; |
65 | 75 |
66 } // namespace syncer | 76 } // namespace syncer |
67 | 77 |
68 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 78 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
OLD | NEW |