OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/service_worker/service_worker_blob_reader.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "storage/browser/blob/blob_data_handle.h" |
| 10 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 ServiceWorkerBlobReader::ServiceWorkerBlobReader( |
| 15 ServiceWorkerURLRequestJob* owner) |
| 16 : owner_(owner) {} |
| 17 |
| 18 ServiceWorkerBlobReader::~ServiceWorkerBlobReader() {} |
| 19 |
| 20 void ServiceWorkerBlobReader::Start( |
| 21 std::unique_ptr<storage::BlobDataHandle> blob_data_handle, |
| 22 const net::URLRequestContext* request_context) { |
| 23 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( |
| 24 std::move(blob_data_handle), request_context, this); |
| 25 blob_request_->Start(); |
| 26 } |
| 27 |
| 28 void ServiceWorkerBlobReader::OnReceivedRedirect( |
| 29 net::URLRequest* request, |
| 30 const net::RedirectInfo& redirect_info, |
| 31 bool* defer_redirect) { |
| 32 NOTREACHED(); |
| 33 } |
| 34 |
| 35 void ServiceWorkerBlobReader::OnAuthRequired( |
| 36 net::URLRequest* request, |
| 37 net::AuthChallengeInfo* auth_info) { |
| 38 NOTREACHED(); |
| 39 } |
| 40 |
| 41 void ServiceWorkerBlobReader::OnCertificateRequested( |
| 42 net::URLRequest* request, |
| 43 net::SSLCertRequestInfo* cert_request_info) { |
| 44 NOTREACHED(); |
| 45 } |
| 46 |
| 47 void ServiceWorkerBlobReader::OnSSLCertificateError( |
| 48 net::URLRequest* request, |
| 49 const net::SSLInfo& ssl_info, |
| 50 bool fatal) { |
| 51 NOTREACHED(); |
| 52 } |
| 53 |
| 54 void ServiceWorkerBlobReader::OnResponseStarted(net::URLRequest* request) { |
| 55 // TODO(falken): This should check request->status() per URLRequest::Delegate |
| 56 // contract. |
| 57 // TODO(falken): Add Content-Length, Content-Type if they were not provided in |
| 58 // the ServiceWorkerResponse. |
| 59 owner_->OnResponseStarted(); |
| 60 } |
| 61 |
| 62 void ServiceWorkerBlobReader::OnReadCompleted(net::URLRequest* request, |
| 63 int bytes_read) { |
| 64 if (!request->status().is_success()) { |
| 65 owner_->RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_BLOB_READ); |
| 66 } else if (bytes_read == 0) { |
| 67 owner_->RecordResult(ServiceWorkerMetrics::REQUEST_JOB_BLOB_RESPONSE); |
| 68 } |
| 69 net::URLRequestStatus status = request->status(); |
| 70 owner_->OnReadRawDataComplete(status.is_success() ? bytes_read |
| 71 : status.error()); |
| 72 } |
| 73 |
| 74 int ServiceWorkerBlobReader::ReadRawData(net::IOBuffer* buf, int buf_size) { |
| 75 int bytes_read = 0; |
| 76 blob_request_->Read(buf, buf_size, &bytes_read); |
| 77 net::URLRequestStatus status = blob_request_->status(); |
| 78 if (status.status() != net::URLRequestStatus::SUCCESS) |
| 79 return status.error(); |
| 80 if (bytes_read == 0) { |
| 81 owner_->RecordResult(ServiceWorkerMetrics::REQUEST_JOB_BLOB_RESPONSE); |
| 82 } |
| 83 return bytes_read; |
| 84 } |
| 85 |
| 86 } // namespace content |
OLD | NEW |