summaryrefslogtreecommitdiffstats
path: root/content/browser/loader/throttling_resource_handler.cc
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 20:11:53 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 20:11:53 +0000
commitf8fe5cf6449af0c8f096b1c2e38b3c76c1c923cb (patch)
tree360be63caedeab943cc4d8c936b112ce0868d2e6 /content/browser/loader/throttling_resource_handler.cc
parent8f89638bcddd0325782e4b3bd1c4eaaf8f6fcc52 (diff)
downloadchromium_src-f8fe5cf6449af0c8f096b1c2e38b3c76c1c923cb.zip
chromium_src-f8fe5cf6449af0c8f096b1c2e38b3c76c1c923cb.tar.gz
chromium_src-f8fe5cf6449af0c8f096b1c2e38b3c76c1c923cb.tar.bz2
Make resource throttles and AsyncResourceHandler add events to NetLog
when they block a request. This is aimed at making issues easier to debug when a delegate defers an request for significant periods of time. Also display that information in about:net-internals when a request is already active and blocked on a delegate. BUG=94920 Review URL: https://codereview.chromium.org/25108004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/loader/throttling_resource_handler.cc')
-rw-r--r--content/browser/loader/throttling_resource_handler.cc45
1 files changed, 31 insertions, 14 deletions
diff --git a/content/browser/loader/throttling_resource_handler.cc b/content/browser/loader/throttling_resource_handler.cc
index 23f77da..36c595f 100644
--- a/content/browser/loader/throttling_resource_handler.cc
+++ b/content/browser/loader/throttling_resource_handler.cc
@@ -7,6 +7,7 @@
#include "content/browser/loader/resource_request_info_impl.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/common/resource_response.h"
+#include "net/url_request/url_request.h"
namespace content {
@@ -17,10 +18,14 @@ ThrottlingResourceHandler::ThrottlingResourceHandler(
: LayeredResourceHandler(request, next_handler.Pass()),
deferred_stage_(DEFERRED_NONE),
throttles_(throttles.Pass()),
- index_(0),
+ next_index_(0),
cancelled_by_resource_throttle_(false) {
- for (size_t i = 0; i < throttles_.size(); ++i)
+ for (size_t i = 0; i < throttles_.size(); ++i) {
throttles_[i]->set_controller(this);
+ // Throttles must have a name, as otherwise, bugs where a throttle fails
+ // to resume a request can be very difficult to debug.
+ DCHECK(throttles_[i]->GetNameForLogging());
+ }
}
ThrottlingResourceHandler::~ThrottlingResourceHandler() {
@@ -33,12 +38,14 @@ bool ThrottlingResourceHandler::OnRequestRedirected(int request_id,
DCHECK(!cancelled_by_resource_throttle_);
*defer = false;
- while (index_ < throttles_.size()) {
- throttles_[index_]->WillRedirectRequest(new_url, defer);
- index_++;
+ while (next_index_ < throttles_.size()) {
+ int index = next_index_;
+ throttles_[index]->WillRedirectRequest(new_url, defer);
+ next_index_++;
if (cancelled_by_resource_throttle_)
return false;
if (*defer) {
+ OnRequestDefered(index);
deferred_stage_ = DEFERRED_REDIRECT;
deferred_url_ = new_url;
deferred_response_ = response;
@@ -46,7 +53,7 @@ bool ThrottlingResourceHandler::OnRequestRedirected(int request_id,
}
}
- index_ = 0; // Reset for next time.
+ next_index_ = 0; // Reset for next time.
return next_handler_->OnRequestRedirected(request_id, new_url, response,
defer);
@@ -58,19 +65,21 @@ bool ThrottlingResourceHandler::OnWillStart(int request_id,
DCHECK(!cancelled_by_resource_throttle_);
*defer = false;
- while (index_ < throttles_.size()) {
- throttles_[index_]->WillStartRequest(defer);
- index_++;
+ while (next_index_ < throttles_.size()) {
+ int index = next_index_;
+ throttles_[index]->WillStartRequest(defer);
+ next_index_++;
if (cancelled_by_resource_throttle_)
return false;
if (*defer) {
+ OnRequestDefered(index);
deferred_stage_ = DEFERRED_START;
deferred_url_ = url;
return true; // Do not cancel.
}
}
- index_ = 0; // Reset for next time.
+ next_index_ = 0; // Reset for next time.
return next_handler_->OnWillStart(request_id, url, defer);
}
@@ -80,19 +89,21 @@ bool ThrottlingResourceHandler::OnResponseStarted(int request_id,
bool* defer) {
DCHECK(!cancelled_by_resource_throttle_);
- while (index_ < throttles_.size()) {
- throttles_[index_]->WillProcessResponse(defer);
- index_++;
+ while (next_index_ < throttles_.size()) {
+ int index = next_index_;
+ throttles_[index]->WillProcessResponse(defer);
+ next_index_++;
if (cancelled_by_resource_throttle_)
return false;
if (*defer) {
+ OnRequestDefered(index);
deferred_stage_ = DEFERRED_RESPONSE;
deferred_response_ = response;
return true; // Do not cancel.
}
}
- index_ = 0; // Reset for next time.
+ next_index_ = 0; // Reset for next time.
return next_handler_->OnResponseStarted(request_id, response, defer);
}
@@ -117,6 +128,8 @@ void ThrottlingResourceHandler::Resume() {
DeferredStage last_deferred_stage = deferred_stage_;
deferred_stage_ = DEFERRED_NONE;
+ // Clear information about the throttle that delayed the request.
+ request()->LogUnblocked();
switch (last_deferred_stage) {
case DEFERRED_NONE:
NOTREACHED();
@@ -177,4 +190,8 @@ void ThrottlingResourceHandler::ResumeResponse() {
}
}
+void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) {
+ request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging());
+}
+
} // namespace content