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

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

Issue 1439953006: Reland: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address David's comment 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 bool URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf, 182 int URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf, int buf_size) {
183 int buf_size,
184 int* bytes_read) {
185 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl, 183 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl,
186 request_->url().spec().c_str()) || 184 request_->url().spec().c_str()) ||
187 base::LowerCaseEqualsASCII(kErrorDownloadUrl, 185 base::LowerCaseEqualsASCII(kErrorDownloadUrl,
188 request_->url().spec().c_str())) { 186 request_->url().spec().c_str())) {
189 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl."; 187 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl.";
190 *bytes_read = 0; 188 return 0;
191 return true;
192 } 189 }
193 190
194 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_ 191 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_
195 << " in the stream."; 192 << " in the stream.";
196 ReadStatus status = FillBufferHelper(buf, buf_size, bytes_read); 193 int bytes_read = 0;
194 ReadStatus status = FillBufferHelper(buf, buf_size, &bytes_read);
197 switch (status) { 195 switch (status) {
198 case BUFFER_FILLED: 196 case BUFFER_FILLED:
199 return true; 197 case REQUEST_COMPLETE:
198 return bytes_read;
200 case REQUEST_BLOCKED: 199 case REQUEST_BLOCKED:
201 buffer_ = buf; 200 buffer_ = buf;
202 buffer_size_ = buf_size; 201 buffer_size_ = buf_size;
203 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
204 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 202 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
205 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus, 203 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus,
206 weak_factory_.GetWeakPtr()), 204 weak_factory_.GetWeakPtr()),
207 base::TimeDelta::FromMilliseconds(100)); 205 base::TimeDelta::FromMilliseconds(100));
208 return false; 206 return ERR_IO_PENDING;
209 case REQUEST_COMPLETE:
210 *bytes_read = 0;
211 return true;
212 } 207 }
213 NOTREACHED(); 208 NOTREACHED();
214 return true; 209 return OK;
215 } 210 }
216 211
217 void URLRequestSlowDownloadJob::CheckDoneStatus() { 212 void URLRequestSlowDownloadJob::CheckDoneStatus() {
218 if (should_finish_download_) { 213 if (should_finish_download_) {
219 VLOG(10) << __FUNCTION__ << " called w/ should_finish_download_ set."; 214 VLOG(10) << __FUNCTION__ << " called w/ should_finish_download_ set.";
220 DCHECK(NULL != buffer_.get()); 215 DCHECK(NULL != buffer_.get());
221 int bytes_written = 0; 216 int bytes_written = 0;
222 ReadStatus status = 217 ReadStatus status =
223 FillBufferHelper(buffer_.get(), buffer_size_, &bytes_written); 218 FillBufferHelper(buffer_.get(), buffer_size_, &bytes_written);
224 DCHECK_EQ(BUFFER_FILLED, status); 219 DCHECK_EQ(BUFFER_FILLED, status);
225 buffer_ = NULL; // Release the reference. 220 buffer_ = NULL; // Release the reference.
226 SetStatus(URLRequestStatus()); 221 ReadRawDataComplete(bytes_written);
227 NotifyReadComplete(bytes_written);
228 } else if (should_error_download_) { 222 } else if (should_error_download_) {
229 VLOG(10) << __FUNCTION__ << " called w/ should_finish_ownload_ set."; 223 VLOG(10) << __FUNCTION__ << " called w/ should_finish_ownload_ set.";
230 NotifyDone( 224 ReadRawDataComplete(ERR_CONNECTION_RESET);
231 URLRequestStatus(URLRequestStatus::FAILED, ERR_CONNECTION_RESET));
232 } else { 225 } else {
233 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 226 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
234 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus, 227 FROM_HERE, base::Bind(&URLRequestSlowDownloadJob::CheckDoneStatus,
235 weak_factory_.GetWeakPtr()), 228 weak_factory_.GetWeakPtr()),
236 base::TimeDelta::FromMilliseconds(100)); 229 base::TimeDelta::FromMilliseconds(100));
237 } 230 }
238 } 231 }
239 232
240 // Public virtual version. 233 // Public virtual version.
241 void URLRequestSlowDownloadJob::GetResponseInfo(HttpResponseInfo* info) { 234 void URLRequestSlowDownloadJob::GetResponseInfo(HttpResponseInfo* info) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 info->headers = new HttpResponseHeaders(raw_headers); 271 info->headers = new HttpResponseHeaders(raw_headers);
279 } 272 }
280 273
281 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { 274 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const {
282 HttpResponseInfo info; 275 HttpResponseInfo info;
283 GetResponseInfoConst(&info); 276 GetResponseInfoConst(&info);
284 return info.headers.get() && info.headers->GetMimeType(mime_type); 277 return info.headers.get() && info.headers->GetMimeType(mime_type);
285 } 278 }
286 279
287 } // namespace net 280 } // 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