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

Unified Diff: net/url_request/url_request_job.cc

Issue 2542843006: ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases. (Closed)
Patch Set: Inline ReadMore Created 4 years 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: net/url_request/url_request_job.cc
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index b315664de1ac52eafb49b36360be97e608d87ecc..0dae4a8b7929814e46152da9b0a6ca4e6016eaf4 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -495,8 +495,9 @@ void URLRequestJob::NotifyHeadersComplete() {
source_stream_ = SetUpSourceStream();
if (!source_stream_) {
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
- ERR_CONTENT_DECODING_INIT_FAILED));
+ OnDone(URLRequestStatus(URLRequestStatus::FAILED,
+ ERR_CONTENT_DECODING_INIT_FAILED),
+ true);
return;
}
if (source_stream_->type() == SourceStream::TYPE_NONE) {
@@ -563,7 +564,7 @@ void URLRequestJob::NotifyStartError(const URLRequestStatus &status) {
// |this| may have been deleted here.
}
-void URLRequestJob::NotifyDone(const URLRequestStatus &status) {
+void URLRequestJob::OnDone(const URLRequestStatus& status, bool notify_done) {
DCHECK(!done_) << "Job sending done notification twice";
if (done_)
return;
@@ -589,14 +590,16 @@ void URLRequestJob::NotifyDone(const URLRequestStatus &status) {
MaybeNotifyNetworkBytes();
- // Complete this notification later. This prevents us from re-entering the
- // delegate if we're done because of a synchronous call.
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone,
- weak_factory_.GetWeakPtr()));
+ if (notify_done) {
+ // Complete this notification later. This prevents us from re-entering the
+ // delegate if we're done because of a synchronous call.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&URLRequestJob::NotifyDone, weak_factory_.GetWeakPtr()));
mmenke 2016/12/02 15:20:08 Note that I want to get rid of NotifyDone entirely
+ }
}
-void URLRequestJob::CompleteNotifyDone() {
+void URLRequestJob::NotifyDone() {
// Check if we should notify the delegate that we're done because of an error.
if (!request_->status().is_success()) {
// We report the error differently depending on whether we've called
@@ -613,7 +616,7 @@ void URLRequestJob::CompleteNotifyDone() {
void URLRequestJob::NotifyCanceled() {
if (!done_) {
- NotifyDone(URLRequestStatus(URLRequestStatus::CANCELED, ERR_ABORTED));
+ OnDone(URLRequestStatus(URLRequestStatus::CANCELED, ERR_ABORTED), true);
}
}
@@ -669,7 +672,7 @@ void URLRequestJob::SourceStreamReadComplete(bool synchronous, int result) {
pending_read_buffer_ = nullptr;
if (result < 0) {
- NotifyDone(URLRequestStatus::FromError(result));
+ OnDone(URLRequestStatus::FromError(result), !synchronous);
return;
}
@@ -682,7 +685,7 @@ void URLRequestJob::SourceStreamReadComplete(bool synchronous, int result) {
DCHECK_EQ(0, result);
DoneReading();
- NotifyDone(URLRequestStatus());
+ OnDone(URLRequestStatus(), !synchronous);
if (!synchronous)
request_->NotifyReadCompleted(result);
}
@@ -713,7 +716,7 @@ int URLRequestJob::ReadRawDataHelper(IOBuffer* buf,
void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) {
int rv = request_->Redirect(redirect_info);
if (rv != OK)
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
+ OnDone(URLRequestStatus(URLRequestStatus::FAILED, rv), true);
}
void URLRequestJob::GatherRawReadStats(int bytes_read) {

Powered by Google App Engine
This is Rietveld 408576698