Chromium Code Reviews| Index: chrome/browser/android/intercept_download_resource_throttle.cc |
| diff --git a/chrome/browser/android/intercept_download_resource_throttle.cc b/chrome/browser/android/intercept_download_resource_throttle.cc |
| index 30fd0a118f346f7833ec01595fd639fb5622d601..dcee235470c1750b10b6a345d18798599b8552ac 100644 |
| --- a/chrome/browser/android/intercept_download_resource_throttle.cc |
| +++ b/chrome/browser/android/intercept_download_resource_throttle.cc |
| @@ -8,11 +8,14 @@ |
| #include "base/metrics/histogram_macros.h" |
| #include "chrome/browser/android/chrome_feature_list.h" |
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" |
| -#include "content/public/browser/android/download_controller_android.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/resource_controller.h" |
| #include "net/http/http_request_headers.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/url_request/url_request.h" |
| +#include "net/url_request/url_request_context.h" |
| + |
| +using content::BrowserThread; |
| namespace { |
| @@ -52,27 +55,26 @@ InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( |
| net::URLRequest* request, |
| int render_process_id, |
| int render_view_id, |
| - int request_id, |
| bool must_download) |
| : request_(request), |
| render_process_id_(render_process_id), |
| render_view_id_(render_view_id), |
| - request_id_(request_id), |
| - must_download_(must_download) { |
| + must_download_(must_download), |
| + cookie_completed_(false) { |
| } |
| InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { |
| } |
| void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { |
| - ProcessDownloadRequest(); |
| + ProcessDownloadRequest(defer); |
| } |
| const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { |
| return "InterceptDownloadResourceThrottle"; |
| } |
| -void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { |
| +void InterceptDownloadResourceThrottle::ProcessDownloadRequest(bool* defer) { |
| if (!IsDownloadInterceptionEnabled()) |
| return; |
| @@ -120,8 +122,50 @@ void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { |
| return; |
| } |
| - content::DownloadControllerAndroid::Get()->CreateGETDownload( |
| - render_process_id_, render_view_id_, request_id_, must_download_); |
| + net::CookieStore* cookie_store = request_->context()->cookie_store(); |
| + if (cookie_store && !cookie_completed_) { |
|
no sievers
2016/06/13 18:32:47
nit: Can you put a comment that deferring will cau
Jinsuk Kim
2016/06/14 00:55:58
Done.
|
| + // Download process will be resumed after we get the cookie asynchronously. |
| + *defer = true; |
| + net::CookieOptions options; |
| + options.set_include_httponly(); |
| + cookie_store->GetCookieListWithOptionsAsync( |
| + request_->url(), |
| + options, |
| + base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy, |
|
qinmin
2016/06/13 18:31:44
could the throttle go away while this is posted?
no sievers
2016/06/13 18:35:51
Actually good catch. This should still use a WeakP
Jinsuk Kim
2016/06/14 00:55:58
Thanks. Done.
Jinsuk Kim
2016/06/14 00:55:58
Yes it does. Used WeakPtr.
|
| + base::Unretained(this))); |
| + } else { |
| + DownloadInfo info(request_); |
| + if (!cookie_.empty()) { |
| + info.cookie = cookie_; |
| + } |
| + StartDownload(info); |
| + } |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::CheckCookiePolicy( |
| + const net::CookieList& cookie_list) { |
| + if (request_->context()->network_delegate()->CanGetCookies(*request_, |
| + cookie_list)) { |
| + cookie_ = net::CookieStore::BuildCookieLine(cookie_list); |
| + } |
| + cookie_completed_ = true; |
| + |
| + // Makes sure the request gets resumed after it is marked as such. |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&InterceptDownloadResourceThrottle::ResumeDeferredRequest, |
|
no sievers
2016/06/13 18:35:51
same here
Jinsuk Kim
2016/06/14 00:55:58
Done.
|
| + base::Unretained(this))); |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::ResumeDeferredRequest() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + controller()->Resume(); |
|
no sievers
2016/06/13 18:32:47
maybe even mention it here too, since that resourc
Jinsuk Kim
2016/06/14 00:55:58
Done.
|
| +} |
| + |
| +void InterceptDownloadResourceThrottle::StartDownload( |
| + const DownloadInfo& info) { |
| + DownloadControllerBase::Get()->CreateGETDownload( |
| + render_process_id_, render_view_id_, must_download_, info); |
| controller()->Cancel(); |
| RecordInterceptFailureReasons(NO_FAILURE); |
| } |