diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 18:27:39 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 18:27:39 +0000 |
commit | e7d8ea75177be9eeff004599e2e7dd4bd10b4c2f (patch) | |
tree | 8c1e3740fa71fa8d3c5925b912bd97ea3030c47c | |
parent | 4916e07255398041971840eb555292b5bcffd29f (diff) | |
download | chromium_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
5 files changed, 32 insertions, 46 deletions
diff --git a/chrome/browser/download/download_resource_throttle.cc b/chrome/browser/download/download_resource_throttle.cc index 87d41dc..9a86dd6 100644 --- a/chrome/browser/download/download_resource_throttle.cc +++ b/chrome/browser/download/download_resource_throttle.cc @@ -34,7 +34,7 @@ void DownloadResourceThrottle::WillRedirectRequest(const GURL& new_url, *defer = request_deferred_ = !request_allowed_; } -void DownloadResourceThrottle::WillReadRequest(bool* defer) { +void DownloadResourceThrottle::WillProcessResponse(bool* defer) { *defer = request_deferred_ = !request_allowed_; } diff --git a/chrome/browser/download/download_resource_throttle.h b/chrome/browser/download/download_resource_throttle.h index 8aaef8e..d29bad2 100644 --- a/chrome/browser/download/download_resource_throttle.h +++ b/chrome/browser/download/download_resource_throttle.h @@ -6,18 +6,11 @@ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_ #pragma once -#include <string> - #include "base/memory/weak_ptr.h" #include "chrome/browser/download/download_request_limiter.h" #include "content/public/browser/resource_throttle.h" -#include "googleurl/src/gurl.h" - -class ResourceDispatcherHost; -namespace net { -class URLRequest; -} // namespace net +class GURL; // DownloadResourceThrottle is used to determine if a download should be // allowed. When a DownloadResourceThrottle is created it pauses the download @@ -38,7 +31,7 @@ class DownloadResourceThrottle // content::ResourceThrottle implementation: virtual void WillStartRequest(bool* defer) OVERRIDE; virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; - virtual void WillReadRequest(bool* defer) OVERRIDE; + virtual void WillProcessResponse(bool* defer) OVERRIDE; private: virtual ~DownloadResourceThrottle(); 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) {} |