| 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_IMPL_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "sync/api/attachments/attachment_store.h" | 13 #include "sync/api/attachments/attachment_store.h" |
| 14 #include "sync/internal_api/public/attachments/attachment_downloader.h" | 14 #include "sync/internal_api/public/attachments/attachment_downloader.h" |
| 15 #include "sync/internal_api/public/attachments/attachment_service.h" | 15 #include "sync/internal_api/public/attachments/attachment_service.h" |
| 16 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" | 16 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" |
| 17 #include "sync/internal_api/public/attachments/attachment_uploader.h" | 17 #include "sync/internal_api/public/attachments/attachment_uploader.h" |
| 18 #include "sync/internal_api/public/attachments/task_queue.h" |
| 18 | 19 |
| 19 namespace syncer { | 20 namespace syncer { |
| 20 | 21 |
| 21 // Implementation of AttachmentService. | 22 // Implementation of AttachmentService. |
| 22 class SYNC_EXPORT AttachmentServiceImpl : public AttachmentService, | 23 class SYNC_EXPORT AttachmentServiceImpl : public AttachmentService, |
| 23 public base::NonThreadSafe { | 24 public base::NonThreadSafe { |
| 24 public: | 25 public: |
| 25 // |delegate| is optional delegate for AttachmentService to notify about | |
| 26 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not | |
| 27 // provided. AttachmentService doesn't take ownership of delegate, the pointer | |
| 28 // must be valid throughout AttachmentService lifetime. | |
| 29 // | |
| 30 // |attachment_uploader| is optional. If null, attachments will never be | 26 // |attachment_uploader| is optional. If null, attachments will never be |
| 31 // uploaded to the sync server and |delegate|'s OnAttachmentUploaded will | 27 // uploaded to the sync server and |delegate|'s OnAttachmentUploaded will |
| 32 // never be invoked. | 28 // never be invoked. |
| 33 // | 29 // |
| 34 // |attachment_downloader| is optional. If null, attachments will never be | 30 // |attachment_downloader| is optional. If null, attachments will never be |
| 35 // downloaded. Only attachments in |attachment_store| will be returned from | 31 // downloaded. Only attachments in |attachment_store| will be returned from |
| 36 // GetOrDownloadAttachments. | 32 // GetOrDownloadAttachments. |
| 37 | 33 // |
| 34 // |delegate| is optional delegate for AttachmentService to notify about |
| 35 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not |
| 36 // provided. AttachmentService doesn't take ownership of delegate, the pointer |
| 37 // must be valid throughout AttachmentService lifetime. |
| 38 // |
| 39 // |initial_backoff_delay| the initial delay between upload attempts. This |
| 40 // class automatically retries failed uploads. After the first failure, it |
| 41 // will wait this amount of time until it tries again. After each failure, |
| 42 // the delay is doubled until the |max_backoff_delay| is reached. A |
| 43 // successful upload clears the delay. |
| 44 // |
| 45 // |max_backoff_delay| the maxmium delay between upload attempts when backed |
| 46 // off. |
| 38 AttachmentServiceImpl(scoped_ptr<AttachmentStore> attachment_store, | 47 AttachmentServiceImpl(scoped_ptr<AttachmentStore> attachment_store, |
| 39 scoped_ptr<AttachmentUploader> attachment_uploader, | 48 scoped_ptr<AttachmentUploader> attachment_uploader, |
| 40 scoped_ptr<AttachmentDownloader> attachment_downloader, | 49 scoped_ptr<AttachmentDownloader> attachment_downloader, |
| 41 Delegate* delegate); | 50 Delegate* delegate, |
| 51 const base::TimeDelta& initial_backoff_delay, |
| 52 const base::TimeDelta& max_backoff_delay); |
| 42 virtual ~AttachmentServiceImpl(); | 53 virtual ~AttachmentServiceImpl(); |
| 43 | 54 |
| 44 // Create an AttachmentServiceImpl suitable for use in tests. | 55 // Create an AttachmentServiceImpl suitable for use in tests. |
| 45 static scoped_ptr<syncer::AttachmentService> CreateForTest(); | 56 static scoped_ptr<syncer::AttachmentService> CreateForTest(); |
| 46 | 57 |
| 47 // AttachmentService implementation. | 58 // AttachmentService implementation. |
| 48 virtual AttachmentStore* GetStore() OVERRIDE; | 59 virtual AttachmentStore* GetStore() OVERRIDE; |
| 49 virtual void GetOrDownloadAttachments( | 60 virtual void GetOrDownloadAttachments( |
| 50 const AttachmentIdList& attachment_ids, | 61 const AttachmentIdList& attachment_ids, |
| 51 const GetOrDownloadCallback& callback) OVERRIDE; | 62 const GetOrDownloadCallback& callback) OVERRIDE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 scoped_ptr<AttachmentMap> attachments, | 73 scoped_ptr<AttachmentMap> attachments, |
| 63 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); | 74 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); |
| 64 void DropDone(const DropCallback& callback, | 75 void DropDone(const DropCallback& callback, |
| 65 const AttachmentStore::Result& result); | 76 const AttachmentStore::Result& result); |
| 66 void UploadDone(const AttachmentUploader::UploadResult& result, | 77 void UploadDone(const AttachmentUploader::UploadResult& result, |
| 67 const AttachmentId& attachment_id); | 78 const AttachmentId& attachment_id); |
| 68 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, | 79 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, |
| 69 const AttachmentId& attachment_id, | 80 const AttachmentId& attachment_id, |
| 70 const AttachmentDownloader::DownloadResult& result, | 81 const AttachmentDownloader::DownloadResult& result, |
| 71 scoped_ptr<Attachment> attachment); | 82 scoped_ptr<Attachment> attachment); |
| 72 void ProcessQueuedUploads(); | 83 void BeginUpload(const AttachmentId& attachment_id); |
| 73 void ReadDoneNowUpload( | 84 void ReadDoneNowUpload( |
| 74 const AttachmentStore::Result& result, | 85 const AttachmentStore::Result& result, |
| 75 scoped_ptr<AttachmentMap> attachments, | 86 scoped_ptr<AttachmentMap> attachments, |
| 76 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); | 87 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); |
| 77 | 88 |
| 78 const scoped_ptr<AttachmentStore> attachment_store_; | 89 const scoped_ptr<AttachmentStore> attachment_store_; |
| 79 | 90 |
| 80 // May be null. | 91 // May be null. |
| 81 const scoped_ptr<AttachmentUploader> attachment_uploader_; | 92 const scoped_ptr<AttachmentUploader> attachment_uploader_; |
| 82 | 93 |
| 83 // May be null. | 94 // May be null. |
| 84 const scoped_ptr<AttachmentDownloader> attachment_downloader_; | 95 const scoped_ptr<AttachmentDownloader> attachment_downloader_; |
| 85 | 96 |
| 86 // May be null. | 97 // May be null. |
| 87 Delegate* delegate_; | 98 Delegate* delegate_; |
| 88 | 99 |
| 89 // Queue of attachment ids to be uploaded. Every entry in this queue should | 100 scoped_ptr<TaskQueue<AttachmentId> > upload_task_queue_; |
| 90 // also exist in ids_in_queue_. | |
| 91 std::deque<AttachmentId> queue_; | |
| 92 | |
| 93 // Ids of attachments currently being uploaded or queued for upload. | |
| 94 AttachmentIdSet ids_in_queue_; | |
| 95 | 101 |
| 96 // Must be last data member. | 102 // Must be last data member. |
| 97 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; | 103 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; |
| 98 | 104 |
| 99 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); | 105 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); |
| 100 }; | 106 }; |
| 101 | 107 |
| 102 } // namespace syncer | 108 } // namespace syncer |
| 103 | 109 |
| 104 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 110 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
| OLD | NEW |