Commit a67ddd2a authored by horo's avatar horo Committed by Commit bot

[ServiceWorker] Handle bytes_read=0 async result correctly in ServiceWorkerWriteToCacheJob.

The async result of net_request_->Read() in ServiceWorkerWriteToCacheJob::ReadNetData() is passed to ServiceWorkerWriteToCacheJob::OnReadCompleted().
In current code the case when bytes_read is 0 is not handled correctly.
So when bytes_read is 0 the script loading will hang.

LayoutTest is here: https://codereview.chromium.org/650193003

I hope this patch will reduce the test flakiness :)

BUG=419999
TEST=http/tests/serviceworker/chromium/load-flushed-script.html

Review URL: https://codereview.chromium.org/640923003

Cr-Commit-Position: refs/heads/master@{#300233}
parent 1dace874
...@@ -360,7 +360,8 @@ void ServiceWorkerWriteToCacheJob::OnReadCompleted( ...@@ -360,7 +360,8 @@ void ServiceWorkerWriteToCacheJob::OnReadCompleted(
net::URLRequest* request, net::URLRequest* request,
int bytes_read) { int bytes_read) {
DCHECK_EQ(net_request_, request); DCHECK_EQ(net_request_, request);
if (!request->status().is_success()) { if (bytes_read < 0) {
DCHECK(!request->status().is_success());
AsyncNotifyDoneHelper(request->status()); AsyncNotifyDoneHelper(request->status());
return; return;
} }
...@@ -368,18 +369,20 @@ void ServiceWorkerWriteToCacheJob::OnReadCompleted( ...@@ -368,18 +369,20 @@ void ServiceWorkerWriteToCacheJob::OnReadCompleted(
WriteDataToCache(bytes_read); WriteDataToCache(bytes_read);
return; return;
} }
TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", // No more data to process, the job is complete.
"ServiceWorkerWriteToCacheJob::ExecutingJob", DCHECK(request->status().is_success());
this, io_buffer_ = NULL;
"WriteHeadersToCache"); version_->script_cache_map()->NotifyFinishedCaching(
// We're done with all. url_, net::URLRequestStatus());
AsyncNotifyDoneHelper(request->status()); did_notify_finished_ = true;
return; SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
NotifyReadComplete(0);
} }
void ServiceWorkerWriteToCacheJob::AsyncNotifyDoneHelper( void ServiceWorkerWriteToCacheJob::AsyncNotifyDoneHelper(
const net::URLRequestStatus& status) { const net::URLRequestStatus& status) {
DCHECK(!status.is_io_pending()); DCHECK(!status.is_io_pending());
DCHECK(!did_notify_finished_);
version_->script_cache_map()->NotifyFinishedCaching(url_, status); version_->script_cache_map()->NotifyFinishedCaching(url_, status);
did_notify_finished_ = true; did_notify_finished_ = true;
SetStatus(status); SetStatus(status);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment