| 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/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 "DataCompressionProxyPromoVisibility") == kEnabled; | 35 "DataCompressionProxyPromoVisibility") == kEnabled; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { | 39 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() { |
| 40 return IsIncludedInFieldTrial() && | 40 return IsIncludedInFieldTrial() && |
| 41 FieldTrialList::FindFullName( | 41 FieldTrialList::FindFullName( |
| 42 "DataCompressionProxyPreconnectHints") == kEnabled; | 42 "DataCompressionProxyPreconnectHints") == kEnabled; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // static | |
| 46 bool DataReductionProxyParams::IsKeySetOnCommandLine() { | |
| 47 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 48 return command_line.HasSwitch( | |
| 49 data_reduction_proxy::switches::kEnableDataReductionProxy); | |
| 50 } | |
| 51 | |
| 52 DataReductionProxyParams::DataReductionProxyParams(int flags) | 45 DataReductionProxyParams::DataReductionProxyParams(int flags) |
| 53 : allowed_((flags & kAllowed) == kAllowed), | 46 : allowed_((flags & kAllowed) == kAllowed), |
| 54 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 47 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
| 55 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 48 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 56 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) { | 49 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
| 50 configured_on_command_line_(false) { |
| 57 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 51 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); |
| 58 DCHECK(result); | 52 DCHECK(result); |
| 59 } | 53 } |
| 60 | 54 |
| 61 DataReductionProxyParams::~DataReductionProxyParams() { | 55 DataReductionProxyParams::~DataReductionProxyParams() { |
| 62 } | 56 } |
| 63 | 57 |
| 64 DataReductionProxyParams::DataReductionProxyList | 58 DataReductionProxyParams::DataReductionProxyList |
| 65 DataReductionProxyParams::GetAllowedProxies() const { | 59 DataReductionProxyParams::GetAllowedProxies() const { |
| 66 DataReductionProxyList list; | 60 DataReductionProxyList list; |
| 67 if (allowed_) | 61 if (allowed_) |
| 68 list.push_back(origin_); | 62 list.push_back(origin_); |
| 69 if (allowed_ && fallback_allowed_) | 63 if (allowed_ && fallback_allowed_) |
| 70 list.push_back(fallback_origin_); | 64 list.push_back(fallback_origin_); |
| 71 if (alt_allowed_) { | 65 if (alt_allowed_) { |
| 72 list.push_back(alt_origin_); | 66 list.push_back(alt_origin_); |
| 73 list.push_back(ssl_origin_); | 67 list.push_back(ssl_origin_); |
| 74 } | 68 } |
| 75 if (alt_allowed_ && fallback_allowed_) | 69 if (alt_allowed_ && fallback_allowed_) |
| 76 list.push_back(alt_fallback_origin_); | 70 list.push_back(alt_fallback_origin_); |
| 77 return list; | 71 return list; |
| 78 } | 72 } |
| 79 | 73 |
| 80 DataReductionProxyParams::DataReductionProxyParams(int flags, | 74 DataReductionProxyParams::DataReductionProxyParams(int flags, |
| 81 bool should_call_init) | 75 bool should_call_init) |
| 82 : allowed_((flags & kAllowed) == kAllowed), | 76 : allowed_((flags & kAllowed) == kAllowed), |
| 83 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), | 77 fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed), |
| 84 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), | 78 alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed), |
| 85 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) { | 79 promo_allowed_((flags & kPromoAllowed) == kPromoAllowed), |
| 80 configured_on_command_line_(false) { |
| 86 if (should_call_init) { | 81 if (should_call_init) { |
| 87 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); | 82 bool result = Init(allowed_, fallback_allowed_, alt_allowed_); |
| 88 DCHECK(result); | 83 DCHECK(result); |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 | 86 |
| 92 bool DataReductionProxyParams::Init( | 87 bool DataReductionProxyParams::Init( |
| 93 bool allowed, bool fallback_allowed, bool alt_allowed) { | 88 bool allowed, bool fallback_allowed, bool alt_allowed) { |
| 94 InitWithoutChecks(); | 89 InitWithoutChecks(); |
| 95 // Verify that all necessary params are set. | 90 // Verify that all necessary params are set. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (origin.empty()) | 157 if (origin.empty()) |
| 163 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); | 158 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy); |
| 164 std::string fallback_origin = | 159 std::string fallback_origin = |
| 165 command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback); | 160 command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback); |
| 166 std::string ssl_origin = | 161 std::string ssl_origin = |
| 167 command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy); | 162 command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy); |
| 168 std::string alt_origin = | 163 std::string alt_origin = |
| 169 command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt); | 164 command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt); |
| 170 std::string alt_fallback_origin = command_line.GetSwitchValueASCII( | 165 std::string alt_fallback_origin = command_line.GetSwitchValueASCII( |
| 171 switches::kDataReductionProxyAltFallback); | 166 switches::kDataReductionProxyAltFallback); |
| 172 key_ = command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | |
| 173 | 167 |
| 174 bool configured_on_command_line = | 168 configured_on_command_line_ = |
| 175 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && | 169 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() && |
| 176 alt_origin.empty() && alt_fallback_origin.empty()); | 170 alt_origin.empty() && alt_fallback_origin.empty()); |
| 177 | 171 |
| 178 | 172 |
| 179 // Configuring the proxy on the command line overrides the values of | 173 // Configuring the proxy on the command line overrides the values of |
| 180 // |allowed_| and |alt_allowed_|. | 174 // |allowed_| and |alt_allowed_|. |
| 181 if (configured_on_command_line) | 175 if (configured_on_command_line_) |
| 182 allowed_ = true; | 176 allowed_ = true; |
| 183 if (!(ssl_origin.empty() && | 177 if (!(ssl_origin.empty() && |
| 184 alt_origin.empty() && | 178 alt_origin.empty() && |
| 185 alt_fallback_origin.empty())) | 179 alt_fallback_origin.empty())) |
| 186 alt_allowed_ = true; | 180 alt_allowed_ = true; |
| 187 | 181 |
| 188 // Only use default key if non of the proxies are configured on the command | |
| 189 // line. | |
| 190 if (key_.empty() && !configured_on_command_line) | |
| 191 key_ = GetDefaultKey(); | |
| 192 | |
| 193 std::string probe_url = command_line.GetSwitchValueASCII( | 182 std::string probe_url = command_line.GetSwitchValueASCII( |
| 194 switches::kDataReductionProxyProbeURL); | 183 switches::kDataReductionProxyProbeURL); |
| 195 std::string warmup_url = command_line.GetSwitchValueASCII( | 184 std::string warmup_url = command_line.GetSwitchValueASCII( |
| 196 switches::kDataReductionProxyWarmupURL); | 185 switches::kDataReductionProxyWarmupURL); |
| 197 | 186 |
| 198 // Set from preprocessor constants those params that are not specified on the | 187 // Set from preprocessor constants those params that are not specified on the |
| 199 // command line. | 188 // command line. |
| 200 if (origin.empty()) | 189 if (origin.empty()) |
| 201 origin = GetDefaultDevOrigin(); | 190 origin = GetDefaultDevOrigin(); |
| 202 if (origin.empty()) | 191 if (origin.empty()) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 if (net::HostPortPair::FromURL(ssl_origin()).Equals(host_port_pair)) { | 259 if (net::HostPortPair::FromURL(ssl_origin()).Equals(host_port_pair)) { |
| 271 if (proxy_servers) { | 260 if (proxy_servers) { |
| 272 (*proxy_servers).first = ssl_origin(); | 261 (*proxy_servers).first = ssl_origin(); |
| 273 (*proxy_servers).second = GURL(); | 262 (*proxy_servers).second = GURL(); |
| 274 } | 263 } |
| 275 return true; | 264 return true; |
| 276 } | 265 } |
| 277 return false; | 266 return false; |
| 278 } | 267 } |
| 279 | 268 |
| 280 std::string DataReductionProxyParams::GetDefaultKey() const { | |
| 281 #if defined(SPDY_PROXY_AUTH_VALUE) | |
| 282 return SPDY_PROXY_AUTH_VALUE; | |
| 283 #endif | |
| 284 return std::string(); | |
| 285 } | |
| 286 | |
| 287 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { | 269 std::string DataReductionProxyParams::GetDefaultDevOrigin() const { |
| 288 #if defined(DATA_REDUCTION_DEV_HOST) | 270 #if defined(DATA_REDUCTION_DEV_HOST) |
| 289 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 271 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 290 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) | 272 if (command_line.HasSwitch(switches::kDisableDataReductionProxyDev)) |
| 291 return std::string(); | 273 return std::string(); |
| 292 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || | 274 if (command_line.HasSwitch(switches::kEnableDataReductionProxyDev) || |
| 293 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == | 275 (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == |
| 294 kEnabled)) { | 276 kEnabled)) { |
| 295 return DATA_REDUCTION_DEV_HOST; | 277 return DATA_REDUCTION_DEV_HOST; |
| 296 } | 278 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 323 } |
| 342 | 324 |
| 343 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 325 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
| 344 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 326 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
| 345 return DATA_REDUCTION_PROXY_WARMUP_URL; | 327 return DATA_REDUCTION_PROXY_WARMUP_URL; |
| 346 #endif | 328 #endif |
| 347 return std::string(); | 329 return std::string(); |
| 348 } | 330 } |
| 349 | 331 |
| 350 } // namespace data_reduction_proxy | 332 } // namespace data_reduction_proxy |
| OLD | NEW |