Chromium Code Reviews| 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/android/intercept_download_resource_throttle.h" | 5 #include "chrome/browser/android/intercept_download_resource_throttle.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/android/chrome_feature_list.h" | 9 #include "chrome/browser/android/chrome_feature_list.h" |
| 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
| 11 #include "content/public/browser/android/download_controller_android.h" | |
| 12 #include "content/public/browser/resource_controller.h" | 11 #include "content/public/browser/resource_controller.h" |
| 13 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
| 14 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 15 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_context.h" | |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // UMA histogram for tracking reasons that chrome fails to intercept the | 19 // UMA histogram for tracking reasons that chrome fails to intercept the |
| 20 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in | 20 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in |
| 21 // histograms.xml. | 21 // histograms.xml. |
| 22 enum MobileDownloadInterceptFailureReason { | 22 enum MobileDownloadInterceptFailureReason { |
| 23 NO_FAILURE = 0, | 23 NO_FAILURE = 0, |
| 24 EMPTY_URL, | 24 EMPTY_URL, |
| 25 NON_HTTP_OR_HTTPS, | 25 NON_HTTP_OR_HTTPS, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 bool InterceptDownloadResourceThrottle::IsDownloadInterceptionEnabled() { | 47 bool InterceptDownloadResourceThrottle::IsDownloadInterceptionEnabled() { |
| 48 return base::FeatureList::IsEnabled(chrome::android::kSystemDownloadManager); | 48 return base::FeatureList::IsEnabled(chrome::android::kSystemDownloadManager); |
| 49 } | 49 } |
| 50 | 50 |
| 51 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( | 51 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( |
| 52 net::URLRequest* request, | 52 net::URLRequest* request, |
| 53 int render_process_id, | 53 int render_process_id, |
| 54 int render_view_id, | 54 int render_view_id, |
| 55 int request_id, | |
| 56 bool must_download) | 55 bool must_download) |
| 57 : request_(request), | 56 : request_(request), |
| 58 render_process_id_(render_process_id), | 57 render_process_id_(render_process_id), |
| 59 render_view_id_(render_view_id), | 58 render_view_id_(render_view_id), |
| 60 request_id_(request_id), | |
| 61 must_download_(must_download) { | 59 must_download_(must_download) { |
| 62 } | 60 } |
| 63 | 61 |
| 64 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { | 62 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { |
| 65 } | 63 } |
| 66 | 64 |
| 67 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { | 65 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { |
| 68 ProcessDownloadRequest(); | 66 ProcessDownloadRequest(); |
| 69 } | 67 } |
| 70 | 68 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 } | 111 } |
| 114 | 112 |
| 115 // If the cookie is possibly channel-bound, don't pass it to android download | 113 // If the cookie is possibly channel-bound, don't pass it to android download |
| 116 // manager. | 114 // manager. |
| 117 // TODO(qinmin): add a test for this. http://crbug.com/430541. | 115 // TODO(qinmin): add a test for this. http://crbug.com/430541. |
| 118 if (request_->ssl_info().channel_id_sent) { | 116 if (request_->ssl_info().channel_id_sent) { |
| 119 RecordInterceptFailureReasons(USE_CHANNEL_BOUND_COOKIES); | 117 RecordInterceptFailureReasons(USE_CHANNEL_BOUND_COOKIES); |
| 120 return; | 118 return; |
| 121 } | 119 } |
| 122 | 120 |
| 123 content::DownloadControllerAndroid::Get()->CreateGETDownload( | 121 // Prepare download. |
| 124 render_process_id_, render_view_id_, request_id_, must_download_); | 122 DownloadInfo info(request_); |
| 123 | |
| 124 net::CookieStore* cookie_store = request_->context()->cookie_store(); | |
| 125 if (cookie_store) { | |
| 126 StartDownloadCB callback = base::Bind( | |
| 127 &InterceptDownloadResourceThrottle::StartDownload, | |
| 128 base::Unretained(this)); | |
| 129 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
| |
| 130 request_->url(), | |
| 131 base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy, | |
| 132 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.
| |
| 133 } else { | |
| 134 // Can't get any cookies, start download. | |
| 135 StartDownload(info); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 void InterceptDownloadResourceThrottle::CheckCookiePolicy( | |
| 140 const DownloadInfo& info, const StartDownloadCB& callback, | |
| 141 const net::CookieList& cookie_list) { | |
| 142 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
| |
| 143 cookie_list)) { | |
| 144 DoLoadCookies(info, callback); | |
| 145 } else { | |
| 146 callback.Run(info); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 void InterceptDownloadResourceThrottle::DoLoadCookies( | |
| 151 const DownloadInfo& info, | |
| 152 const StartDownloadCB& callback) { | |
| 153 net::CookieOptions options; | |
| 154 options.set_include_httponly(); | |
| 155 | |
| 156 request_->context()->cookie_store()->GetCookiesWithOptionsAsync( | |
| 157 info.url, options, | |
| 158 base::Bind(&InterceptDownloadResourceThrottle::OnCookieResponse, | |
| 159 base::Unretained(this), info, callback)); | |
| 160 } | |
| 161 | |
| 162 void InterceptDownloadResourceThrottle::OnCookieResponse( | |
| 163 DownloadInfo download_info, | |
| 164 const StartDownloadCB& callback, | |
| 165 const std::string& cookie) { | |
| 166 download_info.cookie = cookie; | |
| 167 | |
| 168 // We have everything we need, start download. | |
| 169 callback.Run(download_info); | |
| 170 } | |
| 171 | |
| 172 void InterceptDownloadResourceThrottle::StartDownload( | |
| 173 const DownloadInfo& info) { | |
| 174 DownloadControllerBase::Get()->CreateGETDownload( | |
| 175 render_process_id_, render_view_id_, must_download_, info); | |
| 125 controller()->Cancel(); | 176 controller()->Cancel(); |
| 126 RecordInterceptFailureReasons(NO_FAILURE); | 177 RecordInterceptFailureReasons(NO_FAILURE); |
| 127 } | 178 } |
| 128 | 179 |
| 129 } // namespace chrome | 180 } // namespace chrome |
| OLD | NEW |