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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_params.cc

Issue 390533003: Bypassed Bytes UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr comments Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/time/time.h"
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
11 #include "net/base/host_port_pair.h"
10 #include "net/proxy/proxy_info.h" 12 #include "net/proxy/proxy_info.h"
13 #include "net/proxy/proxy_retry_info.h"
14 #include "net/proxy/proxy_server.h"
11 #include "net/proxy/proxy_service.h" 15 #include "net/proxy/proxy_service.h"
12 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
13 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
18 #include "url/url_constants.h"
14 19
15 using base::FieldTrialList; 20 using base::FieldTrialList;
16 21
17 namespace { 22 namespace {
18 const char kEnabled[] = "Enabled"; 23 const char kEnabled[] = "Enabled";
19 } 24 }
20 25
21 namespace data_reduction_proxy { 26 namespace data_reduction_proxy {
22 27
23 // static 28 // static
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 159 }
155 if (promo_allowed_ && !allowed_) { 160 if (promo_allowed_ && !allowed_) {
156 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the " 161 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the "
157 << "data reduction proxy is not allowed"; 162 << "data reduction proxy is not allowed";
158 return false; 163 return false;
159 } 164 }
160 return true; 165 return true;
161 166
162 } 167 }
163 168
164
165 void DataReductionProxyParams::InitWithoutChecks() { 169 void DataReductionProxyParams::InitWithoutChecks() {
166 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 170 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
167 std::string origin; 171 std::string origin;
168 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) { 172 if (!command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) {
169 origin = command_line.GetSwitchValueASCII( 173 origin = command_line.GetSwitchValueASCII(
170 switches::kDataReductionProxyDev); 174 switches::kDataReductionProxyDev);
171 } 175 }
172 if (origin.empty()) 176 if (origin.empty())
173 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); 177 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy);
174 std::string fallback_origin = 178 std::string fallback_origin =
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return std::string(); 326 return std::string();
323 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || 327 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) ||
324 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == 328 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") ==
325 kEnabled)) { 329 kEnabled)) {
326 return DATA_REDUCTION_DEV_HOST; 330 return DATA_REDUCTION_DEV_HOST;
327 } 331 }
328 #endif 332 #endif
329 return std::string(); 333 return std::string();
330 } 334 }
331 335
336 bool DataReductionProxyParams::AreDataReductionProxiesBypassed(
337 const net::URLRequest& request, base::TimeDelta* min_retry_delay) const {
338 if (request.context() != NULL &&
339 request.context()->proxy_service() != NULL) {
340 return AreProxiesBypassed(
341 request.context()->proxy_service()->proxy_retry_info(),
342 request.url().SchemeIs(url::kHttpsScheme),
343 min_retry_delay);
344 }
345
346 return false;
347 }
348
349 bool DataReductionProxyParams::AreProxiesBypassed(
350 const net::ProxyRetryInfoMap& retry_map,
351 bool is_https,
352 base::TimeDelta* min_retry_delay) const {
353 if (retry_map.size() == 0)
354 return false;
355
356 if (is_https && alt_allowed_)
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Add {}'s
megjablon 2014/07/22 18:40:45 Done.
357 return ArePrimaryAndFallbackBypassed(
358 retry_map, ssl_origin_, GURL(), min_retry_delay);
359
360 if (allowed_) {
361 if (ArePrimaryAndFallbackBypassed(
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Merge with if above.
megjablon 2014/07/22 18:40:45 Done.
362 retry_map, origin_, fallback_origin_, min_retry_delay)) {
363 return true;
364 }
365 }
366
367 if (alt_allowed_) {
368 if (ArePrimaryAndFallbackBypassed(
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Merge with if above.
megjablon 2014/07/22 18:40:45 Done.
369 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) {
370 return true;
371 }
372 }
373
374 return false;
375 }
376
377 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed(
378 const net::ProxyRetryInfoMap& retry_map,
379 const GURL& primary,
380 const GURL& fallback,
381 base::TimeDelta* min_retry_delay) const {
382 base::TimeDelta min_delay;
383 net::ProxyRetryInfoMap::const_iterator found;
384
385 found = retry_map.find(
386 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ?
387 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP,
388 net::HostPortPair::FromURL(primary)).ToURI());
389 if (!(found == retry_map.end())) {
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Change to !=
megjablon 2014/07/22 18:40:45 Done.
390 min_delay = found->second.current_delay;
391 if (fallback_allowed_ && fallback.is_valid()) {
392 found = retry_map.find(
393 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ?
394 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP,
395 net::HostPortPair::FromURL(fallback)).ToURI());
396 if (!(found == retry_map.end())) {
397 if(min_delay > found->second.current_delay)
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Add space after if
megjablon 2014/07/22 18:40:45 Done.
398 min_delay = found->second.current_delay;
399 if (min_retry_delay != NULL)
400 *min_retry_delay = min_delay;
401 return true;
402 }
403 } else {
Alexei Svitkine (slow) 2014/07/22 13:57:21 Nit: Reverse the cond of the if (make it check for
megjablon 2014/07/22 18:40:45 Done.
404 if (min_retry_delay != NULL)
405 *min_retry_delay = min_delay;
406 return true;
407 }
408 }
409
410 return false;
411 }
412
332 std::string DataReductionProxyParams::GetDefaultOrigin() const { 413 std::string DataReductionProxyParams::GetDefaultOrigin() const {
333 #if defined(SPDY_PROXY_AUTH_ORIGIN) 414 #if defined(SPDY_PROXY_AUTH_ORIGIN)
334 return SPDY_PROXY_AUTH_ORIGIN; 415 return SPDY_PROXY_AUTH_ORIGIN;
335 #endif 416 #endif
336 return std::string(); 417 return std::string();
337 } 418 }
338 419
339 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { 420 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const {
340 #if defined(DATA_REDUCTION_FALLBACK_HOST) 421 #if defined(DATA_REDUCTION_FALLBACK_HOST)
341 return DATA_REDUCTION_FALLBACK_HOST; 422 return DATA_REDUCTION_FALLBACK_HOST;
(...skipping 30 matching lines...) Expand all
372 } 453 }
373 454
374 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { 455 std::string DataReductionProxyParams::GetDefaultWarmupURL() const {
375 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) 456 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL)
376 return DATA_REDUCTION_PROXY_WARMUP_URL; 457 return DATA_REDUCTION_PROXY_WARMUP_URL;
377 #endif 458 #endif
378 return std::string(); 459 return std::string();
379 } 460 }
380 461
381 } // namespace data_reduction_proxy 462 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698