Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: sync/internal_api/public/attachments/attachment_service_impl.h

Issue 986743004: [Sync] Refactor AttachmentStore classes. Introduce concept of referrer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "net/base/network_change_notifier.h" 13 #include "net/base/network_change_notifier.h"
14 #include "sync/api/attachments/attachment_store.h" 14 #include "sync/api/attachments/attachment_store.h"
15 #include "sync/internal_api/public/attachments/attachment_downloader.h" 15 #include "sync/internal_api/public/attachments/attachment_downloader.h"
16 #include "sync/internal_api/public/attachments/attachment_service.h" 16 #include "sync/internal_api/public/attachments/attachment_service.h"
17 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" 17 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
18 #include "sync/internal_api/public/attachments/attachment_uploader.h" 18 #include "sync/internal_api/public/attachments/attachment_uploader.h"
19 #include "sync/internal_api/public/attachments/task_queue.h" 19 #include "sync/internal_api/public/attachments/task_queue.h"
20 20
21 namespace syncer { 21 namespace syncer {
22 22
23 // Implementation of AttachmentService. 23 // Implementation of AttachmentService.
24 class SYNC_EXPORT AttachmentServiceImpl 24 class SYNC_EXPORT AttachmentServiceImpl
25 : public AttachmentService, 25 : public AttachmentService,
26 public net::NetworkChangeNotifier::NetworkChangeObserver, 26 public net::NetworkChangeNotifier::NetworkChangeObserver,
27 public base::NonThreadSafe { 27 public base::NonThreadSafe {
28 public: 28 public:
29 // |attachment_store| is required. UploadAttachments reads attachment data
30 // from it. Downloaded attachments will be written into it.
31 //
29 // |attachment_uploader| is optional. If null, attachments will never be 32 // |attachment_uploader| is optional. If null, attachments will never be
30 // uploaded to the sync server and |delegate|'s OnAttachmentUploaded will 33 // uploaded to the sync server and |delegate|'s OnAttachmentUploaded will
31 // never be invoked. 34 // never be invoked.
32 // 35 //
33 // |attachment_downloader| is optional. If null, attachments will never be 36 // |attachment_downloader| is optional. If null, attachments will never be
34 // downloaded. Only attachments in |attachment_store| will be returned from 37 // downloaded. Only attachments in |attachment_store| will be returned from
35 // GetOrDownloadAttachments. 38 // GetOrDownloadAttachments.
36 // 39 //
37 // |delegate| is optional delegate for AttachmentService to notify about 40 // |delegate| is optional delegate for AttachmentService to notify about
38 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not 41 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not
39 // provided. AttachmentService doesn't take ownership of delegate, the pointer 42 // provided. AttachmentService doesn't take ownership of delegate, the pointer
40 // must be valid throughout AttachmentService lifetime. 43 // must be valid throughout AttachmentService lifetime.
41 // 44 //
42 // |initial_backoff_delay| the initial delay between upload attempts. This 45 // |initial_backoff_delay| the initial delay between upload attempts. This
43 // class automatically retries failed uploads. After the first failure, it 46 // class automatically retries failed uploads. After the first failure, it
44 // will wait this amount of time until it tries again. After each failure, 47 // will wait this amount of time until it tries again. After each failure,
45 // the delay is doubled until the |max_backoff_delay| is reached. A 48 // the delay is doubled until the |max_backoff_delay| is reached. A
46 // successful upload clears the delay. 49 // successful upload clears the delay.
47 // 50 //
48 // |max_backoff_delay| the maxmium delay between upload attempts when backed 51 // |max_backoff_delay| the maxmium delay between upload attempts when backed
49 // off. 52 // off.
50 AttachmentServiceImpl(scoped_refptr<AttachmentStore> attachment_store, 53 AttachmentServiceImpl(scoped_ptr<AttachmentStore> attachment_store,
51 scoped_ptr<AttachmentUploader> attachment_uploader, 54 scoped_ptr<AttachmentUploader> attachment_uploader,
52 scoped_ptr<AttachmentDownloader> attachment_downloader, 55 scoped_ptr<AttachmentDownloader> attachment_downloader,
53 Delegate* delegate, 56 Delegate* delegate,
54 const base::TimeDelta& initial_backoff_delay, 57 const base::TimeDelta& initial_backoff_delay,
55 const base::TimeDelta& max_backoff_delay); 58 const base::TimeDelta& max_backoff_delay);
56 ~AttachmentServiceImpl() override; 59 ~AttachmentServiceImpl() override;
57 60
58 // Create an AttachmentServiceImpl suitable for use in tests. 61 // Create an AttachmentServiceImpl suitable for use in tests.
59 static scoped_ptr<syncer::AttachmentService> CreateForTest(); 62 static scoped_ptr<syncer::AttachmentService> CreateForTest();
60 63
61 // AttachmentService implementation. 64 // AttachmentService implementation.
62 AttachmentStore* GetStore() override;
63 void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, 65 void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids,
64 const GetOrDownloadCallback& callback) override; 66 const GetOrDownloadCallback& callback) override;
65 void UploadAttachments(const AttachmentIdSet& attachment_ids) override; 67 void UploadAttachments(const AttachmentIdSet& attachment_ids) override;
66 68
67 // NetworkChangeObserver implementation. 69 // NetworkChangeObserver implementation.
68 void OnNetworkChanged( 70 void OnNetworkChanged(
69 net::NetworkChangeNotifier::ConnectionType type) override; 71 net::NetworkChangeNotifier::ConnectionType type) override;
70 72
71 // Use |timer| in the underlying TaskQueue. 73 // Use |timer| in the underlying TaskQueue.
72 // 74 //
(...skipping 15 matching lines...) Expand all
88 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state, 90 void DownloadDone(const scoped_refptr<GetOrDownloadState>& state,
89 const AttachmentId& attachment_id, 91 const AttachmentId& attachment_id,
90 const AttachmentDownloader::DownloadResult& result, 92 const AttachmentDownloader::DownloadResult& result,
91 scoped_ptr<Attachment> attachment); 93 scoped_ptr<Attachment> attachment);
92 void BeginUpload(const AttachmentId& attachment_id); 94 void BeginUpload(const AttachmentId& attachment_id);
93 void ReadDoneNowUpload( 95 void ReadDoneNowUpload(
94 const AttachmentStore::Result& result, 96 const AttachmentStore::Result& result,
95 scoped_ptr<AttachmentMap> attachments, 97 scoped_ptr<AttachmentMap> attachments,
96 scoped_ptr<AttachmentIdList> unavailable_attachment_ids); 98 scoped_ptr<AttachmentIdList> unavailable_attachment_ids);
97 99
98 scoped_refptr<AttachmentStore> attachment_store_; 100 scoped_ptr<AttachmentStore> attachment_store_;
99 101
100 // May be null. 102 // May be null.
101 const scoped_ptr<AttachmentUploader> attachment_uploader_; 103 const scoped_ptr<AttachmentUploader> attachment_uploader_;
102 104
103 // May be null. 105 // May be null.
104 const scoped_ptr<AttachmentDownloader> attachment_downloader_; 106 const scoped_ptr<AttachmentDownloader> attachment_downloader_;
105 107
106 // May be null. 108 // May be null.
107 Delegate* delegate_; 109 Delegate* delegate_;
108 110
109 scoped_ptr<TaskQueue<AttachmentId> > upload_task_queue_; 111 scoped_ptr<TaskQueue<AttachmentId> > upload_task_queue_;
110 112
111 // Must be last data member. 113 // Must be last data member.
112 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_; 114 base::WeakPtrFactory<AttachmentServiceImpl> weak_ptr_factory_;
113 115
114 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl); 116 DISALLOW_COPY_AND_ASSIGN(AttachmentServiceImpl);
115 }; 117 };
116 118
117 } // namespace syncer 119 } // namespace syncer
118 120
119 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_ 121 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698