summaryrefslogtreecommitdiffstats
path: root/content/browser/loader
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/loader')
-rw-r--r--content/browser/loader/async_resource_handler.cc7
-rw-r--r--content/browser/loader/async_resource_handler.h1
-rw-r--r--content/browser/loader/power_save_block_resource_throttle.cc4
-rw-r--r--content/browser/loader/power_save_block_resource_throttle.h1
-rw-r--r--content/browser/loader/resource_dispatcher_host_unittest.cc4
-rw-r--r--content/browser/loader/resource_scheduler.cc4
-rw-r--r--content/browser/loader/throttling_resource_handler.cc45
-rw-r--r--content/browser/loader/throttling_resource_handler.h8
8 files changed, 58 insertions, 16 deletions
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 5983052..93d7e83 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -151,6 +151,7 @@ bool AsyncResourceHandler::OnRequestRedirected(int request_id,
return false;
*defer = did_defer_ = true;
+ OnDefer();
if (rdh_->delegate()) {
rdh_->delegate()->OnRequestRedirected(
@@ -287,6 +288,7 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read,
"Net.AsyncResourceHandler_PendingDataCount_WhenFull",
pending_data_count_, 0, 100, 100);
*defer = did_defer_ = true;
+ OnDefer();
}
return true;
@@ -377,8 +379,13 @@ bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() {
void AsyncResourceHandler::ResumeIfDeferred() {
if (did_defer_) {
did_defer_ = false;
+ request()->LogUnblocked();
controller()->Resume();
}
}
+void AsyncResourceHandler::OnDefer() {
+ request()->LogBlockedBy("AsyncResourceHandler");
+}
+
} // namespace content
diff --git a/content/browser/loader/async_resource_handler.h b/content/browser/loader/async_resource_handler.h
index ac15b59..f603f4f 100644
--- a/content/browser/loader/async_resource_handler.h
+++ b/content/browser/loader/async_resource_handler.h
@@ -72,6 +72,7 @@ class AsyncResourceHandler : public ResourceHandler,
bool EnsureResourceBufferIsInitialized();
void ResumeIfDeferred();
+ void OnDefer();
scoped_refptr<ResourceBuffer> buffer_;
ResourceDispatcherHostImpl* rdh_;
diff --git a/content/browser/loader/power_save_block_resource_throttle.cc b/content/browser/loader/power_save_block_resource_throttle.cc
index d9b843c..7a084b0 100644
--- a/content/browser/loader/power_save_block_resource_throttle.cc
+++ b/content/browser/loader/power_save_block_resource_throttle.cc
@@ -34,6 +34,10 @@ void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) {
timer_.Stop();
}
+const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const {
+ return "PowerSaveBlockResourceThrottle";
+}
+
void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() {
power_save_blocker_ = PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
diff --git a/content/browser/loader/power_save_block_resource_throttle.h b/content/browser/loader/power_save_block_resource_throttle.h
index e94b542..2a4f9b3 100644
--- a/content/browser/loader/power_save_block_resource_throttle.h
+++ b/content/browser/loader/power_save_block_resource_throttle.h
@@ -24,6 +24,7 @@ class PowerSaveBlockResourceThrottle : public ResourceThrottle {
// ResourceThrottle overrides:
virtual void WillStartRequest(bool* defer) OVERRIDE;
virtual void WillProcessResponse(bool* defer) OVERRIDE;
+ virtual const char* GetNameForLogging() const OVERRIDE;
private:
void ActivatePowerSaveBlocker();
diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc
index 895951b..52d3432 100644
--- a/content/browser/loader/resource_dispatcher_host_unittest.cc
+++ b/content/browser/loader/resource_dispatcher_host_unittest.cc
@@ -441,6 +441,10 @@ class GenericResourceThrottle : public ResourceThrottle {
}
}
+ virtual const char* GetNameForLogging() const OVERRIDE {
+ return "GenericResourceThrottle";
+ }
+
void Resume() {
ASSERT_TRUE(this == active_throttle_);
active_throttle_ = NULL;
diff --git a/content/browser/loader/resource_scheduler.cc b/content/browser/loader/resource_scheduler.cc
index 9d05476..d24e484 100644
--- a/content/browser/loader/resource_scheduler.cc
+++ b/content/browser/loader/resource_scheduler.cc
@@ -159,6 +159,10 @@ class ResourceScheduler::ScheduledResourceRequest
deferred_ = *defer = !ready_;
}
+ virtual const char* GetNameForLogging() const OVERRIDE {
+ return "ResourceScheduler";
+ }
+
void DidChangePriority(int request_id, net::RequestPriority new_priority) {
scheduler_->ReprioritizeRequest(this, new_priority);
}
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
diff --git a/content/browser/loader/throttling_resource_handler.h b/content/browser/loader/throttling_resource_handler.h
index 65117bc..9f98921 100644
--- a/content/browser/loader/throttling_resource_handler.h
+++ b/content/browser/loader/throttling_resource_handler.h
@@ -40,7 +40,7 @@ class ThrottlingResourceHandler : public LayeredResourceHandler,
virtual bool OnWillStart(int request_id, const GURL& url,
bool* defer) OVERRIDE;
- // ResourceThrottleController implementation:
+ // ResourceController implementation:
virtual void Cancel() OVERRIDE;
virtual void CancelAndIgnore() OVERRIDE;
virtual void CancelWithError(int error_code) OVERRIDE;
@@ -51,6 +51,10 @@ class ThrottlingResourceHandler : public LayeredResourceHandler,
void ResumeRedirect();
void ResumeResponse();
+ // Called when the throttle at |throttle_index| defers a request. Logs the
+ // name of the throttle that delayed the request.
+ void OnRequestDefered(int throttle_index);
+
enum DeferredStage {
DEFERRED_NONE,
DEFERRED_START,
@@ -60,7 +64,7 @@ class ThrottlingResourceHandler : public LayeredResourceHandler,
DeferredStage deferred_stage_;
ScopedVector<ResourceThrottle> throttles_;
- size_t index_;
+ size_t next_index_;
GURL deferred_url_;
scoped_refptr<ResourceResponse> deferred_response_;