| 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" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/resource_controller.h" | 12 #include "content/public/browser/resource_controller.h" |
| 13 #include "net/http/http_request_headers.h" | 13 #include "net/http/http_request_headers.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_context.h" |
| 17 |
| 18 using content::BrowserThread; |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 // UMA histogram for tracking reasons that chrome fails to intercept the | 22 // UMA histogram for tracking reasons that chrome fails to intercept the |
| 20 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in | 23 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in |
| 21 // histograms.xml. | 24 // histograms.xml. |
| 22 enum MobileDownloadInterceptFailureReason { | 25 enum MobileDownloadInterceptFailureReason { |
| 23 NO_FAILURE = 0, | 26 NO_FAILURE = 0, |
| 24 EMPTY_URL, | 27 EMPTY_URL, |
| 25 NON_HTTP_OR_HTTPS, | 28 NON_HTTP_OR_HTTPS, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 | 48 |
| 46 // static | 49 // static |
| 47 bool InterceptDownloadResourceThrottle::IsDownloadInterceptionEnabled() { | 50 bool InterceptDownloadResourceThrottle::IsDownloadInterceptionEnabled() { |
| 48 return base::FeatureList::IsEnabled(chrome::android::kSystemDownloadManager); | 51 return base::FeatureList::IsEnabled(chrome::android::kSystemDownloadManager); |
| 49 } | 52 } |
| 50 | 53 |
| 51 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( | 54 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( |
| 52 net::URLRequest* request, | 55 net::URLRequest* request, |
| 53 int render_process_id, | 56 int render_process_id, |
| 54 int render_view_id, | 57 int render_view_id, |
| 55 int request_id, | |
| 56 bool must_download) | 58 bool must_download) |
| 57 : request_(request), | 59 : request_(request), |
| 58 render_process_id_(render_process_id), | 60 render_process_id_(render_process_id), |
| 59 render_view_id_(render_view_id), | 61 render_view_id_(render_view_id), |
| 60 request_id_(request_id), | 62 must_download_(must_download), |
| 61 must_download_(must_download) { | 63 weak_factory_(this) { |
| 62 } | 64 } |
| 63 | 65 |
| 64 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { | 66 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { |
| 65 } | 67 } |
| 66 | 68 |
| 67 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { | 69 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { |
| 68 ProcessDownloadRequest(); | 70 ProcessDownloadRequest(defer); |
| 69 } | 71 } |
| 70 | 72 |
| 71 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { | 73 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { |
| 72 return "InterceptDownloadResourceThrottle"; | 74 return "InterceptDownloadResourceThrottle"; |
| 73 } | 75 } |
| 74 | 76 |
| 75 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { | 77 void InterceptDownloadResourceThrottle::ProcessDownloadRequest(bool* defer) { |
| 76 if (!IsDownloadInterceptionEnabled()) | 78 if (!IsDownloadInterceptionEnabled()) |
| 77 return; | 79 return; |
| 78 | 80 |
| 79 if (request_->url_chain().empty()) { | 81 if (request_->url_chain().empty()) { |
| 80 RecordInterceptFailureReasons(EMPTY_URL); | 82 RecordInterceptFailureReasons(EMPTY_URL); |
| 81 return; | 83 return; |
| 82 } | 84 } |
| 83 | 85 |
| 84 GURL url = request_->url_chain().back(); | 86 GURL url = request_->url_chain().back(); |
| 85 if (!url.SchemeIsHTTPOrHTTPS()) { | 87 if (!url.SchemeIsHTTPOrHTTPS()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 } | 115 } |
| 114 | 116 |
| 115 // If the cookie is possibly channel-bound, don't pass it to android download | 117 // If the cookie is possibly channel-bound, don't pass it to android download |
| 116 // manager. | 118 // manager. |
| 117 // TODO(qinmin): add a test for this. http://crbug.com/430541. | 119 // TODO(qinmin): add a test for this. http://crbug.com/430541. |
| 118 if (request_->ssl_info().channel_id_sent) { | 120 if (request_->ssl_info().channel_id_sent) { |
| 119 RecordInterceptFailureReasons(USE_CHANNEL_BOUND_COOKIES); | 121 RecordInterceptFailureReasons(USE_CHANNEL_BOUND_COOKIES); |
| 120 return; | 122 return; |
| 121 } | 123 } |
| 122 | 124 |
| 123 content::DownloadControllerAndroid::Get()->CreateGETDownload( | 125 net::CookieStore* cookie_store = request_->context()->cookie_store(); |
| 124 render_process_id_, render_view_id_, request_id_, must_download_); | 126 if (cookie_store) { |
| 127 // Cookie is obtained via asynchonous call. Setting |*defer| to true |
| 128 // keeps the throttle alive in the meantime. |
| 129 *defer = true; |
| 130 net::CookieOptions options; |
| 131 options.set_include_httponly(); |
| 132 cookie_store->GetCookieListWithOptionsAsync( |
| 133 request_->url(), |
| 134 options, |
| 135 base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy, |
| 136 weak_factory_.GetWeakPtr())); |
| 137 } else { |
| 138 // Can't get any cookies, start android download. |
| 139 StartDownload(DownloadInfo(request_)); |
| 140 } |
| 141 } |
| 142 |
| 143 void InterceptDownloadResourceThrottle::CheckCookiePolicy( |
| 144 const net::CookieList& cookie_list) { |
| 145 DownloadInfo info(request_); |
| 146 if (request_->context()->network_delegate()->CanGetCookies(*request_, |
| 147 cookie_list)) { |
| 148 std::string cookie = net::CookieStore::BuildCookieLine(cookie_list); |
| 149 if (!cookie.empty()) { |
| 150 info.cookie = cookie; |
| 151 } |
| 152 } |
| 153 StartDownload(info); |
| 154 } |
| 155 |
| 156 void InterceptDownloadResourceThrottle::StartDownload( |
| 157 const DownloadInfo& info) { |
| 158 DownloadControllerBase::Get()->CreateGETDownload( |
| 159 render_process_id_, render_view_id_, must_download_, info); |
| 125 controller()->Cancel(); | 160 controller()->Cancel(); |
| 126 RecordInterceptFailureReasons(NO_FAILURE); | 161 RecordInterceptFailureReasons(NO_FAILURE); |
| 127 } | 162 } |
| 128 | 163 |
| 129 } // namespace chrome | 164 } // namespace chrome |
| OLD | NEW |