diff options
Diffstat (limited to 'chromium/components/data_reduction_proxy/core/common')
15 files changed, 485 insertions, 416 deletions
diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h index c2f79e9b84e..008d01928d3 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h @@ -7,8 +7,6 @@ #include <vector> -class GURL; - namespace data_reduction_proxy { class DataReductionProxyServer; @@ -17,22 +15,9 @@ class DataReductionProxyConfigValues { public: virtual ~DataReductionProxyConfigValues() {} - // Returns true if the data reduction proxy promo may be shown. - // This is independent of whether the data reduction proxy is allowed. - // TODO(bengr): maybe tie to whether proxy is allowed. - virtual bool promo_allowed() const = 0; - - // Returns true if the data reduction proxy should not actually use the - // proxy if enabled. - virtual bool holdback() const = 0; - // Returns the HTTP proxy servers to be used. virtual const std::vector<DataReductionProxyServer>& proxies_for_http() const = 0; - - // Returns the URL to check to decide if the secure proxy origin should be - // used. - virtual const GURL& secure_proxy_check_url() const = 0; }; } // namespace data_reduction_proxy diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc index fd6ddc7bd21..ee0fa9dfcd1 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc @@ -106,8 +106,8 @@ DataReductionProxyEventStore::GetSummaryValue() const { auto data_reduction_proxy_values = base::MakeUnique<base::DictionaryValue>(); data_reduction_proxy_values->SetBoolean("enabled", enabled_); if (current_configuration_) { - data_reduction_proxy_values->Set("proxy_config", - current_configuration_->DeepCopy()); + data_reduction_proxy_values->Set( + "proxy_config", base::MakeUnique<base::Value>(*current_configuration_)); } switch (secure_proxy_check_state_) { @@ -129,8 +129,8 @@ DataReductionProxyEventStore::GetSummaryValue() const { int current_time_ticks_ms = (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); if (expiration_ticks_ > current_time_ticks_ms) { - data_reduction_proxy_values->Set("last_bypass", - last_bypass_event->DeepCopy()); + data_reduction_proxy_values->Set( + "last_bypass", base::MakeUnique<base::Value>(*last_bypass_event)); } } diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.cc index f2547d74569..d11c0199df4 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.cc @@ -20,7 +20,12 @@ const base::Feature kDataReductionSiteBreakdown{ // version required the client to make this decision. The new protocol relies // on updates primarily to the Chrome-Proxy-Accept-Transform header. const base::Feature kDataReductionProxyDecidesTransform{ - "DataReductionProxyDecidesTransform", base::FEATURE_DISABLED_BY_DEFAULT}; + "DataReductionProxyDecidesTransform", base::FEATURE_ENABLED_BY_DEFAULT}; + +// Enables the data saver promo for low memory Android devices. +const base::Feature kDataReductionProxyLowMemoryDevicePromo{ + "DataReductionProxyLowMemoryDevicePromo", + base::FEATURE_DISABLED_BY_DEFAULT}; } // namespace features } // namespace data_reduction_proxy diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.h index af951c894ae..4650fcff19b 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_features.h @@ -13,6 +13,7 @@ namespace features { extern const base::Feature kDataReductionMainMenu; extern const base::Feature kDataReductionSiteBreakdown; extern const base::Feature kDataReductionProxyDecidesTransform; +extern const base::Feature kDataReductionProxyLowMemoryDevicePromo; } // namespace features } // namespace data_reduction_proxy diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc index 8961f1b7afb..543bcc5cdf1 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc @@ -29,6 +29,9 @@ using base::TimeDelta; namespace { const char kChromeProxyHeader[] = "chrome-proxy"; +const char kDataReductionPassThroughHeader[] = + "Chrome-Proxy-Accept-Transform: identity\r\nCache-Control: " + "no-cache\r\n\r\n"; const char kChromeProxyECTHeader[] = "chrome-proxy-ect"; const char kChromeProxyAcceptTransformHeader[] = "chrome-proxy-accept-transform"; @@ -42,11 +45,14 @@ const char kEmptyImageDirective[] = "empty-image"; const char kLitePageDirective[] = "lite-page"; const char kCompressedVideoDirective[] = "compressed-video"; const char kIdentityDirective[] = "identity"; +const char kChromeProxyPagePoliciesDirective[] = "page-policies"; // The legacy Chrome-Proxy response header directive for LoFi images. const char kLegacyChromeProxyLoFiResponseDirective[] = "q=low"; -const char kChromeProxyForceLitePageExperiment[] = "force_lite_page"; +const char kChromeProxyExperimentForceLitePage[] = "force_lite_page"; +const char kChromeProxyExperimentForceEmptyImage[] = + "force_page_policies_empty_image"; const char kIfHeavyQualifier[] = "if-heavy"; @@ -118,6 +124,30 @@ bool HasURLRedirectCycle(const std::vector<GURL>& url_chain) { url_chain.back()) != url_chain.rend(); } +data_reduction_proxy::TransformDirective ParsePagePolicyDirective( + const std::string chrome_proxy_header_value) { + for (const auto& directive : base::SplitStringPiece( + chrome_proxy_header_value, ",", base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY)) { + if (!base::StartsWith(directive, kChromeProxyPagePoliciesDirective, + base::CompareCase::INSENSITIVE_ASCII)) { + continue; + } + + // Check policy directive for empty-image entry. + base::StringPiece page_policies_value = base::StringPiece(directive).substr( + arraysize(kChromeProxyPagePoliciesDirective)); + for (const auto& policy : + base::SplitStringPiece(page_policies_value, "|", base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY)) { + if (base::LowerCaseEqualsASCII(policy, kEmptyImageDirective)) { + return data_reduction_proxy::TRANSFORM_PAGE_POLICIES_EMPTY_IMAGE; + } + } + } + return data_reduction_proxy::TRANSFORM_NONE; +} + } // namespace namespace data_reduction_proxy { @@ -126,6 +156,10 @@ const char* chrome_proxy_header() { return kChromeProxyHeader; } +const char* chrome_proxy_pass_through_header() { + return kDataReductionPassThroughHeader; +} + const char* chrome_proxy_ect_header() { return kChromeProxyECTHeader; } @@ -150,18 +184,70 @@ const char* compressed_video_directive() { return kCompressedVideoDirective; } -const char* identity_directive() { - return kIdentityDirective; +const char* chrome_proxy_experiment_force_lite_page() { + return kChromeProxyExperimentForceLitePage; } -const char* chrome_proxy_force_lite_page_experiment() { - return kChromeProxyForceLitePageExperiment; +const char* chrome_proxy_experiment_force_empty_image() { + return kChromeProxyExperimentForceEmptyImage; } const char* if_heavy_qualifier() { return kIfHeavyQualifier; } +TransformDirective ParseRequestTransform( + const net::HttpRequestHeaders& headers) { + std::string accept_transform_value; + if (!headers.GetHeader(chrome_proxy_accept_transform_header(), + &accept_transform_value)) { + return TRANSFORM_NONE; + } + + if (base::LowerCaseEqualsASCII(accept_transform_value, + lite_page_directive())) { + return TRANSFORM_LITE_PAGE; + } else if (base::LowerCaseEqualsASCII(accept_transform_value, + empty_image_directive())) { + return TRANSFORM_EMPTY_IMAGE; + } else if (base::LowerCaseEqualsASCII(accept_transform_value, + compressed_video_directive())) { + return TRANSFORM_COMPRESSED_VIDEO; + } else if (base::LowerCaseEqualsASCII(accept_transform_value, + kIdentityDirective)) { + return TRANSFORM_IDENTITY; + } else { + return TRANSFORM_NONE; + } +} + +TransformDirective ParseResponseTransform( + const net::HttpResponseHeaders& headers) { + std::string content_transform_value; + if (!headers.GetNormalizedHeader(chrome_proxy_content_transform_header(), + &content_transform_value)) { + // No content-transform so check for page-policies in chrome-proxy header. + std::string chrome_proxy_header_value; + if (headers.GetNormalizedHeader(chrome_proxy_header(), + &chrome_proxy_header_value)) { + return ParsePagePolicyDirective(chrome_proxy_header_value); + } + } else if (base::LowerCaseEqualsASCII(content_transform_value, + lite_page_directive())) { + return TRANSFORM_LITE_PAGE; + } else if (base::LowerCaseEqualsASCII(content_transform_value, + empty_image_directive())) { + return TRANSFORM_EMPTY_IMAGE; + } else if (base::LowerCaseEqualsASCII(content_transform_value, + kIdentityDirective)) { + return TRANSFORM_IDENTITY; + } else { + NOTREACHED() << "Unexpected content transform header: " + << content_transform_value; + } + return TRANSFORM_NONE; +} + bool IsEmptyImagePreview(const net::HttpResponseHeaders& headers) { return IsPreviewType(headers, kEmptyImageDirective) || headers.HasHeaderValue(kChromeProxyHeader, diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h index 83202075cf1..7dfedda6edc 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h @@ -11,6 +11,8 @@ #include "base/macros.h" #include "base/strings/string_piece.h" #include "base/time/time.h" +#include "net/http/http_request_headers.h" +#include "net/http/http_response_headers.h" #include "net/proxy/proxy_service.h" class GURL; @@ -21,6 +23,16 @@ class HttpResponseHeaders; namespace data_reduction_proxy { +// Transform directives that may be parsed out of http headers. +enum TransformDirective { + TRANSFORM_NONE, + TRANSFORM_LITE_PAGE, + TRANSFORM_EMPTY_IMAGE, + TRANSFORM_COMPRESSED_VIDEO, + TRANSFORM_PAGE_POLICIES_EMPTY_IMAGE, + TRANSFORM_IDENTITY, +}; + // Values of the UMA DataReductionProxy.BypassType{Primary|Fallback} and // DataReductionProxy.BlockType{Primary|Fallback} histograms. This enum must // remain synchronized with the enum of the same name in @@ -68,6 +80,11 @@ struct DataReductionProxyInfo { // Gets the header used for data reduction proxy requests and responses. const char* chrome_proxy_header(); +// The header used to request a data reduction proxy pass through. When a +// request is sent to the data reduction proxy with this header, it will respond +// with the original uncompressed response. +const char* chrome_proxy_pass_through_header(); + // Gets the chrome-proxy-ect request header that includes the effective // connection type. const char* chrome_proxy_ect_header(); @@ -90,17 +107,17 @@ const char* lite_page_directive(); // compressed video. const char* compressed_video_directive(); -// Gets the directive used by the data reduction proxy to request that -// a resource not be transformed. -const char* identity_directive(); - // Gets the Chrome-Proxy directive used by data reduction proxy lite page // preview requests and responses. const char* chrome_proxy_lite_page_directive(); // Gets the Chrome-Proxy experiment ("exp") value to force a lite page preview // for requests that accept lite pages. -const char* chrome_proxy_force_lite_page_experiment(); +const char* chrome_proxy_experiment_force_lite_page(); + +// Gets the Chrome-Proxy experiment ("exp") value to force an empty image +// preview for requests that enable server provided previews. +const char* chrome_proxy_experiment_force_empty_image(); // Requests a transformation only if the server determines that the page is // otherwise heavy (i.e., the associated page load ordinarily requires the @@ -112,6 +129,18 @@ const char* if_heavy_qualifier(); // that an empty image has been provided. bool IsEmptyImagePreview(const net::HttpResponseHeaders& headers); +// Retrieves the accepted transform type, if any, from |headers|. +TransformDirective ParseRequestTransform( + const net::HttpRequestHeaders& headers); + +// Retrieves the transform directive (whether applied or a page policy), if any, +// from |headers|. +// Note if the response headers contains both an applied content transform and +// a page policies directive, only the applied content transform type will +// be returned. +TransformDirective ParseResponseTransform( + const net::HttpResponseHeaders& headers); + // Returns true if the provided value of the Chrome-Proxy-Content-Transform // response header that is provided in |content_transform_value| indicates that // an empty image has been provided. diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc index f0a2d3d0831..66c9a2d0055 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc @@ -13,13 +13,17 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" #include "components/variations/variations_associated_data.h" #include "net/proxy/proxy_server.h" #include "url/url_constants.h" -using base::FieldTrialList; +#if defined(OS_ANDROID) +#include "base/android/build_info.h" +#include "base/sys_info.h" +#endif namespace { @@ -27,22 +31,12 @@ const char kEnabled[] = "Enabled"; const char kControl[] = "Control"; const char kDisabled[] = "Disabled"; const char kLitePage[] = "Enabled_Preview"; -const char kDefaultSpdyOrigin[] = "https://proxy.googlezip.net:443"; -// A one-off change, until the Data Reduction Proxy configuration service is -// available. -const char kCarrierTestOrigin[] = - "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80"; -const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; const char kDefaultSecureProxyCheckUrl[] = "http://check.googlezip.net/connect"; const char kDefaultWarmupUrl[] = "http://check.googlezip.net/generate_204"; -const char kAndroidOneIdentifier[] = "sprout"; - const char kQuicFieldTrial[] = "DataReductionProxyUseQuic"; const char kLoFiFieldTrial[] = "DataCompressionProxyLoFi"; -const char kLitePageFallbackFieldTrial[] = - "DataCompressionProxyLitePageFallback"; const char kLoFiFlagFieldTrial[] = "DataCompressionProxyLoFiFlag"; const char kBlackListTransitionFieldTrial[] = @@ -66,7 +60,7 @@ const char kServerExperimentsFieldTrial[] = const char kLitePageBlackListVersion[] = "lite-page-blacklist-version"; bool IsIncludedInFieldTrial(const std::string& name) { - return base::StartsWith(FieldTrialList::FindFullName(name), kEnabled, + return base::StartsWith(base::FieldTrialList::FindFullName(name), kEnabled, base::CompareCase::SENSITIVE); } @@ -82,22 +76,64 @@ std::string GetStringValueForVariationParamWithDefaultValue( return it->second; } +bool IsIncludedInAndroidOnePromoFieldTrial( + base::StringPiece build_fingerprint) { + static const char kAndroidOneIdentifier[] = "sprout"; + return build_fingerprint.find(kAndroidOneIdentifier) != std::string::npos; +} + +bool CanShowAndroidLowMemoryDevicePromo() { +#if defined(OS_ANDROID) + return base::SysInfo::IsLowEndDevice() && + base::FeatureList::IsEnabled( + data_reduction_proxy::features:: + kDataReductionProxyLowMemoryDevicePromo); +#endif + return false; +} + } // namespace namespace data_reduction_proxy { namespace params { bool IsIncludedInPromoFieldTrial() { - return IsIncludedInFieldTrial("DataCompressionProxyPromoVisibility"); + if (IsIncludedInFieldTrial("DataCompressionProxyPromoVisibility")) + return true; + +#if defined(OS_ANDROID) + base::StringPiece android_build_fingerprint = + base::android::BuildInfo::GetInstance()->android_build_fp(); + if (IsIncludedInAndroidOnePromoFieldTrial(android_build_fingerprint)) + return true; +#endif + return CanShowAndroidLowMemoryDevicePromo(); +} + +bool IsIncludedInFREPromoFieldTrial() { + if (IsIncludedInFieldTrial("DataReductionProxyFREPromo")) + return true; + +#if defined(OS_ANDROID) + base::StringPiece android_build_fingerprint = + base::android::BuildInfo::GetInstance()->android_build_fp(); + if (IsIncludedInAndroidOnePromoFieldTrial(android_build_fingerprint)) + return true; +#endif + return CanShowAndroidLowMemoryDevicePromo(); +} + +bool IsIncludedInAndroidOnePromoFieldTrialForTesting( + base::StringPiece build_fingerprint) { + return IsIncludedInAndroidOnePromoFieldTrial(build_fingerprint); } bool IsIncludedInHoldbackFieldTrial() { return IsIncludedInFieldTrial("DataCompressionProxyHoldback"); } -bool IsIncludedInAndroidOnePromoFieldTrial( - base::StringPiece build_fingerprint) { - return build_fingerprint.find(kAndroidOneIdentifier) != std::string::npos; +std::string HoldbackFieldTrialGroup() { + return base::FieldTrialList::FindFullName("DataCompressionProxyHoldback"); } const char* GetTrustedSpdyProxyFieldTrialName() { @@ -105,17 +141,24 @@ const char* GetTrustedSpdyProxyFieldTrialName() { } bool IsIncludedInTrustedSpdyProxyFieldTrial() { - return IsIncludedInFieldTrial(GetTrustedSpdyProxyFieldTrialName()); + if (base::StartsWith(base::FieldTrialList::FindFullName( + GetTrustedSpdyProxyFieldTrialName()), + kControl, base::CompareCase::SENSITIVE)) { + return false; + } + if (base::StartsWith(base::FieldTrialList::FindFullName( + GetTrustedSpdyProxyFieldTrialName()), + kDisabled, base::CompareCase::SENSITIVE)) { + return false; + } + // Trusted SPDY proxy experiment is enabled by default. + return true; } const char* GetLoFiFieldTrialName() { return kLoFiFieldTrial; } -const char* GetLitePageFallbackFieldTrialName() { - return kLitePageFallbackFieldTrial; -} - const char* GetLoFiFlagFieldTrialName() { return kLoFiFlagFieldTrial; } @@ -127,32 +170,29 @@ bool IsIncludedInLoFiEnabledFieldTrial() { bool IsIncludedInLoFiControlFieldTrial() { return !IsLoFiOnViaFlags() && !IsLoFiDisabledViaFlags() && - base::StartsWith(FieldTrialList::FindFullName(GetLoFiFieldTrialName()), - kControl, base::CompareCase::SENSITIVE); + base::StartsWith( + base::FieldTrialList::FindFullName(GetLoFiFieldTrialName()), + kControl, base::CompareCase::SENSITIVE); } bool IsIncludedInLitePageFieldTrial() { return !IsLoFiOnViaFlags() && !IsLoFiDisabledViaFlags() && - base::StartsWith(FieldTrialList::FindFullName(GetLoFiFieldTrialName()), - kLitePage, base::CompareCase::SENSITIVE); -} - -bool IsLitePageFallbackEnabled() { - return IsIncludedInFieldTrial(GetLitePageFallbackFieldTrialName()) || - (IsLoFiOnViaFlags() && AreLitePagesEnabledViaFlags()); + base::StartsWith( + base::FieldTrialList::FindFullName(GetLoFiFieldTrialName()), + kLitePage, base::CompareCase::SENSITIVE); } bool IsIncludedInServerExperimentsFieldTrial() { return !base::CommandLine::ForCurrentProcess()->HasSwitch( data_reduction_proxy::switches:: kDataReductionProxyServerExperimentsDisabled) && - FieldTrialList::FindFullName(kServerExperimentsFieldTrial) + base::FieldTrialList::FindFullName(kServerExperimentsFieldTrial) .find(kDisabled) != 0; } bool IsIncludedInTamperDetectionExperiment() { return IsIncludedInServerExperimentsFieldTrial() && base::StartsWith( - FieldTrialList::FindFullName(kServerExperimentsFieldTrial), + base::FieldTrialList::FindFullName(kServerExperimentsFieldTrial), "TamperDetection_Enabled", base::CompareCase::SENSITIVE); } @@ -160,8 +200,8 @@ bool FetchWarmupURLEnabled() { // Fetching of the warmup URL can be enabled only for Enabled* and Control* // groups. if (!IsIncludedInQuicFieldTrial() && - !base::StartsWith(FieldTrialList::FindFullName(kQuicFieldTrial), kControl, - base::CompareCase::SENSITIVE)) { + !base::StartsWith(base::FieldTrialList::FindFullName(kQuicFieldTrial), + kControl, base::CompareCase::SENSITIVE)) { return false; } @@ -231,12 +271,12 @@ bool WarnIfNoDataReductionProxy() { } bool IsIncludedInQuicFieldTrial() { - if (base::StartsWith(FieldTrialList::FindFullName(kQuicFieldTrial), kControl, - base::CompareCase::SENSITIVE)) { + if (base::StartsWith(base::FieldTrialList::FindFullName(kQuicFieldTrial), + kControl, base::CompareCase::SENSITIVE)) { return false; } - if (base::StartsWith(FieldTrialList::FindFullName(kQuicFieldTrial), kDisabled, - base::CompareCase::SENSITIVE)) { + if (base::StartsWith(base::FieldTrialList::FindFullName(kQuicFieldTrial), + kDisabled, base::CompareCase::SENSITIVE)) { return false; } // QUIC is enabled by default. @@ -408,6 +448,16 @@ const char* GetServerExperimentsFieldTrialName() { return kServerExperimentsFieldTrial; } +GURL GetSecureProxyCheckURL() { + std::string secure_proxy_check_url = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kDataReductionProxySecureProxyCheckURL); + if (secure_proxy_check_url.empty()) + secure_proxy_check_url = kDefaultSecureProxyCheckUrl; + + return GURL(secure_proxy_check_url); +} + } // namespace params DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() : proxy_index(0) {} @@ -417,50 +467,10 @@ DataReductionProxyTypeInfo::DataReductionProxyTypeInfo( DataReductionProxyTypeInfo::~DataReductionProxyTypeInfo() {} -DataReductionProxyParams::DataReductionProxyParams(int flags) - : DataReductionProxyParams(flags, true) {} - -DataReductionProxyParams::~DataReductionProxyParams() {} - -DataReductionProxyParams::DataReductionProxyParams(int flags, - bool should_call_init) - : promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), - holdback_((flags & kHoldback) == kHoldback), - use_override_proxies_for_http_(false) { - if (should_call_init) { - bool result = Init(); - DCHECK(result); - } -} - -void DataReductionProxyParams::SetProxiesForHttpForTesting( - const std::vector<DataReductionProxyServer>& proxies_for_http) { - proxies_for_http_ = proxies_for_http; -} - -bool DataReductionProxyParams::Init() { - InitWithoutChecks(); - // Verify that all necessary params are set. - if (!origin_.is_valid()) { - DVLOG(1) << "Invalid data reduction proxy origin: " << origin_.ToURI(); - return false; - } - - if (!fallback_origin_.is_valid()) { - DVLOG(1) << "Invalid data reduction proxy fallback origin: " - << fallback_origin_.ToURI(); - return false; - } - - if (!secure_proxy_check_url_.is_valid()) { - DVLOG(1) << "Invalid secure proxy check url: <null>"; - return false; - } - return true; -} - -void DataReductionProxyParams::InitWithoutChecks() { - DCHECK(proxies_for_http_.empty()); +DataReductionProxyParams::DataReductionProxyParams() + : use_override_proxies_for_http_(false) { + static const char kDefaultSpdyOrigin[] = "https://proxy.googlezip.net:443"; + static const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; use_override_proxies_for_http_ = params::GetOverrideProxiesForHttpFromCommandLine( @@ -468,39 +478,37 @@ void DataReductionProxyParams::InitWithoutChecks() { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - std::string origin; - origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); + std::string origin = + command_line.GetSwitchValueASCII(switches::kDataReductionProxy); std::string fallback_origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback); - std::string secure_proxy_check_url = command_line.GetSwitchValueASCII( - switches::kDataReductionProxySecureProxyCheckURL); - std::string warmup_url = command_line.GetSwitchValueASCII( - switches::kDataReductionProxyWarmupURL); // Set from preprocessor constants those params that are not specified on the // command line. if (origin.empty()) - origin = GetDefaultOrigin(); + origin = kDefaultSpdyOrigin; if (fallback_origin.empty()) - fallback_origin = GetDefaultFallbackOrigin(); - if (secure_proxy_check_url.empty()) - secure_proxy_check_url = GetDefaultSecureProxyCheckURL(); + fallback_origin = kDefaultFallbackOrigin; - origin_ = net::ProxyServer::FromURI(origin, net::ProxyServer::SCHEME_HTTP); - fallback_origin_ = + net::ProxyServer origin_proxy_server = + net::ProxyServer::FromURI(origin, net::ProxyServer::SCHEME_HTTP); + net::ProxyServer fallback_proxy_server = net::ProxyServer::FromURI(fallback_origin, net::ProxyServer::SCHEME_HTTP); - if (origin_.is_valid()) { - // |origin_| is the core proxy server. + if (origin_proxy_server.is_valid()) { proxies_for_http_.push_back( - DataReductionProxyServer(origin_, ProxyServer::CORE)); + DataReductionProxyServer(origin_proxy_server, ProxyServer::CORE)); } - if (fallback_origin_.is_valid()) { - // |fallback| is also a core proxy server. + if (fallback_proxy_server.is_valid()) { proxies_for_http_.push_back( - DataReductionProxyServer(fallback_origin_, ProxyServer::CORE)); + DataReductionProxyServer(fallback_proxy_server, ProxyServer::CORE)); } +} - secure_proxy_check_url_ = GURL(secure_proxy_check_url); +DataReductionProxyParams::~DataReductionProxyParams() {} + +void DataReductionProxyParams::SetProxiesForHttpForTesting( + const std::vector<DataReductionProxyServer>& proxies_for_http) { + proxies_for_http_ = proxies_for_http; } const std::vector<DataReductionProxyServer>& @@ -510,41 +518,4 @@ DataReductionProxyParams::proxies_for_http() const { return proxies_for_http_; } -// Returns the URL to check to decide if the secure proxy origin should be -// used. -const GURL& DataReductionProxyParams::secure_proxy_check_url() const { - return secure_proxy_check_url_; -} - -// Returns true if the data reduction proxy promo may be shown. -// This is idependent of whether the data reduction proxy is allowed. -// TODO(bengr): maybe tie to whether proxy is allowed. -bool DataReductionProxyParams::promo_allowed() const { - return promo_allowed_; -} - -// Returns true if the data reduction proxy should not actually use the -// proxy if enabled. -bool DataReductionProxyParams::holdback() const { - return holdback_; -} - -// TODO(kundaji): Remove tests for macro definitions. -std::string DataReductionProxyParams::GetDefaultOrigin() const { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kEnableDataReductionProxyCarrierTest)) - return kCarrierTestOrigin; - return kDefaultSpdyOrigin; -} - -std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { - return kDefaultFallbackOrigin; -} - -std::string DataReductionProxyParams::GetDefaultSecureProxyCheckURL() const { - return kDefaultSecureProxyCheckUrl; -} - - } // namespace data_reduction_proxy diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h index badc927146f..96f7ba69c93 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h @@ -11,7 +11,6 @@ #include "base/macros.h" #include "base/strings/string_piece.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h" -#include "net/proxy/proxy_server.h" #include "url/gurl.h" namespace net { @@ -27,10 +26,14 @@ class DataReductionProxyServer; // by field trials and command line switches. namespace params { -// Returns true if this client is part of the field trial that should display +// Returns true if this client is part of a field trial that should display // a promotion for the data reduction proxy. bool IsIncludedInPromoFieldTrial(); +// Returns true if this client is part of a field trial that should display +// a FRE promotion for the data reduction proxy. +bool IsIncludedInFREPromoFieldTrial(); + // Returns true if this client is part of a field trial that runs a holdback // experiment. A holdback experiment is one in which a fraction of browser // instances will not be configured to use the data reduction proxy even if @@ -38,6 +41,10 @@ bool IsIncludedInPromoFieldTrial(); // is in effect. bool IsIncludedInHoldbackFieldTrial(); +// The name of the Holdback experiment group, this can return an empty string if +// not included in a group. +std::string HoldbackFieldTrialGroup(); + // Returns the name of the trusted SPDY/HTTP2 proxy field trial. const char* GetTrustedSpdyProxyFieldTrialName(); @@ -46,15 +53,14 @@ const char* GetTrustedSpdyProxyFieldTrialName(); bool IsIncludedInTrustedSpdyProxyFieldTrial(); // Returns true if this client is part of the field trial that should display -// a promotion for the data reduction proxy on Android One devices. -bool IsIncludedInAndroidOnePromoFieldTrial(base::StringPiece build_fingerprint); +// a promotion for the data reduction proxy on Android One devices. This is for +// testing purposes and should not be called outside of tests. +bool IsIncludedInAndroidOnePromoFieldTrialForTesting( + base::StringPiece build_fingerprint); // Returns the name of the Lo-Fi field trial. const char* GetLoFiFieldTrialName(); -// Returns the name of the Lite Page fallback to Lo-Fi field trial. -const char* GetLitePageFallbackFieldTrialName(); - // Returns the name of the Lo-Fi field trial that configures LoFi flags when it // is force enabled through flags. const char* GetLoFiFlagFieldTrialName(); @@ -71,11 +77,6 @@ bool IsIncludedInLoFiControlFieldTrial(); // trial. bool IsIncludedInLitePageFieldTrial(); -// Returns true if this client is part of the Lite Page fallback to Lo-Fi field -// trial or if this client has the command line switch to enable lite pages, -// which should always fallback. -bool IsLitePageFallbackEnabled(); - // Returns true if this client is part of the field trial that should enable // server experiments for the data reduction proxy. bool IsIncludedInServerExperimentsFieldTrial(); @@ -106,8 +107,7 @@ bool IsLoFiDisabledViaFlags(); // Returns true if this client has the command line switch to enable lite pages. // This means a preview should be requested instead of placeholders whenever -// Lo-Fi mode is on. If Lite Pages are enabled via flags, they will always -// fallback to Lo-Fi placeholders. +// Lo-Fi mode is on. bool AreLitePagesEnabledViaFlags(); // Returns true if this client has the command line switch to enable forced @@ -169,6 +169,10 @@ bool GetOverrideProxiesForHttpFromCommandLine( // Returns the name of the server side experiment field trial. const char* GetServerExperimentsFieldTrialName(); +// Returns the URL to check to decide if the secure proxy origin should be +// used. +GURL GetSecureProxyCheckURL(); + // Returns true if fetching of the warmup URL is enabled. bool FetchWarmupURLEnabled(); @@ -195,17 +199,9 @@ struct DataReductionProxyTypeInfo { // Reduction Proxy. class DataReductionProxyParams : public DataReductionProxyConfigValues { public: - // Flags used during construction that specify if the promotion is allowed to - // be shown, and if this instance is part of a holdback experiment. - static const unsigned int kPromoAllowed = (1 << 2); - static const unsigned int kHoldback = (1 << 3); - - // Constructs configuration parameters. If |kPromoAllowed|, the client may - // show a promotion for the data reduction proxy. - // - // A standard configuration has a primary proxy, and a fallback proxy for - // HTTP traffic. - explicit DataReductionProxyParams(int flags); + // Constructs configuration parameters. A standard configuration has a primary + // proxy, and a fallback proxy for HTTP traffic. + DataReductionProxyParams(); // Updates |proxies_for_http_|. void SetProxiesForHttpForTesting( @@ -216,43 +212,9 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues { const std::vector<DataReductionProxyServer>& proxies_for_http() const override; - const GURL& secure_proxy_check_url() const override; - - bool promo_allowed() const override; - - bool holdback() const override; - - protected: - // Test constructor that optionally won't call Init(); - DataReductionProxyParams(int flags, - bool should_call_init); - - // Initialize the values of the proxies, and secure proxy check URL, from - // command line flags and preprocessor constants, and check that there are - // corresponding definitions for the allowed configurations. - bool Init(); - - // Initialize the values of the proxies, and secure proxy check URL from - // command line flags and preprocessor constants. - void InitWithoutChecks(); - - // Returns the corresponding string from preprocessor constants if defined, - // and an empty string otherwise. - virtual std::string GetDefaultOrigin() const; - virtual std::string GetDefaultFallbackOrigin() const; - virtual std::string GetDefaultSecureProxyCheckURL() const; - private: std::vector<DataReductionProxyServer> proxies_for_http_; - net::ProxyServer origin_; - net::ProxyServer fallback_origin_; - - GURL secure_proxy_check_url_; - - bool promo_allowed_; - bool holdback_; - bool use_override_proxies_for_http_; std::vector<DataReductionProxyServer> override_data_reduction_proxy_servers_; diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc index 3a68f3ab5d1..e79393a9f37 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc @@ -4,79 +4,52 @@ #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" -namespace { -// Test values to replace the values specified in preprocessor defines. -static const char kDefaultOrigin[] = "origin.net:80"; -static const char kDefaultFallbackOrigin[] = "fallback.net:80"; -static const char kDefaultSecureProxyCheckURL[] = "http://proxycheck.net/"; - -static const char kFlagOrigin[] = "https://origin.org:443"; -static const char kFlagFallbackOrigin[] = "fallback.org:80"; -static const char kFlagSecureProxyCheckURL[] = "http://proxycheck.org/"; -} +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h" namespace data_reduction_proxy { -TestDataReductionProxyParams::TestDataReductionProxyParams( - int flags, unsigned int has_definitions) - : DataReductionProxyParams(flags, false), - has_definitions_(has_definitions) { - init_result_ = Init(); - } - -bool TestDataReductionProxyParams::init_result() const { - return init_result_; -} - -void TestDataReductionProxyParams::SetProxiesForHttp( - const std::vector<DataReductionProxyServer>& proxies) { - SetProxiesForHttpForTesting(proxies); -} -// Test values to replace the values specified in preprocessor defines. -std::string TestDataReductionProxyParams::DefaultOrigin() { - return kDefaultOrigin; -} - -std::string TestDataReductionProxyParams::DefaultFallbackOrigin() { - return kDefaultFallbackOrigin; -} - -std::string TestDataReductionProxyParams::DefaultSecureProxyCheckURL() { - return kDefaultSecureProxyCheckURL; -} -std::string TestDataReductionProxyParams::FlagOrigin() { - return kFlagOrigin; -} - -std::string TestDataReductionProxyParams::FlagFallbackOrigin() { - return kFlagFallbackOrigin; -} - -std::string TestDataReductionProxyParams::FlagSecureProxyCheckURL() { - return kFlagSecureProxyCheckURL; -} - -std::string TestDataReductionProxyParams::GetDefaultOrigin() const { - return GetDefinition( - TestDataReductionProxyParams::HAS_ORIGIN, kDefaultOrigin); -} +TestDataReductionProxyParams::TestDataReductionProxyParams() + : DataReductionProxyParams(), override_non_secure_proxies_(false) { + proxies_for_http_.push_back(DataReductionProxyServer( + net::ProxyServer::FromURI("origin.net:80", net::ProxyServer::SCHEME_HTTP), + ProxyServer::CORE)); + proxies_for_http_.push_back(DataReductionProxyServer( + net::ProxyServer::FromURI("fallback.net:80", + net::ProxyServer::SCHEME_HTTP), + ProxyServer::CORE)); + } -std::string TestDataReductionProxyParams::GetDefaultFallbackOrigin() const { - return GetDefinition( - TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, - kDefaultFallbackOrigin); -} + TestDataReductionProxyParams::~TestDataReductionProxyParams() {} + + void TestDataReductionProxyParams::SetProxiesForHttp( + const std::vector<DataReductionProxyServer>& proxies) { + DCHECK_GE(2u, proxies_for_http_.size()); + + size_t secure_proxies = 0; + for (const auto& ps : proxies) + if (ps.proxy_server().is_https()) + secure_proxies++; + DCHECK_GE(1u, secure_proxies); + + SetProxiesForHttpForTesting(proxies); + proxies_for_http_.clear(); + for (const auto& ps : proxies) { + if (override_non_secure_proxies_ && ps.proxy_server().is_https()) { + proxies_for_http_.push_back(DataReductionProxyServer( + net::ProxyServer::FromURI("origin.net:80", + net::ProxyServer::SCHEME_HTTP), + ProxyServer::CORE)); + } else { + proxies_for_http_.push_back(ps); + } + } + } -std::string TestDataReductionProxyParams::GetDefaultSecureProxyCheckURL() - const { - return GetDefinition( - TestDataReductionProxyParams::HAS_SECURE_PROXY_CHECK_URL, - kDefaultSecureProxyCheckURL); + const std::vector<DataReductionProxyServer>& + TestDataReductionProxyParams::proxies_for_http() const { + if (override_non_secure_proxies_) + return proxies_for_http_; + return DataReductionProxyParams::proxies_for_http(); } -std::string TestDataReductionProxyParams::GetDefinition( - unsigned int has_def, - const std::string& definition) const { - return ((has_definitions_ & has_def) ? definition : std::string()); -} } // namespace data_reduction_proxy diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h index f779e291a6d..819063316fc 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h @@ -15,43 +15,24 @@ class DataReductionProxyServer; class TestDataReductionProxyParams : public DataReductionProxyParams { public: - // Used to emulate having constants defined by the preprocessor. - enum HasNames { - HAS_NOTHING = 0x0, - HAS_ORIGIN = 0x2, - HAS_FALLBACK_ORIGIN = 0x4, - HAS_SECURE_PROXY_CHECK_URL = 0x40, - HAS_EVERYTHING = 0xff, - }; - - TestDataReductionProxyParams(int flags, - unsigned int has_definitions); - bool init_result() const; + TestDataReductionProxyParams(); - void SetProxiesForHttp(const std::vector<DataReductionProxyServer>& proxies); - - // Test values to replace the values specified in preprocessor defines. - static std::string DefaultOrigin(); - static std::string DefaultFallbackOrigin(); - static std::string DefaultSecureProxyCheckURL(); - - static std::string FlagOrigin(); - static std::string FlagFallbackOrigin(); - static std::string FlagSecureProxyCheckURL(); + ~TestDataReductionProxyParams() override; - protected: - std::string GetDefaultOrigin() const override; + void SetProxiesForHttp(const std::vector<DataReductionProxyServer>& proxies); - std::string GetDefaultFallbackOrigin() const override; + // Use non-secure data saver proxies. Useful when a URL request is fetched + // from non-SSL mock sockets. + void UseNonSecureProxiesForHttp() { override_non_secure_proxies_ = true; } - std::string GetDefaultSecureProxyCheckURL() const override; + const std::vector<DataReductionProxyServer>& proxies_for_http() + const override; private: - std::string GetDefinition(unsigned int has_def, - const std::string& definition) const; + bool override_non_secure_proxies_; - unsigned int has_definitions_; - bool init_result_; + std::vector<DataReductionProxyServer> proxies_for_http_; }; + } // namespace data_reduction_proxy #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_TEST_UTILS_H_ diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc index 0c983328807..63e8cda5a02 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc @@ -13,6 +13,8 @@ #include "base/command_line.h" #include "base/macros.h" #include "base/metrics/field_trial.h" +#include "base/test/scoped_feature_list.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" @@ -22,19 +24,16 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_ANDROID) +#include "base/sys_info.h" +#endif + namespace data_reduction_proxy { class DataReductionProxyParamsTest : public testing::Test { public: - void CheckParams(const TestDataReductionProxyParams& params, - bool expected_init_result, - bool expected_promo_allowed) { - EXPECT_EQ(expected_init_result, params.init_result()); - EXPECT_EQ(expected_promo_allowed, params.promo_allowed()); - } void CheckValues(const TestDataReductionProxyParams& params, const std::string& expected_origin, - const std::string& expected_fallback_origin, - const std::string& expected_secure_proxy_check_url) { + const std::string& expected_fallback_origin) { std::vector<net::ProxyServer> expected_proxies; if (!expected_origin.empty()) { expected_proxies.push_back(net::ProxyServer::FromURI( @@ -49,101 +48,39 @@ class DataReductionProxyParamsTest : public testing::Test { EXPECT_EQ(expected_proxies, DataReductionProxyServer::ConvertToNetProxyServers( params.proxies_for_http())); - EXPECT_EQ(GURL(expected_secure_proxy_check_url), - params.secure_proxy_check_url()); } }; TEST_F(DataReductionProxyParamsTest, EverythingDefined) { - TestDataReductionProxyParams params( - DataReductionProxyParams::kPromoAllowed, - TestDataReductionProxyParams::HAS_EVERYTHING); - CheckParams(params, true, true); + TestDataReductionProxyParams params; std::vector<DataReductionProxyServer> expected_proxies; // Both the origin and fallback proxy must have type CORE. expected_proxies.push_back(DataReductionProxyServer( - net::ProxyServer::FromURI(TestDataReductionProxyParams::DefaultOrigin(), + net::ProxyServer::FromURI("https://proxy.googlezip.net:443", net::ProxyServer::SCHEME_HTTP), ProxyServer::CORE)); expected_proxies.push_back(DataReductionProxyServer( - net::ProxyServer::FromURI( - TestDataReductionProxyParams::DefaultFallbackOrigin(), - net::ProxyServer::SCHEME_HTTP), + net::ProxyServer::FromURI("compress.googlezip.net:80", + net::ProxyServer::SCHEME_HTTP), ProxyServer::CORE)); EXPECT_EQ(expected_proxies, params.proxies_for_http()); - EXPECT_EQ(GURL(TestDataReductionProxyParams::DefaultSecureProxyCheckURL()), - params.secure_proxy_check_url()); } TEST_F(DataReductionProxyParamsTest, Flags) { base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxy, - TestDataReductionProxyParams::FlagOrigin()); + switches::kDataReductionProxy, "http://ovveride-1.com/"); base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyFallback, - TestDataReductionProxyParams::FlagFallbackOrigin()); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxySecureProxyCheckURL, - TestDataReductionProxyParams::FlagSecureProxyCheckURL()); - TestDataReductionProxyParams params( - DataReductionProxyParams::kPromoAllowed, - TestDataReductionProxyParams::HAS_EVERYTHING); - CheckParams(params, true, true); - CheckValues(params, TestDataReductionProxyParams::FlagOrigin(), - TestDataReductionProxyParams::FlagFallbackOrigin(), - TestDataReductionProxyParams::FlagSecureProxyCheckURL()); -} - -TEST_F(DataReductionProxyParamsTest, CarrierTestFlag) { - static const char kCarrierTestOrigin[] = - "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80"; - static const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; - base::CommandLine::ForCurrentProcess()->InitFromArgv(0, nullptr); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kEnableDataReductionProxyCarrierTest, kCarrierTestOrigin); - DataReductionProxyParams params(0); - std::vector<DataReductionProxyServer> proxies_for_http; - proxies_for_http.push_back(DataReductionProxyServer( - net::ProxyServer::FromURI(kCarrierTestOrigin, - net::ProxyServer::SCHEME_HTTP), - ProxyServer::CORE)); - proxies_for_http.push_back(DataReductionProxyServer( - net::ProxyServer::FromURI(kDefaultFallbackOrigin, - net::ProxyServer::SCHEME_HTTP), - ProxyServer::CORE)); - EXPECT_EQ(params.proxies_for_http(), proxies_for_http); -} - -TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) { - const struct { - bool promo_allowed; - unsigned int missing_definitions; - bool expected_result; - } tests[] = { - {true, TestDataReductionProxyParams::HAS_NOTHING, true}, - {true, TestDataReductionProxyParams::HAS_ORIGIN, false}, - {true, TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, false}, - {true, TestDataReductionProxyParams::HAS_SECURE_PROXY_CHECK_URL, false}, - }; - - for (size_t i = 0; i < arraysize(tests); ++i) { - int flags = 0; - if (tests[i].promo_allowed) - flags |= DataReductionProxyParams::kPromoAllowed; - TestDataReductionProxyParams params( - flags, - TestDataReductionProxyParams::HAS_EVERYTHING & - ~(tests[i].missing_definitions)); - EXPECT_EQ(tests[i].expected_result, params.init_result()) << i; - } + switches::kDataReductionProxyFallback, "http://ovveride-2.com/"); + TestDataReductionProxyParams params; + CheckValues(params, "http://ovveride-1.com/", "http://ovveride-2.com/"); } TEST_F(DataReductionProxyParamsTest, AndroidOnePromoFieldTrial) { - EXPECT_TRUE(params::IsIncludedInAndroidOnePromoFieldTrial( + EXPECT_TRUE(params::IsIncludedInAndroidOnePromoFieldTrialForTesting( "google/sprout/sprout:4.4.4/KPW53/1379542:user/release-keys")); - EXPECT_FALSE(params::IsIncludedInAndroidOnePromoFieldTrial( + EXPECT_FALSE(params::IsIncludedInAndroidOnePromoFieldTrialForTesting( "google/hammerhead/hammerhead:5.0/LRX210/1570415:user/release-keys")); } @@ -403,6 +340,27 @@ TEST_F(DataReductionProxyParamsTest, LoFiPreviewFieldTrial) { } } +TEST_F(DataReductionProxyParamsTest, TrustedSpdyProxyFieldTrial) { + const struct { + std::string trial_group_name; + bool expected_enabled; + } tests[] = { + {"Enabled", true}, {"Enabled_Control", true}, {"Control", false}, + {"Disabled", false}, {"enabled", true}, {"Enabled", true}, + {std::string(), true}, + }; + + for (const auto& test : tests) { + variations::testing::ClearAllVariationParams(); + base::FieldTrialList field_trial_list(nullptr); + base::FieldTrialList::CreateFieldTrial( + params::GetTrustedSpdyProxyFieldTrialName(), test.trial_group_name); + + EXPECT_EQ(test.expected_enabled, + params::IsIncludedInTrustedSpdyProxyFieldTrial()); + } +} + // Tests if the QUIC field trial is set correctly. TEST_F(DataReductionProxyParamsTest, QuicFieldTrial) { const struct { @@ -503,6 +461,7 @@ TEST_F(DataReductionProxyParamsTest, HoldbackEnabledFieldTrial) { ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( "DataCompressionProxyHoldback", test.trial_group_name)); + EXPECT_EQ(test.trial_group_name, params::HoldbackFieldTrialGroup()); EXPECT_EQ(test.expected_enabled, params::IsIncludedInHoldbackFieldTrial()) << test.trial_group_name; } @@ -529,6 +488,56 @@ TEST_F(DataReductionProxyParamsTest, PromoFieldTrial) { } } +TEST_F(DataReductionProxyParamsTest, FREPromoFieldTrial) { + const struct { + std::string trial_group_name; + bool expected_enabled; + } tests[] = { + {"Enabled", true}, + {"Enabled_Control", true}, + {"Disabled", false}, + {"enabled", false}, + }; + + for (const auto& test : tests) { + base::FieldTrialList field_trial_list(nullptr); + + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( + "DataReductionProxyFREPromo", test.trial_group_name)); + EXPECT_EQ(test.expected_enabled, params::IsIncludedInFREPromoFieldTrial()) + << test.trial_group_name; + } +} + +TEST_F(DataReductionProxyParamsTest, LowMemoryPromoFeature) { + const struct { + bool expected_in_field_trial; + } tests[] = { + {false}, {true}, + }; + + for (const auto& test : tests) { + base::test::ScopedFeatureList scoped_feature_list; + if (test.expected_in_field_trial) { + scoped_feature_list.InitAndDisableFeature( + features::kDataReductionProxyLowMemoryDevicePromo); + } else { + scoped_feature_list.InitAndEnableFeature( + features::kDataReductionProxyLowMemoryDevicePromo); + } + +#if defined(OS_ANDROID) + EXPECT_EQ(test.expected_in_field_trial && base::SysInfo::IsLowEndDevice(), + params::IsIncludedInPromoFieldTrial()); + EXPECT_EQ(test.expected_in_field_trial && base::SysInfo::IsLowEndDevice(), + params::IsIncludedInFREPromoFieldTrial()); +#else + EXPECT_FALSE(params::IsIncludedInPromoFieldTrial()); + EXPECT_FALSE(params::IsIncludedInFREPromoFieldTrial()); +#endif + } +} + TEST_F(DataReductionProxyParamsTest, GetConfigServiceURL) { const struct { std::string test_case; @@ -556,11 +565,38 @@ TEST_F(DataReductionProxyParamsTest, GetConfigServiceURL) { } } +TEST_F(DataReductionProxyParamsTest, SecureProxyURL) { + const struct { + std::string test_case; + std::string flag_value; + GURL expected; + } tests[] = { + { + "Nothing set", "", GURL("http://check.googlezip.net/connect"), + }, + { + "Only command line set", "http://example.com/flag", + GURL("http://example.com/flag"), + }, + }; + + for (const auto& test : tests) { + // Reset all flags. + base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); + if (!test.flag_value.empty()) { + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxySecureProxyCheckURL, test.flag_value); + } + EXPECT_EQ(test.expected, params::GetSecureProxyCheckURL()) + << test.test_case; + } +} + TEST(DataReductionProxyParamsStandaloneTest, OverrideProxiesForHttp) { base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kDataReductionProxyHttpProxies, "http://override-first.net;http://override-second.net"); - DataReductionProxyParams params(0); + DataReductionProxyParams params; // Overriding proxies must have type UNSPECIFIED_TYPE. std::vector<DataReductionProxyServer> expected_override_proxies_for_http; diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc index 4877facd493..6145b52f76c 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc @@ -59,10 +59,6 @@ const char kDataReductionProxySecureProxyCheckURL[] = const char kDataReductionProxyServerExperimentsDisabled[] = "data-reduction-proxy-server-experiments-disabled"; -// Sets a URL to fetch to warm up the data reduction proxy on startup and -// network changes. -const char kDataReductionProxyWarmupURL[] = "data-reduction-proxy-warmup-url"; - // Enable the data reduction proxy. const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth"; @@ -70,10 +66,6 @@ const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth"; const char kEnableDataReductionProxyBypassWarning[] = "enable-data-reduction-proxy-bypass-warning"; -// Enables the origin of the carrier test data reduction proxy. -const char kEnableDataReductionProxyCarrierTest[] = - "enable-data-reduction-proxy-carrier-test"; - // Enables lite page from the data reduction proxy. This means a lite page // should be requested instead of placeholders whenever Lo-Fi mode is on. Lo-fi // must also be enabled via a flag or field trial. diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h index 0773ba8d281..7ea15f89fde 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h @@ -26,10 +26,8 @@ extern const char kDataReductionProxyLoFiValueSlowConnectionsOnly[]; extern const char kDataReductionProxySecureProxyCheckURL[]; extern const char kDataReductionProxyServerExperimentsDisabled[]; extern const char kDataReductionProxyServerAlternative[]; -extern const char kDataReductionProxyWarmupURL[]; extern const char kEnableDataReductionProxy[]; extern const char kEnableDataReductionProxyBypassWarning[]; -extern const char kEnableDataReductionProxyCarrierTest[]; extern const char kEnableDataReductionProxyForcePingback[]; extern const char kEnableDataReductionProxyLitePage[]; extern const char kEnableDataReductionProxySavingsPromo[]; diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc index ed6759db08d..8a26cb849b6 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc @@ -9,6 +9,7 @@ #include "base/strings/string_number_conversions.h" #include "base/time/time.h" #include "base/version.h" +#include "components/data_reduction_proxy/core/common/lofi_decider.h" #include "components/data_reduction_proxy/core/common/version.h" #include "net/base/net_errors.h" #include "net/base/url_util.h" @@ -58,6 +59,22 @@ int64_t ScaleByteCountByRatio(int64_t byte_count, return static_cast<int64_t>(scaled_byte_count); } +// Estimate the size of the original headers of |request|. If |used_drp| is +// true, then it's assumed that the original request would have used HTTP/1.1, +// otherwise it assumes that the original request would have used the same +// protocol as |request| did. This is to account for stuff like HTTP/2 header +// compression. +int64_t EstimateOriginalHeaderBytes(const net::URLRequest& request, + bool used_drp) { + if (used_drp) { + // TODO(sclittle): Remove headers added by Data Reduction Proxy when + // computing original size. https://crbug.com/535701. + return request.response_headers()->raw_headers().size(); + } + return std::max<int64_t>(0, request.GetTotalReceivedBytes() - + request.received_response_content_length()); +} + } // namespace namespace util { @@ -187,6 +204,30 @@ int64_t CalculateEffectiveOCL(const net::URLRequest& request) { content_length_from_header); } +int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request, + bool used_drp, + const LoFiDecider* lofi_decider) { + if (request.was_cached() || !request.response_headers()) + return request.GetTotalReceivedBytes(); + + if (lofi_decider) { + if (lofi_decider->IsClientLoFiAutoReloadRequest(request)) + return 0; + + int64_t first, last, length; + if (lofi_decider->IsClientLoFiImageRequest(request) && + request.response_headers()->GetContentRangeFor206(&first, &last, + &length) && + length > request.received_response_content_length()) { + return EstimateOriginalHeaderBytes(request, used_drp) + length; + } + } + + return used_drp ? EstimateOriginalHeaderBytes(request, used_drp) + + util::CalculateEffectiveOCL(request) + : request.GetTotalReceivedBytes(); +} + } // namespace util namespace protobuf_parser { diff --git a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.h b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.h index 811faa9025f..a528060b421 100644 --- a/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.h +++ b/chromium/components/data_reduction_proxy/core/common/data_reduction_proxy_util.h @@ -28,6 +28,8 @@ class URLRequest; namespace data_reduction_proxy { +class LoFiDecider; + enum class Client { UNKNOWN, CRONET_ANDROID, @@ -89,6 +91,13 @@ bool ApplyProxyConfigToProxyInfo(const net::ProxyConfig& proxy_config, // for partial responses if necessary. int64_t CalculateEffectiveOCL(const net::URLRequest& request); +// Given a |request| that went through the Data Reduction Proxy if |used_drp| is +// true, this function estimates how many bytes would have been received if the +// response had been received directly from the origin without any data saver +// optimizations. +int64_t EstimateOriginalReceivedBytes(const net::URLRequest& request, + bool used_drp, + const LoFiDecider* lofi_decider); } // namespace util namespace protobuf_parser { |