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(
net::URLRequest* request,
int bytes_read) {
DCHECK_EQ(net_request_, request);
if (!request->status().is_success()) {
if (bytes_read < 0) {
DCHECK(!request->status().is_success());
AsyncNotifyDoneHelper(request->status());
return;
}
......@@ -368,18 +369,20 @@ void ServiceWorkerWriteToCacheJob::OnReadCompleted(
WriteDataToCache(bytes_read);
return;
}
TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
"ServiceWorkerWriteToCacheJob::ExecutingJob",
this,
"WriteHeadersToCache");
// We're done with all.
AsyncNotifyDoneHelper(request->status());
return;
// No more data to process, the job is complete.
DCHECK(request->status().is_success());
io_buffer_ = NULL;
version_->script_cache_map()->NotifyFinishedCaching(
url_, net::URLRequestStatus());
did_notify_finished_ = true;
SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
NotifyReadComplete(0);
}
void ServiceWorkerWriteToCacheJob::AsyncNotifyDoneHelper(
const net::URLRequestStatus& status) {
DCHECK(!status.is_io_pending());
DCHECK(!did_notify_finished_);
version_->script_cache_map()->NotifyFinishedCaching(url_, status);
did_notify_finished_ = true;
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