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

Unified Diff: content/common/throttling_url_loader.cc

Issue 2982363002: Add support for fallback content for the frame. This includes main and subframes. (Closed)
Patch Set: Address review comments. Add the fallback function as a parameter to LoaderCallback Created 3 years, 5 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
Index: content/common/throttling_url_loader.cc
diff --git a/content/common/throttling_url_loader.cc b/content/common/throttling_url_loader.cc
index 7fa5b73b20d8e27d1866fcb85b425f52556eb5a5..ddc11010f2615aa83a5a615b2240b5bf8b0a45f8 100644
--- a/content/common/throttling_url_loader.cc
+++ b/content/common/throttling_url_loader.cc
@@ -93,7 +93,7 @@ void ThrottlingURLLoader::FollowRedirect() {
void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) {
- if (!url_loader_ && !cancelled_by_throttle_) {
+ if (!url_loader_ && !loader_cancelled_) {
DCHECK_EQ(DEFERRED_START, deferred_stage_);
priority_info_ =
base::MakeUnique<PriorityInfo>(priority, intra_priority_value);
@@ -103,6 +103,12 @@ void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
url_loader_->SetPriority(priority, intra_priority_value);
}
+void ThrottlingURLLoader::DisconnectClient() {
+ client_binding_.Close();
+ url_loader_ = nullptr;
+ loader_cancelled_ = true;
+}
+
ThrottlingURLLoader::ThrottlingURLLoader(
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
mojom::URLLoaderClient* client,
@@ -128,13 +134,13 @@ void ThrottlingURLLoader::Start(
const ResourceRequest& url_request,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
if (throttle_) {
bool deferred = false;
throttle_->WillStartRequest(url_request.url, url_request.load_flags,
url_request.resource_type, &deferred);
- if (cancelled_by_throttle_)
+ if (loader_cancelled_)
return;
if (deferred) {
@@ -187,12 +193,12 @@ void ThrottlingURLLoader::OnReceiveResponse(
const base::Optional<net::SSLInfo>& ssl_info,
mojom::DownloadedTempFilePtr downloaded_file) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
if (throttle_) {
bool deferred = false;
throttle_->WillProcessResponse(&deferred);
- if (cancelled_by_throttle_)
+ if (loader_cancelled_)
return;
if (deferred) {
@@ -212,12 +218,12 @@ void ThrottlingURLLoader::OnReceiveRedirect(
const net::RedirectInfo& redirect_info,
const ResourceResponseHead& response_head) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
if (throttle_) {
bool deferred = false;
throttle_->WillRedirectRequest(redirect_info, &deferred);
- if (cancelled_by_throttle_)
+ if (loader_cancelled_)
return;
if (deferred) {
@@ -235,7 +241,7 @@ void ThrottlingURLLoader::OnReceiveRedirect(
void ThrottlingURLLoader::OnDataDownloaded(int64_t data_len,
int64_t encoded_data_len) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnDataDownloaded(data_len, encoded_data_len);
}
@@ -245,7 +251,7 @@ void ThrottlingURLLoader::OnUploadProgress(
int64_t total_size,
OnUploadProgressCallback ack_callback) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnUploadProgress(current_position, total_size,
std::move(ack_callback));
@@ -254,14 +260,14 @@ void ThrottlingURLLoader::OnUploadProgress(
void ThrottlingURLLoader::OnReceiveCachedMetadata(
const std::vector<uint8_t>& data) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnReceiveCachedMetadata(data);
}
void ThrottlingURLLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnTransferSizeUpdated(transfer_size_diff);
}
@@ -269,7 +275,7 @@ void ThrottlingURLLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) {
void ThrottlingURLLoader::OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnStartLoadingResponseBody(std::move(body));
}
@@ -277,7 +283,7 @@ void ThrottlingURLLoader::OnStartLoadingResponseBody(
void ThrottlingURLLoader::OnComplete(
const ResourceRequestCompletionStatus& status) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
- DCHECK(!cancelled_by_throttle_);
+ DCHECK(!loader_cancelled_);
forwarding_client_->OnComplete(status);
}
@@ -285,24 +291,20 @@ void ThrottlingURLLoader::OnComplete(
void ThrottlingURLLoader::CancelWithError(int error_code) {
// TODO(yzshen): Support a mode that cancellation also deletes the disk cache
// entry.
- if (cancelled_by_throttle_)
+ if (loader_cancelled_)
return;
- cancelled_by_throttle_ = true;
-
ResourceRequestCompletionStatus request_complete_data;
request_complete_data.error_code = error_code;
request_complete_data.completion_time = base::TimeTicks::Now();
deferred_stage_ = DEFERRED_NONE;
- client_binding_.Close();
- url_loader_ = nullptr;
-
+ DisconnectClient();
forwarding_client_->OnComplete(request_complete_data);
}
void ThrottlingURLLoader::Resume() {
- if (cancelled_by_throttle_ || deferred_stage_ == DEFERRED_NONE)
+ if (loader_cancelled_ || deferred_stage_ == DEFERRED_NONE)
return;
switch (deferred_stage_) {

Powered by Google App Engine
This is Rietveld 408576698