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..63a5eb18afe2bfc88599c37ca702dbe7492cdbcf 100644 |
| --- a/chrome/browser/android/intercept_download_resource_throttle.cc |
| +++ b/chrome/browser/android/intercept_download_resource_throttle.cc |
| @@ -8,11 +8,11 @@ |
| #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/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" |
| namespace { |
| @@ -52,12 +52,10 @@ 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) { |
| } |
| @@ -120,8 +118,61 @@ void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { |
| return; |
| } |
| - content::DownloadControllerAndroid::Get()->CreateGETDownload( |
| - render_process_id_, render_view_id_, request_id_, must_download_); |
| + // Prepare download. |
| + DownloadInfo info(request_); |
| + |
| + net::CookieStore* cookie_store = request_->context()->cookie_store(); |
| + if (cookie_store) { |
| + StartDownloadCB callback = base::Bind( |
| + &InterceptDownloadResourceThrottle::StartDownload, |
| + base::Unretained(this)); |
| + cookie_store->GetAllCookiesForURLAsync( |
|
no sievers
2016/06/10 19:40:06
Can't we use GetCookieListWithOptionsAsync() in th
Jinsuk Kim
2016/06/13 03:21:12
Done. Sorry I should have done this in the previou
|
| + request_->url(), |
| + base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy, |
| + base::Unretained(this), info, callback)); |
|
no sievers
2016/06/10 19:40:06
|this| might go away...
Jinsuk Kim
2016/06/13 03:21:12
Set |defer| to true to make sure |this| will stay.
|
| + } else { |
| + // Can't get any cookies, start download. |
| + StartDownload(info); |
| + } |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::CheckCookiePolicy( |
| + const DownloadInfo& info, const StartDownloadCB& callback, |
| + const net::CookieList& cookie_list) { |
| + if (request_->context()->network_delegate()->CanGetCookies(*request_, |
|
no sievers
2016/06/10 19:40:06
And even if |this| is still valid, |request| might
Jinsuk Kim
2016/06/13 03:21:12
Set |defer| to true to resume the process later wh
Jinsuk Kim
2016/06/13 05:34:50
Didn't split CanGetCookies() because it doesn't lo
|
| + cookie_list)) { |
| + DoLoadCookies(info, callback); |
| + } else { |
| + callback.Run(info); |
| + } |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::DoLoadCookies( |
| + const DownloadInfo& info, |
| + const StartDownloadCB& callback) { |
| + net::CookieOptions options; |
| + options.set_include_httponly(); |
| + |
| + request_->context()->cookie_store()->GetCookiesWithOptionsAsync( |
| + info.url, options, |
| + base::Bind(&InterceptDownloadResourceThrottle::OnCookieResponse, |
| + base::Unretained(this), info, callback)); |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::OnCookieResponse( |
| + DownloadInfo download_info, |
| + const StartDownloadCB& callback, |
| + const std::string& cookie) { |
| + download_info.cookie = cookie; |
| + |
| + // We have everything we need, start download. |
| + callback.Run(download_info); |
| +} |
| + |
| +void InterceptDownloadResourceThrottle::StartDownload( |
| + const DownloadInfo& info) { |
| + DownloadControllerBase::Get()->CreateGETDownload( |
| + render_process_id_, render_view_id_, must_download_, info); |
| controller()->Cancel(); |
| RecordInterceptFailureReasons(NO_FAILURE); |
| } |