| OLD | NEW |
| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/download/download_stats.h" | 11 #include "chrome/browser/download/download_stats.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/resource_controller.h" | |
| 14 | 13 |
| 15 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 16 #include "chrome/browser/android/download/download_controller_base.h" | 15 #include "chrome/browser/android/download/download_controller_base.h" |
| 17 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 using content::BrowserThread; | 19 using content::BrowserThread; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DCHECK(!request_deferred_); | 122 DCHECK(!request_deferred_); |
| 124 | 123 |
| 125 // Defer the download until we have the DownloadRequestLimiter result. | 124 // Defer the download until we have the DownloadRequestLimiter result. |
| 126 if (querying_limiter_) { | 125 if (querying_limiter_) { |
| 127 request_deferred_ = true; | 126 request_deferred_ = true; |
| 128 *defer = true; | 127 *defer = true; |
| 129 return; | 128 return; |
| 130 } | 129 } |
| 131 | 130 |
| 132 if (!request_allowed_) | 131 if (!request_allowed_) |
| 133 controller()->Cancel(); | 132 Cancel(); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void DownloadResourceThrottle::ContinueDownload(bool allow) { | 135 void DownloadResourceThrottle::ContinueDownload(bool allow) { |
| 137 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 138 querying_limiter_ = false; | 137 querying_limiter_ = false; |
| 139 request_allowed_ = allow; | 138 request_allowed_ = allow; |
| 140 | 139 |
| 141 if (allow) { | 140 if (allow) { |
| 142 // Presumes all downloads initiated by navigation use this throttle and | 141 // Presumes all downloads initiated by navigation use this throttle and |
| 143 // nothing else does. | 142 // nothing else does. |
| 144 RecordDownloadSource(DOWNLOAD_INITIATED_BY_NAVIGATION); | 143 RecordDownloadSource(DOWNLOAD_INITIATED_BY_NAVIGATION); |
| 145 } else { | 144 } else { |
| 146 RecordDownloadCount(CHROME_DOWNLOAD_COUNT_BLOCKED_BY_THROTTLING); | 145 RecordDownloadCount(CHROME_DOWNLOAD_COUNT_BLOCKED_BY_THROTTLING); |
| 147 } | 146 } |
| 148 | 147 |
| 149 if (request_deferred_) { | 148 if (request_deferred_) { |
| 150 request_deferred_ = false; | 149 request_deferred_ = false; |
| 151 if (allow) { | 150 if (allow) { |
| 152 controller()->Resume(); | 151 Resume(); |
| 153 } else { | 152 } else { |
| 154 controller()->Cancel(); | 153 Cancel(); |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 } | 156 } |
| OLD | NEW |