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

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: Fix merge 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
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_test_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..33fb9afc4a40c405377fa097bc689572ef71bb6e 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,15 +590,18 @@ 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()));
+ }
}
-void URLRequestJob::CompleteNotifyDone() {
- // Check if we should notify the delegate that we're done because of an error.
+void URLRequestJob::NotifyDone() {
+ // Check if we should notify the URLRequest that we're done because of an
+ // error.
if (!request_->status().is_success()) {
// We report the error differently depending on whether we've called
// OnResponseStarted yet.
@@ -613,7 +617,7 @@ void URLRequestJob::CompleteNotifyDone() {
void URLRequestJob::NotifyCanceled() {
if (!done_) {
- NotifyDone(URLRequestStatus(URLRequestStatus::CANCELED, ERR_ABORTED));
+ OnDone(URLRequestStatus(URLRequestStatus::CANCELED, ERR_ABORTED), true);
}
}
@@ -669,20 +673,21 @@ void URLRequestJob::SourceStreamReadComplete(bool synchronous, int result) {
pending_read_buffer_ = nullptr;
if (result < 0) {
- NotifyDone(URLRequestStatus::FromError(result));
+ OnDone(URLRequestStatus::FromError(result), !synchronous);
return;
}
if (result > 0) {
postfilter_bytes_read_ += result;
- if (!synchronous)
- request_->NotifyReadCompleted(result);
- return;
+ } else {
+ DCHECK_EQ(0, result);
+ DoneReading();
+ // In the synchronous case, the caller will notify the URLRequest of
+ // completion. In the async case, the NotifyReadCompleted call will.
+ // TODO(mmenke): Can this be combined with the error case?
+ OnDone(URLRequestStatus(), false);
}
- DCHECK_EQ(0, result);
- DoneReading();
- NotifyDone(URLRequestStatus());
if (!synchronous)
request_->NotifyReadCompleted(result);
}
@@ -713,7 +718,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) {
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_test_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698