| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (!blob_handle->content_disposition().empty()) { | 184 if (!blob_handle->content_disposition().empty()) { |
| 185 std::string content_disposition_header("Content-Disposition: "); | 185 std::string content_disposition_header("Content-Disposition: "); |
| 186 content_disposition_header.append(blob_handle->content_disposition()); | 186 content_disposition_header.append(blob_handle->content_disposition()); |
| 187 headers->AddHeader(content_disposition_header); | 187 headers->AddHeader(content_disposition_header); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 return headers; | 191 return headers; |
| 192 } | 192 } |
| 193 | 193 |
| 194 net::HttpStatusCode BlobURLRequestJob::NetErrorToHttpStatusCode( | |
| 195 int error_code) { | |
| 196 net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR; | |
| 197 switch (error_code) { | |
| 198 case net::ERR_ACCESS_DENIED: | |
| 199 status_code = net::HTTP_FORBIDDEN; | |
| 200 break; | |
| 201 case net::ERR_FILE_NOT_FOUND: | |
| 202 status_code = net::HTTP_NOT_FOUND; | |
| 203 break; | |
| 204 case net::ERR_METHOD_NOT_SUPPORTED: | |
| 205 status_code = net::HTTP_METHOD_NOT_ALLOWED; | |
| 206 break; | |
| 207 case net::ERR_REQUEST_RANGE_NOT_SATISFIABLE: | |
| 208 status_code = net::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE; | |
| 209 break; | |
| 210 case net::ERR_INVALID_ARGUMENT: | |
| 211 status_code = net::HTTP_BAD_REQUEST; | |
| 212 break; | |
| 213 case net::ERR_CACHE_READ_FAILURE: | |
| 214 case net::ERR_CACHE_CHECKSUM_READ_FAILURE: | |
| 215 case net::ERR_UNEXPECTED: | |
| 216 case net::ERR_FAILED: | |
| 217 break; | |
| 218 default: | |
| 219 DCHECK(false) << "Error code not supported: " << error_code; | |
| 220 break; | |
| 221 } | |
| 222 return status_code; | |
| 223 } | |
| 224 | |
| 225 BlobURLRequestJob::~BlobURLRequestJob() { | 194 BlobURLRequestJob::~BlobURLRequestJob() { |
| 226 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest", this, "uuid", | 195 TRACE_EVENT_ASYNC_END1("Blob", "BlobRequest", this, "uuid", |
| 227 blob_handle_ ? blob_handle_->uuid() : "NotFound"); | 196 blob_handle_ ? blob_handle_->uuid() : "NotFound"); |
| 228 } | 197 } |
| 229 | 198 |
| 230 void BlobURLRequestJob::DidStart() { | 199 void BlobURLRequestJob::DidStart() { |
| 231 error_ = false; | 200 error_ = false; |
| 232 | 201 |
| 233 // We only support GET request per the spec. | 202 // We only support GET request per the spec. |
| 234 if (request()->method() != "GET") { | 203 if (request()->method() != "GET") { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 ReadRawDataComplete(result); | 285 ReadRawDataComplete(result); |
| 317 } | 286 } |
| 318 | 287 |
| 319 void BlobURLRequestJob::NotifyFailure(int error_code) { | 288 void BlobURLRequestJob::NotifyFailure(int error_code) { |
| 320 error_ = true; | 289 error_ = true; |
| 321 | 290 |
| 322 // If we already return the headers on success, we can't change the headers | 291 // If we already return the headers on success, we can't change the headers |
| 323 // now. Instead, we just error out. | 292 // now. Instead, we just error out. |
| 324 DCHECK(!response_info_) << "Cannot NotifyFailure after headers."; | 293 DCHECK(!response_info_) << "Cannot NotifyFailure after headers."; |
| 325 | 294 |
| 326 HeadersCompleted(NetErrorToHttpStatusCode(error_code)); | 295 NotifyStartError(net::URLRequestStatus::FromError(error_code)); |
| 327 } | 296 } |
| 328 | 297 |
| 329 void BlobURLRequestJob::HeadersCompleted(net::HttpStatusCode status_code) { | 298 void BlobURLRequestJob::HeadersCompleted(net::HttpStatusCode status_code) { |
| 330 int64_t content_size = 0; | 299 int64_t content_size = 0; |
| 331 response_info_.reset(new net::HttpResponseInfo()); | 300 response_info_.reset(new net::HttpResponseInfo()); |
| 332 response_info_->headers = | 301 response_info_->headers = |
| 333 GenerateHeaders(status_code, blob_handle_.get(), blob_reader_.get(), | 302 GenerateHeaders(status_code, blob_handle_.get(), blob_reader_.get(), |
| 334 &byte_range_, &content_size); | 303 &byte_range_, &content_size); |
| 335 set_expected_content_size(content_size); | 304 set_expected_content_size(content_size); |
| 336 if (blob_reader_) | 305 if (blob_reader_) |
| 337 response_info_->metadata = blob_reader_->side_data(); | 306 response_info_->metadata = blob_reader_->side_data(); |
| 338 | 307 |
| 339 NotifyHeadersComplete(); | 308 NotifyHeadersComplete(); |
| 340 } | 309 } |
| 341 | 310 |
| 342 } // namespace storage | 311 } // namespace storage |
| OLD | NEW |