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

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

Issue 1692693003: add a flag to enable/disable download interception on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 10 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/command_line.h"
8 #include "base/metrics/field_trial.h"
7 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_util.h"
11 #include "chrome/common/chrome_switches.h"
8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
9 #include "content/public/browser/android/download_controller_android.h" 13 #include "content/public/browser/android/download_controller_android.h"
10 #include "content/public/browser/resource_controller.h" 14 #include "content/public/browser/resource_controller.h"
11 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
12 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
13 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
14 18
15 namespace { 19 namespace {
16 20
21 // Finch flag to be passed in.
22 const char kDisableDownloadInterception[] = "DisableDownloadInterception";
23
17 // UMA histogram for tracking reasons that chrome fails to intercept the 24 // UMA histogram for tracking reasons that chrome fails to intercept the
18 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in 25 // download. Keep this in sync with MobileDownloadInterceptFailureReasons in
19 // histograms.xml. 26 // histograms.xml.
20 enum MobileDownloadInterceptFailureReason { 27 enum MobileDownloadInterceptFailureReason {
21 NO_FAILURE = 0, 28 NO_FAILURE = 0,
22 EMPTY_URL, 29 EMPTY_URL,
23 NON_HTTP_OR_HTTPS, 30 NON_HTTP_OR_HTTPS,
24 NON_GET_METHODS, 31 NON_GET_METHODS,
25 NO_REQUEST_HEADERS, 32 NO_REQUEST_HEADERS,
26 USE_HTTP_AUTH, 33 USE_HTTP_AUTH,
27 USE_CHANNEL_BOUND_COOKIES, 34 USE_CHANNEL_BOUND_COOKIES,
28 // FAILURE_REASON_SIZE should always be last - this is a count of the number 35 // FAILURE_REASON_SIZE should always be last - this is a count of the number
29 // of items in this enum. 36 // of items in this enum.
30 FAILURE_REASON_SIZE, 37 FAILURE_REASON_SIZE,
31 }; 38 };
32 39
33 void RecordInterceptFailureReasons( 40 void RecordInterceptFailureReasons(
34 MobileDownloadInterceptFailureReason reason) { 41 MobileDownloadInterceptFailureReason reason) {
35 UMA_HISTOGRAM_ENUMERATION("MobileDownload.InterceptFailureReason", 42 UMA_HISTOGRAM_ENUMERATION("MobileDownload.InterceptFailureReason",
36 reason, 43 reason,
37 FAILURE_REASON_SIZE); 44 FAILURE_REASON_SIZE);
38 } 45 }
39 46
40 } // namespace 47 } // namespace
41 48
42 namespace chrome { 49 namespace chrome {
43 50
51 // static
52 bool InterceptDownloadResourceThrottle::IsDownloadInterceptionEnabled() {
53
54 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
55 switches::kEnableDownloadInterception)) {
56 return true;
57 }
58
59 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
60 switches::kDisableDownloadInterception)) {
61 return false;
62 }
63
64 return !base::StartsWith(
65 base::FieldTrialList::FindFullName(kDisableDownloadInterception),
asanka 2016/02/23 02:55:30 See base/feature_list.h . Rather than add the enab
qinmin 2016/02/23 22:28:05 Done.
66 "Enabled", base::CompareCase::INSENSITIVE_ASCII);
67 }
68
44 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( 69 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
45 net::URLRequest* request, 70 net::URLRequest* request,
46 int render_process_id, 71 int render_process_id,
47 int render_view_id, 72 int render_view_id,
48 int request_id) 73 int request_id)
49 : request_(request), 74 : request_(request),
50 render_process_id_(render_process_id), 75 render_process_id_(render_process_id),
51 render_view_id_(render_view_id), 76 render_view_id_(render_view_id),
52 request_id_(request_id) { 77 request_id_(request_id) {
53 } 78 }
54 79
55 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { 80 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
56 } 81 }
57 82
58 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { 83 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
59 ProcessDownloadRequest(); 84 ProcessDownloadRequest();
60 } 85 }
61 86
62 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { 87 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
63 return "InterceptDownloadResourceThrottle"; 88 return "InterceptDownloadResourceThrottle";
64 } 89 }
65 90
66 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { 91 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
92 if (!IsDownloadInterceptionEnabled())
93 return;
94
67 if (request_->url_chain().empty()) { 95 if (request_->url_chain().empty()) {
68 RecordInterceptFailureReasons(EMPTY_URL); 96 RecordInterceptFailureReasons(EMPTY_URL);
69 return; 97 return;
70 } 98 }
71 99
72 GURL url = request_->url_chain().back(); 100 GURL url = request_->url_chain().back();
73 if (!url.SchemeIsHTTPOrHTTPS()) { 101 if (!url.SchemeIsHTTPOrHTTPS()) {
74 RecordInterceptFailureReasons(NON_HTTP_OR_HTTPS); 102 RecordInterceptFailureReasons(NON_HTTP_OR_HTTPS);
75 return; 103 return;
76 } 104 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return; 136 return;
109 } 137 }
110 138
111 content::DownloadControllerAndroid::Get()->CreateGETDownload( 139 content::DownloadControllerAndroid::Get()->CreateGETDownload(
112 render_process_id_, render_view_id_, request_id_); 140 render_process_id_, render_view_id_, request_id_);
113 controller()->Cancel(); 141 controller()->Cancel();
114 RecordInterceptFailureReasons(NO_FAILURE); 142 RecordInterceptFailureReasons(NO_FAILURE);
115 } 143 }
116 144
117 } // namespace chrome 145 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698