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

Side by Side Diff: storage/browser/blob/blob_url_request_job.cc

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