Chromium Code Reviews| Index: content/browser/service_worker/service_worker_url_request_job.cc |
| diff --git a/content/browser/service_worker/service_worker_url_request_job.cc b/content/browser/service_worker/service_worker_url_request_job.cc |
| index 37d22d01df41fc778f1914ea9f0fb389966b22a2..7edee3f04f67457e53d960ecd08f079601adc208 100644 |
| --- a/content/browser/service_worker/service_worker_url_request_job.cc |
| +++ b/content/browser/service_worker/service_worker_url_request_job.cc |
| @@ -6,23 +6,29 @@ |
| #include "base/bind.h" |
| #include "base/strings/stringprintf.h" |
| +#include "content/browser/fileapi/chrome_blob_storage_context.h" |
| #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
| #include "content/browser/service_worker/service_worker_provider_host.h" |
| #include "net/http/http_request_headers.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/http/http_response_info.h" |
| #include "net/http/http_util.h" |
| +#include "webkit/browser/blob/blob_data_handle.h" |
| +#include "webkit/browser/blob/blob_storage_context.h" |
| +#include "webkit/browser/blob/blob_url_request_job_factory.h" |
| namespace content { |
| ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( |
| net::URLRequest* request, |
| net::NetworkDelegate* network_delegate, |
| - base::WeakPtr<ServiceWorkerProviderHost> provider_host) |
| + base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| + base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) |
| : net::URLRequestJob(request, network_delegate), |
| provider_host_(provider_host), |
| response_type_(NOT_DETERMINED), |
| is_started_(false), |
| + blob_storage_context_(blob_storage_context), |
| weak_factory_(this) { |
| } |
| @@ -94,13 +100,64 @@ void ServiceWorkerURLRequestJob::SetExtraRequestHeaders( |
| bool ServiceWorkerURLRequestJob::ReadRawData( |
| net::IOBuffer* buf, int buf_size, int *bytes_read) { |
| - // TODO(kinuko): Implement this. |
| - // If the response returned from ServiceWorker had an |
| - // identifier to on-disk data (e.g. blob or cache entry) we'll need to |
| - // pull the body from disk. |
| - NOTIMPLEMENTED(); |
| - *bytes_read = 0; |
| - return true; |
| + if (!blob_request_) { |
| + *bytes_read = 0; |
| + return true; |
| + } |
| + |
| + blob_request_->Read(buf, buf_size, bytes_read); |
| + net::URLRequestStatus status = blob_request_->status(); |
| + SetStatus(status); |
| + if (status.is_io_pending()) |
| + return false; |
| + return status.is_success(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnReceivedRedirect(net::URLRequest* request, |
| + const GURL& new_url, |
| + bool* defer_redirect) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnAuthRequired( |
| + net::URLRequest* request, |
| + net::AuthChallengeInfo* auth_info) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnCertificateRequested( |
| + net::URLRequest* request, |
| + net::SSLCertRequestInfo* cert_request_info) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnSSLCertificateError( |
| + net::URLRequest* request, |
| + const net::SSLInfo& ssl_info, |
| + bool fatal) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnBeforeNetworkStart(net::URLRequest* request, |
| + bool* defer) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnResponseStarted(net::URLRequest* request) { |
| + // TODO(falken): Add Content-Length, Content-Type if they were not provided in |
| + // the ServiceWorkerResponse. |
| + NotifyHeadersComplete(); |
| +} |
| + |
| +void ServiceWorkerURLRequestJob::OnReadCompleted(net::URLRequest* request, |
| + int bytes_read) { |
| + if (!request->status().is_success()) { |
| + NotifyDone(request->status()); |
| + return; |
| + } |
| + NotifyReadComplete(bytes_read); |
| + if (bytes_read == 0) |
| + NotifyDone(request->status()); |
| } |
| const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { |
| @@ -183,11 +240,22 @@ void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( |
| return; |
| } |
| + // Set up a request for reading the blob. |
| + if (response_type_ == FORWARD_TO_SERVICE_WORKER && |
|
michaeln
2014/05/23 02:23:23
Should this just be a function of fetchresult and
falken
2014/05/23 11:15:46
Good point. When we get here status is OK and fetc
|
| + !response.blob_uuid.empty()) { |
| + scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle = |
| + blob_storage_context_->GetBlobDataFromUUID(response.blob_uuid); |
|
michaeln
2014/05/23 02:23:23
test if (blob_storage_context_) to see if the weak
falken
2014/05/23 11:15:46
Done.
|
| + blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( |
|
michaeln
2014/05/23 02:32:32
This line right here setups so the webkit_blob::Bl
falken
2014/05/23 11:15:46
I see!
|
| + blob_data_handle.Pass(), request()->context(), this); |
| + blob_request_->Start(); |
| + } |
| + |
| // We should have response now. |
| DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result); |
| CreateResponseHeader(response); |
|
michaeln
2014/05/23 02:23:23
i think we might want to defer setting http_respon
falken
2014/05/23 11:15:46
That does seem safer though it complicates the cod
|
| - NotifyHeadersComplete(); |
| + if (!blob_request_) |
| + NotifyHeadersComplete(); |
| } |
| void ServiceWorkerURLRequestJob::CreateResponseHeader( |