Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2914)

Unified Diff: chrome/browser/download/download_resource_throttle.cc

Issue 9522006: Make DownloadResourceThrottle robust to ContinueDownload being called before (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_resource_throttle.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_resource_throttle.cc
===================================================================
--- chrome/browser/download/download_resource_throttle.cc (revision 123743)
+++ chrome/browser/download/download_resource_throttle.cc (working copy)
@@ -13,7 +13,8 @@
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 @@
}
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 {
« no previous file with comments | « chrome/browser/download/download_resource_throttle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698