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

Side by Side Diff: storage/browser/blob/blob_url_request_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 "storage/browser/blob/blob_url_request_job.h" 5 #include "storage/browser/blob/blob_url_request_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 void BlobURLRequestJob::Kill() { 70 void BlobURLRequestJob::Kill() {
71 if (blob_reader_) { 71 if (blob_reader_) {
72 blob_reader_->Kill(); 72 blob_reader_->Kill();
73 } 73 }
74 net::URLRequestJob::Kill(); 74 net::URLRequestJob::Kill();
75 weak_factory_.InvalidateWeakPtrs(); 75 weak_factory_.InvalidateWeakPtrs();
76 } 76 }
77 77
78 int BlobURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size) { 78 bool BlobURLRequestJob::ReadRawData(net::IOBuffer* dest,
79 int dest_size,
80 int* bytes_read) {
79 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest::ReadRawData", this, "uuid", 81 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest::ReadRawData", this, "uuid",
80 blob_handle_ ? blob_handle_->uuid() : "NotFound"); 82 blob_handle_ ? blob_handle_->uuid() : "NotFound");
81 DCHECK_NE(dest_size, 0); 83 DCHECK_NE(dest_size, 0);
84 DCHECK(bytes_read);
82 85
83 // Bail out immediately if we encounter an error. This happens if a previous 86 // Bail out immediately if we encounter an error.
84 // ReadRawData signalled an error to its caller but the caller called 87 if (error_) {
85 // ReadRawData again anyway. 88 *bytes_read = 0;
86 if (error_) 89 return true;
87 return 0; 90 }
88 91
89 int bytes_read = 0;
90 BlobReader::Status read_status = 92 BlobReader::Status read_status =
91 blob_reader_->Read(dest, dest_size, &bytes_read, 93 blob_reader_->Read(dest, dest_size, bytes_read,
92 base::Bind(&BlobURLRequestJob::DidReadRawData, 94 base::Bind(&BlobURLRequestJob::DidReadRawData,
93 weak_factory_.GetWeakPtr())); 95 weak_factory_.GetWeakPtr()));
94 96
95 switch (read_status) { 97 switch (read_status) {
96 case BlobReader::Status::NET_ERROR: 98 case BlobReader::Status::NET_ERROR:
99 NotifyFailure(blob_reader_->net_error());
97 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid", 100 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid",
98 blob_handle_ ? blob_handle_->uuid() : "NotFound"); 101 blob_handle_ ? blob_handle_->uuid() : "NotFound");
99 return blob_reader_->net_error(); 102 return false;
100 case BlobReader::Status::IO_PENDING: 103 case BlobReader::Status::IO_PENDING:
101 return net::ERR_IO_PENDING; 104 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
105 return false;
102 case BlobReader::Status::DONE: 106 case BlobReader::Status::DONE:
103 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid", 107 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid",
104 blob_handle_ ? blob_handle_->uuid() : "NotFound"); 108 blob_handle_ ? blob_handle_->uuid() : "NotFound");
105 return bytes_read; 109 return true;
106 } 110 }
107 NOTREACHED(); 111 NOTREACHED();
108 return 0; 112 return true;
109 } 113 }
110 114
111 bool BlobURLRequestJob::GetMimeType(std::string* mime_type) const { 115 bool BlobURLRequestJob::GetMimeType(std::string* mime_type) const {
112 if (!response_info_) 116 if (!response_info_)
113 return false; 117 return false;
114 118
115 return response_info_->headers->GetMimeType(mime_type); 119 return response_info_->headers->GetMimeType(mime_type);
116 } 120 }
117 121
118 void BlobURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { 122 void BlobURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 215
212 net::HttpStatusCode status_code = net::HTTP_OK; 216 net::HttpStatusCode status_code = net::HTTP_OK;
213 if (byte_range_set_ && byte_range_.IsValid()) 217 if (byte_range_set_ && byte_range_.IsValid())
214 status_code = net::HTTP_PARTIAL_CONTENT; 218 status_code = net::HTTP_PARTIAL_CONTENT;
215 HeadersCompleted(status_code); 219 HeadersCompleted(status_code);
216 } 220 }
217 221
218 void BlobURLRequestJob::DidReadRawData(int result) { 222 void BlobURLRequestJob::DidReadRawData(int result) {
219 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid", 223 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest::ReadRawData", this, "uuid",
220 blob_handle_ ? blob_handle_->uuid() : "NotFound"); 224 blob_handle_ ? blob_handle_->uuid() : "NotFound");
221 ReadRawDataComplete(result); 225 if (result < 0) {
226 NotifyFailure(result);
227 return;
228 }
229 // Clear the IO_PENDING status
230 SetStatus(net::URLRequestStatus());
231 NotifyReadComplete(result);
222 } 232 }
223 233
224 void BlobURLRequestJob::NotifyFailure(int error_code) { 234 void BlobURLRequestJob::NotifyFailure(int error_code) {
225 error_ = true; 235 error_ = true;
226 236
227 // If we already return the headers on success, we can't change the headers 237 // If we already return the headers on success, we can't change the headers
228 // now. Instead, we just error out. 238 // now. Instead, we just error out.
229 DCHECK(!response_info_) << "Cannot NotifyFailure after headers."; 239 if (response_info_) {
240 NotifyDone(
241 net::URLRequestStatus(net::URLRequestStatus::FAILED, error_code));
242 return;
243 }
230 244
231 net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR; 245 net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR;
232 switch (error_code) { 246 switch (error_code) {
233 case net::ERR_ACCESS_DENIED: 247 case net::ERR_ACCESS_DENIED:
234 status_code = net::HTTP_FORBIDDEN; 248 status_code = net::HTTP_FORBIDDEN;
235 break; 249 break;
236 case net::ERR_FILE_NOT_FOUND: 250 case net::ERR_FILE_NOT_FOUND:
237 status_code = net::HTTP_NOT_FOUND; 251 status_code = net::HTTP_NOT_FOUND;
238 break; 252 break;
239 case net::ERR_METHOD_NOT_SUPPORTED: 253 case net::ERR_METHOD_NOT_SUPPORTED:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 308 }
295 } 309 }
296 310
297 response_info_.reset(new net::HttpResponseInfo()); 311 response_info_.reset(new net::HttpResponseInfo());
298 response_info_->headers = headers; 312 response_info_->headers = headers;
299 313
300 NotifyHeadersComplete(); 314 NotifyHeadersComplete();
301 } 315 }
302 316
303 } // namespace storage 317 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_url_request_job.h ('k') | storage/browser/fileapi/file_system_dir_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698