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

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

Issue 2309793002: Use modified URLRequest::Read() and delegate methods in /service_worker/ (Closed)
Patch Set: nits Created 4 years, 3 months 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
« no previous file with comments | « content/browser/service_worker/service_worker_write_to_cache_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_write_to_cache_job.cc
diff --git a/content/browser/service_worker/service_worker_write_to_cache_job.cc b/content/browser/service_worker/service_worker_write_to_cache_job.cc
index 6d3f88f3c8b7aed60d609aca5b2a6e815bc689ac..bf226ad74f87f0b7474e96817e8ca6cf09abbeaf 100644
--- a/content/browser/service_worker/service_worker_write_to_cache_job.cc
+++ b/content/browser/service_worker/service_worker_write_to_cache_job.cc
@@ -107,8 +107,7 @@ void ServiceWorkerWriteToCacheJob::Kill() {
has_been_killed_ = true;
net_request_.reset();
if (did_notify_started_) {
- net::Error error = NotifyFinishedCaching(
- net::URLRequestStatus::FromError(net::ERR_ABORTED), kKilledError);
+ net::Error error = NotifyFinishedCaching(net::ERR_ABORTED, kKilledError);
DCHECK_EQ(net::ERR_ABORTED, error);
}
writer_.reset();
@@ -158,18 +157,18 @@ void ServiceWorkerWriteToCacheJob::SetExtraRequestHeaders(
int ServiceWorkerWriteToCacheJob::ReadRawData(net::IOBuffer* buf,
int buf_size) {
- int bytes_read = 0;
- net::URLRequestStatus status = ReadNetData(buf, buf_size, &bytes_read);
- if (status.is_io_pending())
+ int rv = ReadNetData(buf, buf_size);
+ if (rv == net::ERR_IO_PENDING)
return net::ERR_IO_PENDING;
- if (!status.is_success()) {
- net::Error error = NotifyFinishedCaching(status, kFetchScriptError);
- DCHECK_EQ(status.error(), error);
+ if (rv < 0) {
+ net::Error error = static_cast<net::Error>(rv);
+ error = NotifyFinishedCaching(error, kFetchScriptError);
+ DCHECK_EQ(rv, error);
return error;
}
- return HandleNetData(bytes_read);
+ return HandleNetData(rv);
}
const net::HttpResponseInfo* ServiceWorkerWriteToCacheJob::http_info() const {
@@ -205,18 +204,12 @@ void ServiceWorkerWriteToCacheJob::StartNetRequest() {
net_request_->Start(); // We'll continue in OnResponseStarted.
}
-net::URLRequestStatus ServiceWorkerWriteToCacheJob::ReadNetData(
- net::IOBuffer* buf,
- int buf_size,
- int* bytes_read) {
+int ServiceWorkerWriteToCacheJob::ReadNetData(net::IOBuffer* buf,
+ int buf_size) {
DCHECK_GT(buf_size, 0);
- DCHECK(bytes_read);
io_buffer_ = buf;
io_buffer_bytes_ = 0;
- if (!net_request_->Read(buf, buf_size, bytes_read))
- DCHECK_NE(net::URLRequestStatus::SUCCESS, net_request_->status().status());
-
- return net_request_->status();
+ return net_request_->Read(buf, buf_size);
}
void ServiceWorkerWriteToCacheJob::OnReceivedRedirect(
@@ -227,9 +220,7 @@ void ServiceWorkerWriteToCacheJob::OnReceivedRedirect(
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerWriteToCacheJob::OnReceivedRedirect");
// Script resources can't redirect.
- NotifyStartErrorHelper(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_UNSAFE_REDIRECT),
- kRedirectError);
+ NotifyStartErrorHelper(net::ERR_UNSAFE_REDIRECT, kRedirectError);
}
void ServiceWorkerWriteToCacheJob::OnAuthRequired(
@@ -239,9 +230,7 @@ void ServiceWorkerWriteToCacheJob::OnAuthRequired(
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerWriteToCacheJob::OnAuthRequired");
// TODO(michaeln): Pass this thru to our jobs client.
- NotifyStartErrorHelper(
- net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED),
- kClientAuthenticationError);
+ NotifyStartErrorHelper(net::ERR_FAILED, kClientAuthenticationError);
}
void ServiceWorkerWriteToCacheJob::OnCertificateRequested(
@@ -252,9 +241,7 @@ void ServiceWorkerWriteToCacheJob::OnCertificateRequested(
"ServiceWorkerWriteToCacheJob::OnCertificateRequested");
// TODO(michaeln): Pass this thru to our jobs client.
// see NotifyCertificateRequested.
- NotifyStartErrorHelper(
- net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED),
- kClientAuthenticationError);
+ NotifyStartErrorHelper(net::ERR_FAILED, kClientAuthenticationError);
}
void ServiceWorkerWriteToCacheJob::OnSSLCertificateError(
@@ -266,24 +253,23 @@ void ServiceWorkerWriteToCacheJob::OnSSLCertificateError(
"ServiceWorkerWriteToCacheJob::OnSSLCertificateError");
// TODO(michaeln): Pass this thru to our jobs client,
// see NotifySSLCertificateError.
- NotifyStartErrorHelper(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INSECURE_RESPONSE),
- kSSLError);
+ NotifyStartErrorHelper(net::ERR_INSECURE_RESPONSE, kSSLError);
}
-void ServiceWorkerWriteToCacheJob::OnResponseStarted(
- net::URLRequest* request) {
+void ServiceWorkerWriteToCacheJob::OnResponseStarted(net::URLRequest* request,
+ int net_error) {
+ DCHECK_NE(net::ERR_IO_PENDING, net_error);
DCHECK_EQ(net_request_.get(), request);
- if (!request->status().is_success()) {
- NotifyStartErrorHelper(request->status(), kFetchScriptError);
+
+ if (net_error != net::OK) {
+ net::Error error = static_cast<net::Error>(net_error);
+ NotifyStartErrorHelper(error, kFetchScriptError);
return;
}
if (request->GetResponseCode() / 100 != 2) {
std::string error_message =
base::StringPrintf(kBadHTTPResponseError, request->GetResponseCode());
- NotifyStartErrorHelper(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INVALID_RESPONSE),
- error_message);
+ NotifyStartErrorHelper(net::ERR_INVALID_RESPONSE, error_message);
// TODO(michaeln): Instead of error'ing immediately, send the net
// response to our consumer, just don't cache it?
return;
@@ -294,10 +280,7 @@ void ServiceWorkerWriteToCacheJob::OnResponseStarted(
const net::HttpNetworkSession::Params* session_params =
request->context()->GetNetworkSessionParams();
if (!session_params || !session_params->ignore_certificate_errors) {
- NotifyStartErrorHelper(
- net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INSECURE_RESPONSE),
- kSSLError);
+ NotifyStartErrorHelper(net::ERR_INSECURE_RESPONSE, kSSLError);
return;
}
}
@@ -312,10 +295,7 @@ void ServiceWorkerWriteToCacheJob::OnResponseStarted(
mime_type.empty()
? kNoMIMEError
: base::StringPrintf(kBadMIMEError, mime_type.c_str());
- NotifyStartErrorHelper(
- net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INSECURE_RESPONSE),
- error_message);
+ NotifyStartErrorHelper(net::ERR_INSECURE_RESPONSE, error_message);
return;
}
@@ -357,7 +337,7 @@ void ServiceWorkerWriteToCacheJob::OnWriteHeadersComplete(net::Error error) {
void ServiceWorkerWriteToCacheJob::OnWriteDataComplete(net::Error error) {
DCHECK_NE(net::ERR_IO_PENDING, error);
if (io_buffer_bytes_ == 0)
- error = NotifyFinishedCaching(net::URLRequestStatus::FromError(error), "");
+ error = NotifyFinishedCaching(error, "");
if (error != net::OK) {
ServiceWorkerMetrics::CountWriteResponseResult(
ServiceWorkerMetrics::WRITE_DATA_ERROR);
@@ -371,12 +351,13 @@ void ServiceWorkerWriteToCacheJob::OnWriteDataComplete(net::Error error) {
void ServiceWorkerWriteToCacheJob::OnReadCompleted(net::URLRequest* request,
int bytes_read) {
+ DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
DCHECK_EQ(net_request_.get(), request);
int result;
if (bytes_read < 0) {
- DCHECK(!request->status().is_success());
- result = NotifyFinishedCaching(request->status(), kFetchScriptError);
+ net::Error error = static_cast<net::Error>(bytes_read);
+ result = NotifyFinishedCaching(error, kFetchScriptError);
} else {
result = HandleNetData(bytes_read);
}
@@ -399,9 +380,7 @@ bool ServiceWorkerWriteToCacheJob::CheckPathRestriction(
if (!ServiceWorkerUtils::IsPathRestrictionSatisfied(
version_->scope(), url_,
has_header ? &service_worker_allowed : nullptr, &error_message)) {
- NotifyStartErrorHelper(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INSECURE_RESPONSE),
- error_message);
+ NotifyStartErrorHelper(net::ERR_INSECURE_RESPONSE, error_message);
return false;
}
return true;
@@ -416,57 +395,53 @@ int ServiceWorkerWriteToCacheJob::HandleNetData(int bytes_read) {
// In case of ERR_IO_PENDING, this logic is done in OnWriteDataComplete.
if (error != net::ERR_IO_PENDING && bytes_read == 0) {
- error = NotifyFinishedCaching(net::URLRequestStatus::FromError(error),
- std::string());
+ error = NotifyFinishedCaching(error, std::string());
}
return error == net::OK ? bytes_read : error;
}
void ServiceWorkerWriteToCacheJob::NotifyStartErrorHelper(
- const net::URLRequestStatus& status,
+ net::Error net_error,
const std::string& status_message) {
- DCHECK(!status.is_io_pending());
- NotifyFinishedCaching(status, status_message);
- NotifyStartError(status);
+ NotifyFinishedCaching(net_error, status_message);
+ NotifyStartError(net::URLRequestStatus::FromError(net_error));
}
net::Error ServiceWorkerWriteToCacheJob::NotifyFinishedCaching(
- net::URLRequestStatus status,
+ net::Error net_error,
const std::string& status_message) {
- net::Error result = static_cast<net::Error>(status.error());
+ DCHECK_NE(net::ERR_IO_PENDING, net_error);
+
if (did_notify_finished_)
- return result;
+ return net_error;
- if (status.status() != net::URLRequestStatus::SUCCESS) {
+ int size = -1;
+ if (net_error != net::OK) {
// AddMessageToConsole must be called before this job notifies that an error
// occurred because the worker stops soon after receiving the error
// response.
version_->embedded_worker()->AddMessageToConsole(
CONSOLE_MESSAGE_LEVEL_ERROR,
status_message.empty() ? kFetchScriptError : status_message);
- }
-
- int size = -1;
- if (status.is_success())
+ } else {
size = cache_writer_->bytes_written();
+ }
// If all the calls to MaybeWriteHeaders/MaybeWriteData succeeded, but the
// incumbent entry wasn't actually replaced because the new entry was
// equivalent, the new version didn't actually install because it already
// exists.
- if (status.status() == net::URLRequestStatus::SUCCESS &&
- !cache_writer_->did_replace()) {
- status = net::URLRequestStatus::FromError(kIdenticalScriptError);
+ if (net_error == net::OK && !cache_writer_->did_replace()) {
version_->SetStartWorkerStatusCode(SERVICE_WORKER_ERROR_EXISTS);
- version_->script_cache_map()->NotifyFinishedCaching(url_, size, status,
- std::string());
+ version_->script_cache_map()->NotifyFinishedCaching(
+ url_, size, kIdenticalScriptError, std::string());
} else {
- version_->script_cache_map()->NotifyFinishedCaching(url_, size, status,
+ version_->script_cache_map()->NotifyFinishedCaching(url_, size, net_error,
status_message);
}
did_notify_finished_ = true;
- return result;
+ return net_error;
}
std::unique_ptr<ServiceWorkerResponseReader>
« no previous file with comments | « content/browser/service_worker/service_worker_write_to_cache_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698