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/macros.h" | 10 #include "base/macros.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // must be valid throughout AttachmentService lifetime. | 44 // must be valid throughout AttachmentService lifetime. |
45 // | 45 // |
46 // |initial_backoff_delay| the initial delay between upload attempts. This | 46 // |initial_backoff_delay| the initial delay between upload attempts. This |
47 // class automatically retries failed uploads. After the first failure, it | 47 // class automatically retries failed uploads. After the first failure, it |
48 // will wait this amount of time until it tries again. After each failure, | 48 // will wait this amount of time until it tries again. After each failure, |
49 // the delay is doubled until the |max_backoff_delay| is reached. A | 49 // the delay is doubled until the |max_backoff_delay| is reached. A |
50 // successful upload clears the delay. | 50 // successful upload clears the delay. |
51 // | 51 // |
52 // |max_backoff_delay| the maxmium delay between upload attempts when backed | 52 // |max_backoff_delay| the maxmium delay between upload attempts when backed |
53 // off. | 53 // off. |
54 AttachmentServiceImpl(scoped_ptr<AttachmentStoreForSync> attachment_store, | 54 AttachmentServiceImpl( |
55 scoped_ptr<AttachmentUploader> attachment_uploader, | 55 std::unique_ptr<AttachmentStoreForSync> attachment_store, |
56 scoped_ptr<AttachmentDownloader> attachment_downloader, | 56 std::unique_ptr<AttachmentUploader> attachment_uploader, |
57 Delegate* delegate, | 57 std::unique_ptr<AttachmentDownloader> attachment_downloader, |
58 const base::TimeDelta& initial_backoff_delay, | 58 Delegate* delegate, |
59 const base::TimeDelta& max_backoff_delay); | 59 const base::TimeDelta& initial_backoff_delay, |
| 60 const base::TimeDelta& max_backoff_delay); |
60 ~AttachmentServiceImpl() override; | 61 ~AttachmentServiceImpl() override; |
61 | 62 |
62 // Create an AttachmentServiceImpl suitable for use in tests. | 63 // Create an AttachmentServiceImpl suitable for use in tests. |
63 static scoped_ptr<syncer::AttachmentService> CreateForTest(); | 64 static std::unique_ptr<syncer::AttachmentService> CreateForTest(); |
64 | 65 |
65 // AttachmentService implementation. | 66 // AttachmentService implementation. |
66 void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, | 67 void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, |
67 const GetOrDownloadCallback& callback) override; | 68 const GetOrDownloadCallback& callback) override; |
68 void UploadAttachments(const AttachmentIdList& attachment_ids) override; | 69 void UploadAttachments(const AttachmentIdList& attachment_ids) override; |
69 | 70 |
70 // NetworkChangeObserver implementation. | 71 // NetworkChangeObserver implementation. |
71 void OnNetworkChanged( | 72 void OnNetworkChanged( |
72 net::NetworkChangeNotifier::ConnectionType type) override; | 73 net::NetworkChangeNotifier::ConnectionType type) override; |
73 | 74 |
74 // Use |timer| in the underlying TaskQueue. | 75 // Use |timer| in the underlying TaskQueue. |
75 // | 76 // |
76 // Used in tests. See also MockTimer. | 77 // Used in tests. See also MockTimer. |
77 void SetTimerForTest(scoped_ptr<base::Timer> timer); | 78 void SetTimerForTest(std::unique_ptr<base::Timer> timer); |
78 | 79 |
79 private: | 80 private: |
80 class GetOrDownloadState; | 81 class GetOrDownloadState; |
81 | 82 |
82 void ReadDone(const scoped_refptr<GetOrDownloadState>& state, | 83 void ReadDone(const scoped_refptr<GetOrDownloadState>& state, |
83 const AttachmentStore::Result& result, | 84 const AttachmentStore::Result& result, |
84 scoped_ptr<AttachmentMap> attachments, | 85 std::unique_ptr<AttachmentMap> attachments, |
85 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); | 86 std::unique_ptr<AttachmentIdList> unavailable_attachment_ids); |
86 void WriteDone(const scoped_refptr<GetOrDownloadState>& state, | 87 void WriteDone(const scoped_refptr<GetOrDownloadState>& state, |
87 const Attachment& attachment, | 88 const Attachment& attachment, |
88 const AttachmentStore::Result& result); | 89 const AttachmentStore::Result& result); |
89 void UploadDone(const AttachmentUploader::UploadResult& result, | 90 void UploadDone(const AttachmentUploader::UploadResult& result, |
90 const AttachmentId& attachment_id); | 91 const AttachmentId& attachment_id); |
91 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, | 92 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, |
92 const AttachmentId& attachment_id, | 93 const AttachmentId& attachment_id, |
93 const AttachmentDownloader::DownloadResult& result, | 94 const AttachmentDownloader::DownloadResult& result, |
94 scoped_ptr<Attachment> attachment); | 95 std::unique_ptr<Attachment> attachment); |
95 void BeginUpload(const AttachmentId& attachment_id); | 96 void BeginUpload(const AttachmentId& attachment_id); |
96 void ReadDoneNowUpload( | 97 void ReadDoneNowUpload( |
97 const AttachmentStore::Result& result, | 98 const AttachmentStore::Result& result, |
98 scoped_ptr<AttachmentMap> attachments, | 99 std::unique_ptr<AttachmentMap> attachments, |
99 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); | 100 std::unique_ptr<AttachmentIdList> unavailable_attachment_ids); |
100 | 101 |
101 scoped_ptr<AttachmentStoreForSync> attachment_store_; | 102 std::unique_ptr<AttachmentStoreForSync> attachment_store_; |
102 | 103 |
103 // May be null. | 104 // May be null. |
104 const scoped_ptr<AttachmentUploader> attachment_uploader_; | 105 const std::unique_ptr<AttachmentUploader> attachment_uploader_; |
105 | 106 |
106 // May be null. | 107 // May be null. |
107 const scoped_ptr<AttachmentDownloader> attachment_downloader_; | 108 const std::unique_ptr<AttachmentDownloader> attachment_downloader_; |
108 | 109 |
109 // May be null. | 110 // May be null. |
110 Delegate* delegate_; | 111 Delegate* delegate_; |
111 | 112 |
112 scoped_ptr<TaskQueue<AttachmentId> > upload_task_queue_; | 113 std::unique_ptr<TaskQueue<AttachmentId>> upload_task_queue_; |
113 | 114 |
114 // Must be last data member. | 115 // Must be last data member. |
115 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; | 116 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; |
116 | 117 |
117 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); | 118 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); |
118 }; | 119 }; |
119 | 120 |
120 } // namespace syncer | 121 } // namespace syncer |
121 | 122 |
122 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ | 123 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ |
OLD | NEW |