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

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: allow server trial to be overriden 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),
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 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return; 133 return;
109 } 134 }
110 135
111 content::DownloadControllerAndroid::Get()->CreateGETDownload( 136 content::DownloadControllerAndroid::Get()->CreateGETDownload(
112 render_process_id_, render_view_id_, request_id_); 137 render_process_id_, render_view_id_, request_id_);
113 controller()->Cancel(); 138 controller()->Cancel();
114 RecordInterceptFailureReasons(NO_FAILURE); 139 RecordInterceptFailureReasons(NO_FAILURE);
115 } 140 }
116 141
117 } // namespace chrome 142 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698