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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_resource_throttle.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_resource_throttle.h" 5 #include "chrome/browser/download/download_resource_throttle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/download/download_util.h" 8 #include "chrome/browser/download/download_util.h"
9 #include "content/public/browser/resource_throttle_controller.h" 9 #include "content/public/browser/resource_throttle_controller.h"
10 10
11 DownloadResourceThrottle::DownloadResourceThrottle( 11 DownloadResourceThrottle::DownloadResourceThrottle(
12 DownloadRequestLimiter* limiter, 12 DownloadRequestLimiter* limiter,
13 int render_process_id, 13 int render_process_id,
14 int render_view_id, 14 int render_view_id,
15 int request_id) 15 int request_id)
16 : request_allowed_(false), 16 : querying_limiter_(true),
17 request_allowed_(false),
17 request_deferred_(false) { 18 request_deferred_(false) {
18 limiter->CanDownloadOnIOThread( 19 limiter->CanDownloadOnIOThread(
19 render_process_id, 20 render_process_id,
20 render_view_id, 21 render_view_id,
21 request_id, 22 request_id,
22 base::Bind(&DownloadResourceThrottle::ContinueDownload, 23 base::Bind(&DownloadResourceThrottle::ContinueDownload,
23 AsWeakPtr())); 24 AsWeakPtr()));
24 } 25 }
25 26
26 DownloadResourceThrottle::~DownloadResourceThrottle() { 27 DownloadResourceThrottle::~DownloadResourceThrottle() {
27 } 28 }
28 29
29 void DownloadResourceThrottle::WillStartRequest(bool* defer) { 30 void DownloadResourceThrottle::WillStartRequest(bool* defer) {
30 *defer = request_deferred_ = !request_allowed_; 31 WillDownload(defer);
31 } 32 }
32 33
33 void DownloadResourceThrottle::WillRedirectRequest(const GURL& new_url, 34 void DownloadResourceThrottle::WillRedirectRequest(const GURL& new_url,
34 bool* defer) { 35 bool* defer) {
35 *defer = request_deferred_ = !request_allowed_; 36 WillDownload(defer);
36 } 37 }
37 38
38 void DownloadResourceThrottle::WillProcessResponse(bool* defer) { 39 void DownloadResourceThrottle::WillProcessResponse(bool* defer) {
39 *defer = request_deferred_ = !request_allowed_; 40 WillDownload(defer);
41 }
42
43 void DownloadResourceThrottle::WillDownload(bool* defer) {
44 DCHECK(!request_deferred_);
45
46 // Defer the download until we have the DownloadRequestLimiter result.
47 if (querying_limiter_) {
48 request_deferred_ = true;
49 *defer = true;
50 return;
51 }
52
53 if (!request_allowed_)
54 controller()->Cancel();
40 } 55 }
41 56
42 void DownloadResourceThrottle::ContinueDownload(bool allow) { 57 void DownloadResourceThrottle::ContinueDownload(bool allow) {
58 querying_limiter_ = false;
43 request_allowed_ = allow; 59 request_allowed_ = allow;
60
44 if (allow) { 61 if (allow) {
45 // Presumes all downloads initiated by navigation using this throttle and 62 // Presumes all downloads initiated by navigation use this throttle and
46 // nothing else does. 63 // nothing else does.
47 download_util::RecordDownloadSource( 64 download_util::RecordDownloadSource(download_util::INITIATED_BY_NAVIGATION);
48 download_util::INITIATED_BY_NAVIGATION);
49 } else { 65 } else {
50 download_util::RecordDownloadCount(download_util::BLOCKED_BY_THROTTLING); 66 download_util::RecordDownloadCount(download_util::BLOCKED_BY_THROTTLING);
51 } 67 }
52 68
53 if (request_deferred_) { 69 if (request_deferred_) {
70 request_deferred_ = false;
54 if (allow) { 71 if (allow) {
55 controller()->Resume(); 72 controller()->Resume();
56 } else { 73 } else {
57 controller()->Cancel(); 74 controller()->Cancel();
58 } 75 }
59 } 76 }
60 } 77 }
OLDNEW
« 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