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

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: Fixed WereDataReductionProxiesBypassed 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 "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " 9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
10 #include "net/proxy/proxy_info.h" 10 #include "net/proxy/proxy_info.h"
11 #include "net/proxy/proxy_service.h" 11 #include "net/proxy/proxy_service.h"
12 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
13 #include "net/url_request/url_request_context.h" 13 #include "net/url_request/url_request_context.h"
14 14
15 using base::FieldTrialList; 15 using base::FieldTrialList;
16 16
17 namespace { 17 namespace {
18 const char kEnabled[] = "Enabled"; 18 const char kEnabled[] = "Enabled";
19 } 19 }
20 20
21 using namespace net;
22
21 namespace data_reduction_proxy { 23 namespace data_reduction_proxy {
22 24
23 // static 25 // static
24 bool DataReductionProxyParams::IsIncludedInFieldTrial() { 26 bool DataReductionProxyParams::IsIncludedInFieldTrial() {
25 return base::FieldTrialList::FindFullName( 27 return base::FieldTrialList::FindFullName(
26 "DataCompressionProxyRollout") == kEnabled; 28 "DataCompressionProxyRollout") == kEnabled;
27 } 29 }
28 30
29 // static 31 // static
30 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() { 32 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return std::string(); 324 return std::string();
323 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || 325 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) ||
324 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == 326 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") ==
325 kEnabled)) { 327 kEnabled)) {
326 return DATA_REDUCTION_DEV_HOST; 328 return DATA_REDUCTION_DEV_HOST;
327 } 329 }
328 #endif 330 #endif
329 return std::string(); 331 return std::string();
330 } 332 }
331 333
334 bool WerePrimaryAndFallbackBypassed(
335 const net::ProxyRetryInfoMap& retry_map,
336 GURL primary,
337 GURL fallback,
338 bool fallback_allowed,
339 int64* delay_seconds) {
340 int64 shortest_delay = 0;
341 net::ProxyRetryInfoMap::const_iterator found;
342
343 std::string proxy = net::HostPortPair::FromURL(primary).ToString();
344 // The retry list has the scheme prefix for https but not for http.
345 if (primary.SchemeIs(url::kHttpsScheme))
346 proxy = std::string("https://") + proxy;
347
348 found = retry_map.find(proxy);
349 if (!(found == retry_map.end())) {
350 shortest_delay = found->second.current_delay.InSeconds();
351 if (fallback_allowed) {
352 proxy = net::HostPortPair::FromURL(fallback).ToString();
353 found = retry_map.find(proxy);
354 if (!(found == retry_map.end())) {
355 if(shortest_delay > found->second.current_delay.InSeconds())
356 shortest_delay = found->second.current_delay.InSeconds();
357 if (delay_seconds != NULL)
358 *delay_seconds = shortest_delay;
359 return true;
360 }
361 } else {
362 if (delay_seconds != NULL)
363 *delay_seconds = shortest_delay;
364 return true;
365 }
366 }
367
368 return false;
369 }
370
371 bool DataReductionProxyParams::WereDataReductionProxiesBypassed(
372 const net::URLRequest* request, int64* delay_seconds) const {
373 DCHECK(request);
374 DCHECK(request->context());
375 DCHECK(request->context()->proxy_service());
376
377 const net::ProxyRetryInfoMap& retry_map =
378 request->context()->proxy_service()->proxy_retry_info();
379 if (retry_map.size() == 0)
380 return false;
381
382 if(allowed_) {
383 if (WerePrimaryAndFallbackBypassed(retry_map,
384 origin_,
385 fallback_origin_,
386 fallback_allowed_,
387 delay_seconds)) {
388 return true;
389 }
390 }
391
392 if (alt_allowed_) {
393 if (WerePrimaryAndFallbackBypassed(retry_map,
394 alt_origin_,
395 alt_fallback_origin_,
396 fallback_allowed_,
397 delay_seconds)) {
398 return true;
399 }
400
401 if (WerePrimaryAndFallbackBypassed(
402 retry_map, ssl_origin_, GURL(), false, delay_seconds)) {
403 return true;
404 }
405 }
406
407 return false;
408 }
409
332 std::string DataReductionProxyParams::GetDefaultOrigin() const { 410 std::string DataReductionProxyParams::GetDefaultOrigin() const {
333 #if defined(SPDY_PROXY_AUTH_ORIGIN) 411 #if defined(SPDY_PROXY_AUTH_ORIGIN)
334 return SPDY_PROXY_AUTH_ORIGIN; 412 return SPDY_PROXY_AUTH_ORIGIN;
335 #endif 413 #endif
336 return std::string(); 414 return std::string();
337 } 415 }
338 416
339 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { 417 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const {
340 #if defined(DATA_REDUCTION_FALLBACK_HOST) 418 #if defined(DATA_REDUCTION_FALLBACK_HOST)
341 return DATA_REDUCTION_FALLBACK_HOST; 419 return DATA_REDUCTION_FALLBACK_HOST;
(...skipping 30 matching lines...) Expand all
372 } 450 }
373 451
374 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { 452 std::string DataReductionProxyParams::GetDefaultWarmupURL() const {
375 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) 453 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL)
376 return DATA_REDUCTION_PROXY_WARMUP_URL; 454 return DATA_REDUCTION_PROXY_WARMUP_URL;
377 #endif 455 #endif
378 return std::string(); 456 return std::string();
379 } 457 }
380 458
381 } // namespace data_reduction_proxy 459 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698