Commit 9cfbf665 authored by darin@chromium.org's avatar darin@chromium.org

Make DownloadResourceThrottle robust to ContinueDownload being called before

WillStartRequest.

R=rdsmith@chromium.org
BUG=114853

Review URL: http://codereview.chromium.org/9522006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124659 0039d316-1c4b-4281-b951-d872f2087c98
parent 50adc0e1
......@@ -13,7 +13,8 @@ DownloadResourceThrottle::DownloadResourceThrottle(
int render_process_id,
int render_view_id,
int request_id)
: request_allowed_(false),
: querying_limiter_(true),
request_allowed_(false),
request_deferred_(false) {
limiter->CanDownloadOnIOThread(
render_process_id,
......@@ -27,30 +28,46 @@ DownloadResourceThrottle::~DownloadResourceThrottle() {
}
void DownloadResourceThrottle::WillStartRequest(bool* defer) {
*defer = request_deferred_ = !request_allowed_;
WillDownload(defer);
}
void DownloadResourceThrottle::WillRedirectRequest(const GURL& new_url,
bool* defer) {
*defer = request_deferred_ = !request_allowed_;
WillDownload(defer);
}
void DownloadResourceThrottle::WillProcessResponse(bool* defer) {
*defer = request_deferred_ = !request_allowed_;
WillDownload(defer);
}
void DownloadResourceThrottle::WillDownload(bool* defer) {
DCHECK(!request_deferred_);
// Defer the download until we have the DownloadRequestLimiter result.
if (querying_limiter_) {
request_deferred_ = true;
*defer = true;
return;
}
if (!request_allowed_)
controller()->Cancel();
}
void DownloadResourceThrottle::ContinueDownload(bool allow) {
querying_limiter_ = false;
request_allowed_ = allow;
if (allow) {
// Presumes all downloads initiated by navigation using this throttle and
// Presumes all downloads initiated by navigation use this throttle and
// nothing else does.
download_util::RecordDownloadSource(
download_util::INITIATED_BY_NAVIGATION);
download_util::RecordDownloadSource(download_util::INITIATED_BY_NAVIGATION);
} else {
download_util::RecordDownloadCount(download_util::BLOCKED_BY_THROTTLING);
}
if (request_deferred_) {
request_deferred_ = false;
if (allow) {
controller()->Resume();
} else {
......
......@@ -36,8 +36,12 @@ class DownloadResourceThrottle
private:
virtual ~DownloadResourceThrottle();
void WillDownload(bool* defer);
void ContinueDownload(bool allow);
// Set to true when we are querying the DownloadRequestLimiter.
bool querying_limiter_;
// Set to true when we know that the request is allowed to start.
bool request_allowed_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment