Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/android/intercept_download_resource_throttle.cc

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed deprecated cookie apis Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 cookie_completed_(false) {
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
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 && !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.
127 // Download process will be resumed after we get the cookie asynchronously.
128 *defer = true;
129 net::CookieOptions options;
130 options.set_include_httponly();
131 cookie_store->GetCookieListWithOptionsAsync(
132 request_->url(),
133 options,
134 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.
135 base::Unretained(this)));
136 } else {
137 DownloadInfo info(request_);
138 if (!cookie_.empty()) {
139 info.cookie = cookie_;
140 }
141 StartDownload(info);
142 }
143 }
144
145 void InterceptDownloadResourceThrottle::CheckCookiePolicy(
146 const net::CookieList& cookie_list) {
147 if (request_->context()->network_delegate()->CanGetCookies(*request_,
148 cookie_list)) {
149 cookie_ = net::CookieStore::BuildCookieLine(cookie_list);
150 }
151 cookie_completed_ = true;
152
153 // Makes sure the request gets resumed after it is marked as such.
154 BrowserThread::PostTask(
155 BrowserThread::IO, FROM_HERE,
156 base::Bind(&InterceptDownloadResourceThrottle::ResumeDeferredRequest,
no sievers 2016/06/13 18:35:51 same here
Jinsuk Kim 2016/06/14 00:55:58 Done.
157 base::Unretained(this)));
158 }
159
160 void InterceptDownloadResourceThrottle::ResumeDeferredRequest() {
161 DCHECK_CURRENTLY_ON(BrowserThread::IO);
162 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.
163 }
164
165 void InterceptDownloadResourceThrottle::StartDownload(
166 const DownloadInfo& info) {
167 DownloadControllerBase::Get()->CreateGETDownload(
168 render_process_id_, render_view_id_, must_download_, info);
125 controller()->Cancel(); 169 controller()->Cancel();
126 RecordInterceptFailureReasons(NO_FAILURE); 170 RecordInterceptFailureReasons(NO_FAILURE);
127 } 171 }
128 172
129 } // namespace chrome 173 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698