| 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..03f5ba595305d10a7c85c3ff4fbbdbed1443a31c 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,
|
| + scoped_refptr<ChromeBlobStorageContext> 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,62 @@ 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) {
|
| + 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 {
|
| @@ -138,7 +193,8 @@ void ServiceWorkerURLRequestJob::StartRequest() {
|
| return;
|
|
|
| case FORWARD_TO_SERVICE_WORKER:
|
| - DCHECK(provider_host_ && provider_host_->active_version());
|
| + DCHECK(provider_host_);
|
| + DCHECK(provider_host_->active_version());
|
| DCHECK(!fetch_dispatcher_);
|
|
|
| // Send a fetch event to the ServiceWorker associated to the
|
| @@ -183,11 +239,23 @@ void ServiceWorkerURLRequestJob::DidDispatchFetchEvent(
|
| return;
|
| }
|
|
|
| + // Set up a request for reading the blob.
|
| + if (response_type_ == FORWARD_TO_SERVICE_WORKER &&
|
| + !response.blob_uuid.empty()) {
|
| + scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle =
|
| + blob_storage_context_->context()->GetBlobDataFromUUID(
|
| + response.blob_uuid);
|
| + blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest(
|
| + 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);
|
| - NotifyHeadersComplete();
|
| + if (!blob_request_)
|
| + NotifyHeadersComplete();
|
| }
|
|
|
| void ServiceWorkerURLRequestJob::CreateResponseHeader(
|
|
|