| OLD | NEW |
| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 "DataCompressionProxyPromoVisibility") == kEnabled; | 38 "DataCompressionProxyPromoVisibility") == kEnabled; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { | 42 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { |
| 43 return IsIncludedInFieldTrial() && | 43 return IsIncludedInFieldTrial() && |
| 44 FieldTrialList::FindFullName( | 44 FieldTrialList::FindFullName( |
| 45 "DataCompressionProxyPreconnectHints") == kEnabled; | 45 "DataCompressionProxyPreconnectHints") == kEnabled; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // static | |
| 49 bool DataReductionProxyParams::IsKeySetOnCommandLine() { | |
| 50 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 51 return command_line.HasSwitch( | |
| 52 data_reduction_proxy::switches::kEnableDataReductionProxy); | |
| 53 } | |
| 54 | |
| 55 DataReductionProxyParams::DataReductionProxyParams(int flags) | 48 DataReductionProxyParams::DataReductionProxyParams(int flags) |
| 56 : allowed_((flags & kAllowed) == kAllowed), | 49 : allowed_((flags & kAllowed) == kAllowed), |
| 57 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 50 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
| 58 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 51 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 59 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) { | 52 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
| 53 configured_on_command_line_(false) { |
| 60 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 54 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); |
| 61 DCHECK(result); | 55 DCHECK(result); |
| 62 } | 56 } |
| 63 | 57 |
| 64 DataReductionProxyParams::~DataReductionProxyParams() { | 58 DataReductionProxyParams::~DataReductionProxyParams() { |
| 65 } | 59 } |
| 66 | 60 |
| 67 DataReductionProxyParams::DataReductionProxyList | 61 DataReductionProxyParams::DataReductionProxyList |
| 68 DataReductionProxyParams::GetAllowedProxies() const { | 62 DataReductionProxyParams::GetAllowedProxies() const { |
| 69 DataReductionProxyList list; | 63 DataReductionProxyList list; |
| 70 if (allowed_) | 64 if (allowed_) |
| 71 list.push_back(origin_); | 65 list.push_back(origin_); |
| 72 if (allowed_ && fallback_allowed_) | 66 if (allowed_ && fallback_allowed_) |
| 73 list.push_back(fallback_origin_); | 67 list.push_back(fallback_origin_); |
| 74 if (alt_allowed_) { | 68 if (alt_allowed_) { |
| 75 list.push_back(alt_origin_); | 69 list.push_back(alt_origin_); |
| 76 list.push_back(ssl_origin_); | 70 list.push_back(ssl_origin_); |
| 77 } | 71 } |
| 78 if (alt_allowed_ && fallback_allowed_) | 72 if (alt_allowed_ && fallback_allowed_) |
| 79 list.push_back(alt_fallback_origin_); | 73 list.push_back(alt_fallback_origin_); |
| 80 return list; | 74 return list; |
| 81 } | 75 } |
| 82 | 76 |
| 83 DataReductionProxyParams::DataReductionProxyParams(int flags, | 77 DataReductionProxyParams::DataReductionProxyParams(int flags, |
| 84 bool should_call_init) | 78 bool should_call_init) |
| 85 : allowed_((flags & kAllowed) == kAllowed), | 79 : allowed_((flags & kAllowed) == kAllowed), |
| 86 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 80 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
| 87 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 81 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 88 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) { | 82 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
| 83 configured_on_command_line_(false) { |
| 89 if (should_call_init) { | 84 if (should_call_init) { |
| 90 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 85 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); |
| 91 DCHECK(result); | 86 DCHECK(result); |
| 92 } | 87 } |
| 93 } | 88 } |
| 94 | 89 |
| 95 bool DataReductionProxyParams::Init( | 90 bool DataReductionProxyParams::Init( |
| 96 bool allowed, bool fallback_allowed, bool alt_allowed) { | 91 bool allowed, bool fallback_allowed, bool alt_allowed) { |
| 97 InitWithoutChecks(); | 92 InitWithoutChecks(); |
| 98 // Verify that all necessary params are set. | 93 // Verify that all necessary params are set. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 if (origin.empty()) | 160 if (origin.empty()) |
| 166 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); | 161 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); |
| 167 std::string fallback_origin = | 162 std::string fallback_origin = |
| 168 command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback); | 163 command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback); |
| 169 std::string ssl_origin = | 164 std::string ssl_origin = |
| 170 command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy); | 165 command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy); |
| 171 std::string alt_origin = | 166 std::string alt_origin = |
| 172 command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt); | 167 command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt); |
| 173 std::string alt_fallback_origin = command_line.GetSwitchValueASCII( | 168 std::string alt_fallback_origin = command_line.GetSwitchValueASCII( |
| 174 switches::kDataReductionProxyAltFallback); | 169 switches::kDataReductionProxyAltFallback); |
| 175 key_ = command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | |
| 176 | 170 |
| 177 bool configured_on_command_line = | 171 configured_on_command_line_ = |
| 178 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && | 172 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && |
| 179 alt_origin.empty() && alt_fallback_origin.empty()); | 173 alt_origin.empty() && alt_fallback_origin.empty()); |
| 180 | 174 |
| 181 | 175 |
| 182 // Configuring the proxy on the command line overrides the values of | 176 // Configuring the proxy on the command line overrides the values of |
| 183 // |allowed_| and |alt_allowed_|. | 177 // |allowed_| and |alt_allowed_|. |
| 184 if (configured_on_command_line) | 178 if (configured_on_command_line_) |
| 185 allowed_ = true; | 179 allowed_ = true; |
| 186 if (!(ssl_origin.empty() && | 180 if (!(ssl_origin.empty() && |
| 187 alt_origin.empty() && | 181 alt_origin.empty() && |
| 188 alt_fallback_origin.empty())) | 182 alt_fallback_origin.empty())) |
| 189 alt_allowed_ = true; | 183 alt_allowed_ = true; |
| 190 | 184 |
| 191 // Only use default key if non of the proxies are configured on the command | |
| 192 // line. | |
| 193 if (key_.empty() && !configured_on_command_line) | |
| 194 key_ = GetDefaultKey(); | |
| 195 | |
| 196 std::string probe_url = command_line.GetSwitchValueASCII( | 185 std::string probe_url = command_line.GetSwitchValueASCII( |
| 197 switches::kDataReductionProxyProbeURL); | 186 switches::kDataReductionProxyProbeURL); |
| 198 std::string warmup_url = command_line.GetSwitchValueASCII( | 187 std::string warmup_url = command_line.GetSwitchValueASCII( |
| 199 switches::kDataReductionProxyWarmupURL); | 188 switches::kDataReductionProxyWarmupURL); |
| 200 | 189 |
| 201 // Set from preprocessor constants those params that are not specified on the | 190 // Set from preprocessor constants those params that are not specified on the |
| 202 // command line. | 191 // command line. |
| 203 if (origin.empty()) | 192 if (origin.empty()) |
| 204 origin = GetDefaultDevOrigin(); | 193 origin = GetDefaultDevOrigin(); |
| 205 if (origin.empty()) | 194 if (origin.empty()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 net::ProxyInfo result; | 279 net::ProxyInfo result; |
| 291 request->context()->proxy_service()->config().proxy_rules().Apply( | 280 request->context()->proxy_service()->config().proxy_rules().Apply( |
| 292 request->url(), &result); | 281 request->url(), &result); |
| 293 if (!result.proxy_server().is_valid()) | 282 if (!result.proxy_server().is_valid()) |
| 294 return false; | 283 return false; |
| 295 if (result.proxy_server().is_direct()) | 284 if (result.proxy_server().is_direct()) |
| 296 return false; | 285 return false; |
| 297 return IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); | 286 return IsDataReductionProxy(result.proxy_server().host_port_pair(), NULL); |
| 298 } | 287 } |
| 299 | 288 |
| 300 std::string DataReductionProxyParams::GetDefaultKey() const { | |
| 301 #if defined(SPDY_PROXY_AUTH_VALUE) | |
| 302 return SPDY_PROXY_AUTH_VALUE; | |
| 303 #endif | |
| 304 return std::string(); | |
| 305 } | |
| 306 | |
| 307 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { | 289 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { |
| 308 #if defined(DATA_REDUCTION_DEV_HOST) | 290 #if defined(DATA_REDUCTION_DEV_HOST) |
| 309 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 291 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 310 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) | 292 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) |
| 311 return std::string(); | 293 return std::string(); |
| 312 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 294 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
| 313 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 295 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
| 314 kEnabled)) { | 296 kEnabled)) { |
| 315 return DATA_REDUCTION_DEV_HOST; | 297 return DATA_REDUCTION_DEV_HOST; |
| 316 } | 298 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 343 } |
| 362 | 344 |
| 363 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 345 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
| 364 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 346 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
| 365 return DATA_REDUCTION_PROXY_WARMUP_URL; | 347 return DATA_REDUCTION_PROXY_WARMUP_URL; |
| 366 #endif | 348 #endif |
| 367 return std::string(); | 349 return std::string(); |
| 368 } | 350 } |
| 369 | 351 |
| 370 } // namespace data_reduction_proxy | 352 } // namespace data_reduction_proxy |
| OLD | NEW |