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

Unified Diff: content/browser/loader/throttling_resource_handler.cc

Issue 129173002: Adds the new URLRequest::OnBeforeNetworkStart hook to the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@defer_1_net
Patch Set: Created 6 years, 11 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/browser/loader/throttling_resource_handler.cc
diff --git a/content/browser/loader/throttling_resource_handler.cc b/content/browser/loader/throttling_resource_handler.cc
index 36c595fbf1b9aaabbf2cc8841f5702c2fcd602cb..0de6177842469d8ad983d064a694b3638d9a09a5 100644
--- a/content/browser/loader/throttling_resource_handler.cc
+++ b/content/browser/loader/throttling_resource_handler.cc
@@ -84,6 +84,31 @@ bool ThrottlingResourceHandler::OnWillStart(int request_id,
return next_handler_->OnWillStart(request_id, url, defer);
}
+bool ThrottlingResourceHandler::OnBeforeNetworkStart(int request_id,
+ const GURL& url,
+ bool* defer) {
+ DCHECK(!cancelled_by_resource_throttle_);
+
+ *defer = false;
+ while (next_index_ < throttles_.size()) {
+ int index = next_index_;
+ throttles_[index]->OnBeforeNetworkStart(defer);
+ next_index_++;
+ if (cancelled_by_resource_throttle_)
+ return false;
+ if (*defer) {
+ OnRequestDefered(index);
+ deferred_stage_ = DEFERRED_NETWORK_START;
+ deferred_url_ = url;
+ return true; // Do not cancel.
+ }
+ }
+
+ next_index_ = 0; // Reset for next time.
+
+ return next_handler_->OnBeforeNetworkStart(request_id, url, defer);
+}
+
bool ThrottlingResourceHandler::OnResponseStarted(int request_id,
ResourceResponse* response,
bool* defer) {
@@ -137,6 +162,9 @@ void ThrottlingResourceHandler::Resume() {
case DEFERRED_START:
ResumeStart();
break;
+ case DEFERRED_NETWORK_START:
+ ResumeNetworkStart();
+ break;
case DEFERRED_REDIRECT:
ResumeRedirect();
break;
@@ -160,6 +188,20 @@ void ThrottlingResourceHandler::ResumeStart() {
}
}
+void ThrottlingResourceHandler::ResumeNetworkStart() {
+ DCHECK(!cancelled_by_resource_throttle_);
+
+ GURL url = deferred_url_;
+ deferred_url_ = GURL();
+
+ bool defer = false;
+ if (!OnBeforeNetworkStart(GetRequestID(), url, &defer)) {
+ controller()->Cancel();
+ } else if (!defer) {
+ controller()->Resume();
+ }
+}
+
void ThrottlingResourceHandler::ResumeRedirect() {
DCHECK(!cancelled_by_resource_throttle_);

Powered by Google App Engine
This is Rietveld 408576698