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

Side by Side Diff: sync/internal_api/attachments/attachment_service_impl.cc

Issue 996473005: Revert of [Sync] Refactor AttachmentStore classes. Introduce concept of referrer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 #include "sync/internal_api/public/attachments/attachment_service_impl.h" 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // All requests completed. Let's notify consumer. 103 // All requests completed. Let's notify consumer.
104 GetOrDownloadResult result = 104 GetOrDownloadResult result =
105 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; 105 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR;
106 base::MessageLoop::current()->PostTask( 106 base::MessageLoop::current()->PostTask(
107 FROM_HERE, 107 FROM_HERE,
108 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); 108 base::Bind(callback_, result, base::Passed(&retrieved_attachments_)));
109 } 109 }
110 } 110 }
111 111
112 AttachmentServiceImpl::AttachmentServiceImpl( 112 AttachmentServiceImpl::AttachmentServiceImpl(
113 scoped_ptr<AttachmentStore> attachment_store, 113 scoped_refptr<AttachmentStore> attachment_store,
114 scoped_ptr<AttachmentUploader> attachment_uploader, 114 scoped_ptr<AttachmentUploader> attachment_uploader,
115 scoped_ptr<AttachmentDownloader> attachment_downloader, 115 scoped_ptr<AttachmentDownloader> attachment_downloader,
116 Delegate* delegate, 116 Delegate* delegate,
117 const base::TimeDelta& initial_backoff_delay, 117 const base::TimeDelta& initial_backoff_delay,
118 const base::TimeDelta& max_backoff_delay) 118 const base::TimeDelta& max_backoff_delay)
119 : attachment_store_(attachment_store.Pass()), 119 : attachment_store_(attachment_store),
120 attachment_uploader_(attachment_uploader.Pass()), 120 attachment_uploader_(attachment_uploader.Pass()),
121 attachment_downloader_(attachment_downloader.Pass()), 121 attachment_downloader_(attachment_downloader.Pass()),
122 delegate_(delegate), 122 delegate_(delegate),
123 weak_ptr_factory_(this) { 123 weak_ptr_factory_(this) {
124 DCHECK(CalledOnValidThread()); 124 DCHECK(CalledOnValidThread());
125 DCHECK(attachment_store_.get()); 125 DCHECK(attachment_store_.get());
126 126
127 // TODO(maniscalco): Observe network connectivity change events. When the 127 // TODO(maniscalco): Observe network connectivity change events. When the
128 // network becomes disconnected, consider suspending queue dispatch. When 128 // network becomes disconnected, consider suspending queue dispatch. When
129 // connectivity is restored, consider clearing any dispatch backoff (bug 129 // connectivity is restored, consider clearing any dispatch backoff (bug
130 // 411981). 130 // 411981).
131 upload_task_queue_.reset(new TaskQueue<AttachmentId>( 131 upload_task_queue_.reset(new TaskQueue<AttachmentId>(
132 base::Bind(&AttachmentServiceImpl::BeginUpload, 132 base::Bind(&AttachmentServiceImpl::BeginUpload,
133 weak_ptr_factory_.GetWeakPtr()), 133 weak_ptr_factory_.GetWeakPtr()),
134 initial_backoff_delay, 134 initial_backoff_delay,
135 max_backoff_delay)); 135 max_backoff_delay));
136 136
137 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 137 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
138 } 138 }
139 139
140 AttachmentServiceImpl::~AttachmentServiceImpl() { 140 AttachmentServiceImpl::~AttachmentServiceImpl() {
141 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
142 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 142 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
143 } 143 }
144 144
145 // Static. 145 // Static.
146 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { 146 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() {
147 scoped_ptr<syncer::AttachmentStore> attachment_store = 147 scoped_refptr<syncer::AttachmentStore> attachment_store =
148 AttachmentStore::CreateInMemoryStore(); 148 AttachmentStore::CreateInMemoryStore();
149 scoped_ptr<AttachmentUploader> attachment_uploader( 149 scoped_ptr<AttachmentUploader> attachment_uploader(
150 new FakeAttachmentUploader); 150 new FakeAttachmentUploader);
151 scoped_ptr<AttachmentDownloader> attachment_downloader( 151 scoped_ptr<AttachmentDownloader> attachment_downloader(
152 new FakeAttachmentDownloader()); 152 new FakeAttachmentDownloader());
153 scoped_ptr<syncer::AttachmentService> attachment_service( 153 scoped_ptr<syncer::AttachmentService> attachment_service(
154 new syncer::AttachmentServiceImpl(attachment_store.Pass(), 154 new syncer::AttachmentServiceImpl(attachment_store,
155 attachment_uploader.Pass(), 155 attachment_uploader.Pass(),
156 attachment_downloader.Pass(), 156 attachment_downloader.Pass(),
157 NULL, 157 NULL,
158 base::TimeDelta(), 158 base::TimeDelta(),
159 base::TimeDelta())); 159 base::TimeDelta()));
160 return attachment_service.Pass(); 160 return attachment_service.Pass();
161 } 161 }
162 162
163 AttachmentStore* AttachmentServiceImpl::GetStore() {
164 return attachment_store_.get();
165 }
166
163 void AttachmentServiceImpl::GetOrDownloadAttachments( 167 void AttachmentServiceImpl::GetOrDownloadAttachments(
164 const AttachmentIdList& attachment_ids, 168 const AttachmentIdList& attachment_ids,
165 const GetOrDownloadCallback& callback) { 169 const GetOrDownloadCallback& callback) {
166 DCHECK(CalledOnValidThread()); 170 DCHECK(CalledOnValidThread());
167 scoped_refptr<GetOrDownloadState> state( 171 scoped_refptr<GetOrDownloadState> state(
168 new GetOrDownloadState(attachment_ids, callback)); 172 new GetOrDownloadState(attachment_ids, callback));
169 attachment_store_->Read(attachment_ids, 173 attachment_store_->Read(attachment_ids,
170 base::Bind(&AttachmentServiceImpl::ReadDone, 174 base::Bind(&AttachmentServiceImpl::ReadDone,
171 weak_ptr_factory_.GetWeakPtr(), state)); 175 weak_ptr_factory_.GetWeakPtr(),
176 state));
172 } 177 }
173 178
174 void AttachmentServiceImpl::ReadDone( 179 void AttachmentServiceImpl::ReadDone(
175 const scoped_refptr<GetOrDownloadState>& state, 180 const scoped_refptr<GetOrDownloadState>& state,
176 const AttachmentStore::Result& result, 181 const AttachmentStore::Result& result,
177 scoped_ptr<AttachmentMap> attachments, 182 scoped_ptr<AttachmentMap> attachments,
178 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) { 183 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) {
179 // Add read attachments to result. 184 // Add read attachments to result.
180 for (AttachmentMap::const_iterator iter = attachments->begin(); 185 for (AttachmentMap::const_iterator iter = attachments->begin();
181 iter != attachments->end(); 186 iter != attachments->end();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::Bind(&AttachmentServiceImpl::UploadDone, 320 base::Bind(&AttachmentServiceImpl::UploadDone,
316 weak_ptr_factory_.GetWeakPtr())); 321 weak_ptr_factory_.GetWeakPtr()));
317 } 322 }
318 } 323 }
319 324
320 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { 325 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) {
321 upload_task_queue_->SetTimerForTest(timer.Pass()); 326 upload_task_queue_->SetTimerForTest(timer.Pass());
322 } 327 }
323 328
324 } // namespace syncer 329 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/syncable_service.cc ('k') | sync/internal_api/attachments/attachment_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698