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

Side by Side Diff: net/test/url_request/url_request_slow_download_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/test/url_request/url_request_slow_download_job.h" 5 #include "net/test/url_request/url_request_slow_download_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 buf->data()[i] = '*'; 172 buf->data()[i] = '*';
173 } 173 }
174 *bytes_written = bytes_to_write; 174 *bytes_written = bytes_to_write;
175 bytes_already_sent_ += bytes_to_write; 175 bytes_already_sent_ += bytes_to_write;
176 return BUFFER_FILLED; 176 return BUFFER_FILLED;
177 } 177 }
178 178
179 return REQUEST_COMPLETE; 179 return REQUEST_COMPLETE;
180 } 180 }
181 181
182 int URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf, int buf_size) { 182 bool URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf,
183 int buf_size,
184 int* bytes_read) {
183 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl, 185 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl,
184 request_->url().spec().c_str()) || 186 request_->url().spec().c_str()) ||
185 base::LowerCaseEqualsASCII(kErrorDownloadUrl, 187 base::LowerCaseEqualsASCII(kErrorDownloadUrl,
186 request_->url().spec().c_str())) { 188 request_->url().spec().c_str())) {
187 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl."; 189 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl.";
188 return 0; 190 *bytes_read = 0;
191 return true;
189 } 192 }
190 193
191 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_ 194 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_
192 << " in the stream."; 195 << " in the stream.";
193 int bytes_read = 0; 196 ReadStatus status = FillBufferHelper(buf, buf_size, bytes_read);
194 ReadStatus status = FillBufferHelper(buf, buf_size, &bytes_read);
195 switch (status) { 197 switch (status) {
196 case BUFFER_FILLED: 198 case BUFFER_FILLED:
197 case REQUEST_COMPLETE: 199 return true;
198 return bytes_read;
199 case REQUEST_BLOCKED: 200 case REQUEST_BLOCKED:
200 buffer_ = buf; 201 buffer_ = buf;
201 buffer_size_ = buf_size; 202 buffer_size_ = buf_size;
203 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
202 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 204 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
203 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus, 205 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus,
204 weak_factory_.GetWeakPtr()), 206 weak_factory_.GetWeakPtr()),
205 base::TimeDelta::FromMilliseconds(100)); 207 base::TimeDelta::FromMilliseconds(100));
206 return ERR_IO_PENDING; 208 return false;
209 case REQUEST_COMPLETE:
210 *bytes_read = 0;
211 return true;
207 } 212 }
208 NOTREACHED(); 213 NOTREACHED();
209 return OK; 214 return true;
210 } 215 }
211 216
212 void URLRequestSlowDownloadJob::CheckDoneStatus() { 217 void URLRequestSlowDownloadJob::CheckDoneStatus() {
213 if (should_finish_download_) { 218 if (should_finish_download_) {
214 VLOG(10) << __FUNCTION__ << " called w/ should_finish_download_ set."; 219 VLOG(10) << __FUNCTION__ << " called w/ should_finish_download_ set.";
215 DCHECK(NULL != buffer_.get()); 220 DCHECK(NULL != buffer_.get());
216 int bytes_written = 0; 221 int bytes_written = 0;
217 ReadStatus status = 222 ReadStatus status =
218 FillBufferHelper(buffer_.get(), buffer_size_, &bytes_written); 223 FillBufferHelper(buffer_.get(), buffer_size_, &bytes_written);
219 DCHECK_EQ(BUFFER_FILLED, status); 224 DCHECK_EQ(BUFFER_FILLED, status);
220 buffer_ = NULL; // Release the reference. 225 buffer_ = NULL; // Release the reference.
221 ReadRawDataComplete(bytes_written); 226 SetStatus(URLRequestStatus());
227 NotifyReadComplete(bytes_written);
222 } else if (should_error_download_) { 228 } else if (should_error_download_) {
223 VLOG(10) << __FUNCTION__ << " called w/ should_finish_ownload_ set."; 229 VLOG(10) << __FUNCTION__ << " called w/ should_finish_ownload_ set.";
224 ReadRawDataComplete(ERR_CONNECTION_RESET); 230 NotifyDone(
231 URLRequestStatus(URLRequestStatus::FAILED, ERR_CONNECTION_RESET));
225 } else { 232 } else {
226 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 233 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
227 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus, 234 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus,
228 weak_factory_.GetWeakPtr()), 235 weak_factory_.GetWeakPtr()),
229 base::TimeDelta::FromMilliseconds(100)); 236 base::TimeDelta::FromMilliseconds(100));
230 } 237 }
231 } 238 }
232 239
233 // Public virtual version. 240 // Public virtual version.
234 void URLRequestSlowDownloadJob::GetResponseInfo(HttpResponseInfo* info) { 241 void URLRequestSlowDownloadJob::GetResponseInfo(HttpResponseInfo* info) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 info->headers = new HttpResponseHeaders(raw_headers); 278 info->headers = new HttpResponseHeaders(raw_headers);
272 } 279 }
273 280
274 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { 281 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const {
275 HttpResponseInfo info; 282 HttpResponseInfo info;
276 GetResponseInfoConst(&info); 283 GetResponseInfoConst(&info);
277 return info.headers.get() && info.headers->GetMimeType(mime_type); 284 return info.headers.get() && info.headers->GetMimeType(mime_type);
278 } 285 }
279 286
280 } // namespace net 287 } // namespace net
OLDNEW
« no previous file with comments | « net/test/url_request/url_request_slow_download_job.h ('k') | net/url_request/url_request_file_dir_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698