summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-13 18:27:39 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-13 18:27:39 +0000
commite7d8ea75177be9eeff004599e2e7dd4bd10b4c2f (patch)
tree8c1e3740fa71fa8d3c5925b912bd97ea3030c47c /content
parent4916e07255398041971840eb555292b5bcffd29f (diff)
downloadchromium_src-e7d8ea75177be9eeff004599e2e7dd4bd10b4c2f.zip
chromium_src-e7d8ea75177be9eeff004599e2e7dd4bd10b4c2f.tar.gz
chromium_src-e7d8ea75177be9eeff004599e2e7dd4bd10b4c2f.tar.bz2
Replace WillReadRequest with WillProcessResponse so that the
DownloadResourceThrottle can defer ResourceHandler::OnResponseStarted. Review URL: http://codereview.chromium.org/9387001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/throttling_resource_handler.cc53
-rw-r--r--content/browser/renderer_host/throttling_resource_handler.h10
-rw-r--r--content/public/browser/resource_throttle.h2
3 files changed, 29 insertions, 36 deletions
diff --git a/content/browser/renderer_host/throttling_resource_handler.cc b/content/browser/renderer_host/throttling_resource_handler.cc
index 565da83..38b656f 100644
--- a/content/browser/renderer_host/throttling_resource_handler.cc
+++ b/content/browser/renderer_host/throttling_resource_handler.cc
@@ -72,20 +72,26 @@ bool ThrottlingResourceHandler::OnWillStart(int request_id,
return next_handler_->OnWillStart(request_id, url, defer);
}
-bool ThrottlingResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
- int* buf_size, int min_size) {
+bool ThrottlingResourceHandler::OnResponseStarted(
+ int request_id,
+ content::ResourceResponse* response) {
DCHECK_EQ(request_id_, request_id);
- bool defer = false;
- WillReadRequest(&defer);
- if (defer) {
- host_->PauseRequest(child_id_, request_id_, true);
- return false; // Do not read.
+ while (index_ < throttles_.size()) {
+ bool defer = false;
+ throttles_[index_]->WillProcessResponse(&defer);
+ index_++;
+ if (defer) {
+ host_->PauseRequest(child_id_, request_id_, true);
+ deferred_stage_ = DEFERRED_RESPONSE;
+ deferred_response_ = response;
+ return true; // Do not cancel.
+ }
}
index_ = 0; // Reset for next time.
- return next_handler_->OnWillRead(request_id, buf, buf_size, min_size);
+ return next_handler_->OnResponseStarted(request_id, response);
}
void ThrottlingResourceHandler::OnRequestClosed() {
@@ -108,8 +114,8 @@ void ThrottlingResourceHandler::Resume() {
case DEFERRED_REDIRECT:
ResumeRedirect();
break;
- case DEFERRED_READ:
- ResumeRead();
+ case DEFERRED_RESPONSE:
+ ResumeResponse();
break;
}
deferred_stage_ = DEFERRED_NONE;
@@ -144,26 +150,15 @@ void ThrottlingResourceHandler::ResumeRedirect() {
}
}
-void ThrottlingResourceHandler::ResumeRead() {
- bool defer = false;
- WillReadRequest(&defer);
- if (!defer) {
- host_->PauseRequest(child_id_, request_id_, false);
- // OnWillRead will be called again, and from there we'll call the
- // next_handler_'s OnWillRead.
- }
-}
+void ThrottlingResourceHandler::ResumeResponse() {
+ scoped_refptr<ResourceResponse> response;
+ deferred_response_.swap(response);
-void ThrottlingResourceHandler::WillReadRequest(bool* defer) {
- *defer = false;
- while (index_ < throttles_.size()) {
- throttles_[index_]->WillReadRequest(defer);
- index_++;
- if (*defer) {
- deferred_stage_ = DEFERRED_READ;
- break;
- }
- }
+ // OnResponseStarted will pause again if necessary.
+ host_->PauseRequest(child_id_, request_id_, false);
+
+ if (!OnResponseStarted(request_id_, response))
+ Cancel();
}
} // namespace content
diff --git a/content/browser/renderer_host/throttling_resource_handler.h b/content/browser/renderer_host/throttling_resource_handler.h
index ab3286b..4a387ee 100644
--- a/content/browser/renderer_host/throttling_resource_handler.h
+++ b/content/browser/renderer_host/throttling_resource_handler.h
@@ -34,10 +34,10 @@ class ThrottlingResourceHandler : public LayeredResourceHandler,
virtual bool OnRequestRedirected(int request_id, const GURL& url,
ResourceResponse* response,
bool* defer) OVERRIDE;
+ virtual bool OnResponseStarted(int request_id,
+ content::ResourceResponse* response) OVERRIDE;
virtual bool OnWillStart(int request_id, const GURL& url,
bool* defer) OVERRIDE;
- virtual bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
- int min_size) OVERRIDE;
virtual void OnRequestClosed() OVERRIDE;
// ResourceThrottleController implementation:
@@ -49,15 +49,13 @@ class ThrottlingResourceHandler : public LayeredResourceHandler,
void ResumeStart();
void ResumeRedirect();
- void ResumeRead();
-
- void WillReadRequest(bool* defer);
+ void ResumeResponse();
enum DeferredStage {
DEFERRED_NONE,
DEFERRED_START,
DEFERRED_REDIRECT,
- DEFERRED_READ
+ DEFERRED_RESPONSE
};
DeferredStage deferred_stage_;
diff --git a/content/public/browser/resource_throttle.h b/content/public/browser/resource_throttle.h
index e794d17..79afa21 100644
--- a/content/public/browser/resource_throttle.h
+++ b/content/public/browser/resource_throttle.h
@@ -24,7 +24,7 @@ class ResourceThrottle {
virtual void WillStartRequest(bool* defer) {}
virtual void WillRedirectRequest(const GURL& new_url, bool* defer) {}
- virtual void WillReadRequest(bool* defer) {}
+ virtual void WillProcessResponse(bool* defer) {}
protected:
ResourceThrottle() : controller_(NULL) {}