Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: content/browser/service_worker/service_worker_read_from_cache_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_read_from_cache_job.cc
diff --git a/content/browser/service_worker/service_worker_read_from_cache_job.cc b/content/browser/service_worker/service_worker_read_from_cache_job.cc
index 6aa92af82bdd88625e8c8ca4b25e4bbaccddef36..93579911aeb1a0b95da449c6e0daa1be2c3d631d 100644
--- a/content/browser/service_worker/service_worker_read_from_cache_job.cc
+++ b/content/browser/service_worker/service_worker_read_from_cache_job.cc
@@ -41,9 +41,26 @@ ServiceWorkerReadFromCacheJob::~ServiceWorkerReadFromCacheJob() {
}
void ServiceWorkerReadFromCacheJob::Start() {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&ServiceWorkerReadFromCacheJob::StartAsync,
- weak_factory_.GetWeakPtr()));
+ TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
+ "ServiceWorkerReadFromCacheJob::ReadInfo", this,
+ "URL", request_->url().spec());
+ if (!context_) {
+ NotifyStartError(
+ net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED));
+ return;
+ }
+
+ // Create a response reader and start reading the headers,
+ // we'll continue when thats done.
+ if (is_main_script())
+ version_->embedded_worker()->OnScriptReadStarted();
+ reader_ = context_->storage()->CreateResponseReader(resource_id_);
+ http_info_io_buffer_ = new HttpResponseInfoIOBuffer;
+ reader_->ReadInfo(
+ http_info_io_buffer_.get(),
+ base::Bind(&ServiceWorkerReadFromCacheJob::OnReadInfoComplete,
+ weak_factory_.GetWeakPtr()));
+ SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
}
void ServiceWorkerReadFromCacheJob::Kill() {
@@ -105,9 +122,11 @@ void ServiceWorkerReadFromCacheJob::SetExtraRequestHeaders(
range_requested_ = ranges[0];
}
-int ServiceWorkerReadFromCacheJob::ReadRawData(net::IOBuffer* buf,
- int buf_size) {
+bool ServiceWorkerReadFromCacheJob::ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read) {
DCHECK_NE(buf_size, 0);
+ DCHECK(bytes_read);
DCHECK(!reader_->IsReadPending());
TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
"ServiceWorkerReadFromCacheJob::ReadRawData",
@@ -116,31 +135,8 @@ int ServiceWorkerReadFromCacheJob::ReadRawData(net::IOBuffer* buf,
reader_->ReadData(buf, buf_size,
base::Bind(&ServiceWorkerReadFromCacheJob::OnReadComplete,
weak_factory_.GetWeakPtr()));
- return net::ERR_IO_PENDING;
-}
-
-void ServiceWorkerReadFromCacheJob::StartAsync() {
- TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
- "ServiceWorkerReadFromCacheJob::ReadInfo", this,
- "URL", request_->url().spec());
- if (!context_) {
- // NotifyStartError is not safe to call synchronously in Start.
- NotifyStartError(
- net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED));
- return;
- }
-
- // Create a response reader and start reading the headers,
- // we'll continue when thats done.
- if (is_main_script())
- version_->embedded_worker()->OnScriptReadStarted();
- reader_ = context_->storage()->CreateResponseReader(resource_id_);
- http_info_io_buffer_ = new HttpResponseInfoIOBuffer;
- reader_->ReadInfo(
- http_info_io_buffer_.get(),
- base::Bind(&ServiceWorkerReadFromCacheJob::OnReadInfoComplete,
- weak_factory_.GetWeakPtr()));
SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
+ return false;
}
const net::HttpResponseInfo* ServiceWorkerReadFromCacheJob::http_info() const {
@@ -158,8 +154,6 @@ void ServiceWorkerReadFromCacheJob::OnReadInfoComplete(int result) {
ServiceWorkerMetrics::CountReadResponseResult(
ServiceWorkerMetrics::READ_HEADERS_ERROR);
Done(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
- NotifyStartError(
- net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
return;
}
DCHECK_GE(result, 0);
@@ -213,22 +207,23 @@ void ServiceWorkerReadFromCacheJob::Done(const net::URLRequestStatus& status) {
}
if (is_main_script())
version_->embedded_worker()->OnScriptReadFinished();
+ NotifyDone(status);
}
void ServiceWorkerReadFromCacheJob::OnReadComplete(int result) {
ServiceWorkerMetrics::ReadResponseResult check_result;
-
- if (result >= 0) {
+ if (result == 0) {
check_result = ServiceWorkerMetrics::READ_OK;
- if (result == 0)
- Done(net::URLRequestStatus());
- } else {
+ Done(net::URLRequestStatus());
+ } else if (result < 0) {
check_result = ServiceWorkerMetrics::READ_DATA_ERROR;
Done(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
+ } else {
+ check_result = ServiceWorkerMetrics::READ_OK;
+ SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
}
-
ServiceWorkerMetrics::CountReadResponseResult(check_result);
- ReadRawDataComplete(result);
+ NotifyReadComplete(result);
TRACE_EVENT_ASYNC_END1("ServiceWorker",
"ServiceWorkerReadFromCacheJob::ReadRawData",
this,

Powered by Google App Engine
This is Rietveld 408576698