| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) | 144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) |
| 145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); | 145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); |
| 146 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 146 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 147 return SPDY_PROXY_AUTH_ORIGIN; | 147 return SPDY_PROXY_AUTH_ORIGIN; |
| 148 #else | 148 #else |
| 149 return std::string(); | 149 return std::string(); |
| 150 #endif | 150 #endif |
| 151 } | 151 } |
| 152 | 152 |
| 153 std::string DataReductionProxySettings::GetDataReductionProxyFallback() { |
| 154 // Regardless of what else is defined, only return a value if the main proxy |
| 155 // origin is defined. |
| 156 if (GetDataReductionProxyOrigin().empty()) |
| 157 return std::string(); |
| 158 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 159 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback)) |
| 160 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback); |
| 161 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
| 162 return DATA_REDUCTION_FALLBACK_HOST; |
| 163 #else |
| 164 return std::string(); |
| 165 #endif |
| 166 } |
| 167 |
| 153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { | 168 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { |
| 154 if (!IsDataReductionProxyAllowed()) | 169 if (!IsDataReductionProxyAllowed()) |
| 155 return std::string(); | 170 return std::string(); |
| 156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 171 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | 172 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { |
| 158 // If an origin is provided via a switch, then only consider the value | 173 // If an origin is provided via a switch, then only consider the value |
| 159 // that is provided by a switch. Do not use the preprocessor constant. | 174 // that is provided by a switch. Do not use the preprocessor constant. |
| 160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | 175 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command |
| 161 // line. | 176 // line. |
| 162 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | 177 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 245 } |
| 231 DVLOG(1) << "The data reduction proxy is blocked."; | 246 DVLOG(1) << "The data reduction proxy is blocked."; |
| 232 | 247 |
| 233 if (enabled_by_user_ && !disabled_by_carrier_) { | 248 if (enabled_by_user_ && !disabled_by_carrier_) { |
| 234 // Disable the proxy. | 249 // Disable the proxy. |
| 235 SetProxyConfigs(false, false); | 250 SetProxyConfigs(false, false); |
| 236 } | 251 } |
| 237 disabled_by_carrier_ = true; | 252 disabled_by_carrier_ = true; |
| 238 } | 253 } |
| 239 | 254 |
| 240 std::string DataReductionProxySettings::GetDataReductionProxyOriginHostPort() { | |
| 241 std::string spdy_proxy = GetDataReductionProxyOrigin(); | |
| 242 if (spdy_proxy.empty()) { | |
| 243 DLOG(ERROR) << "A SPDY proxy has not been set."; | |
| 244 return spdy_proxy; | |
| 245 } | |
| 246 // Remove a trailing slash from the proxy string if one exists as well as | |
| 247 // leading HTTPS scheme. | |
| 248 return net::HostPortPair::FromURL(GURL(spdy_proxy)).ToString(); | |
| 249 } | |
| 250 | |
| 251 void DataReductionProxySettings::OnIPAddressChanged() { | 255 void DataReductionProxySettings::OnIPAddressChanged() { |
| 252 if (enabled_by_user_) { | 256 if (enabled_by_user_) { |
| 253 DCHECK(IsDataReductionProxyAllowed()); | 257 DCHECK(IsDataReductionProxyAllowed()); |
| 254 ProbeWhetherDataReductionProxyIsAvailable(); | 258 ProbeWhetherDataReductionProxyIsAvailable(); |
| 255 } | 259 } |
| 256 } | 260 } |
| 257 | 261 |
| 258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 262 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
| 259 if (!IsDataReductionProxyAllowed()) | 263 if (!IsDataReductionProxyAllowed()) |
| 260 return; | 264 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 PrefService* prefs = GetOriginalProfilePrefs(); | 321 PrefService* prefs = GetOriginalProfilePrefs(); |
| 318 | 322 |
| 319 // TODO(marq): Consider moving this so stats are wiped the first time the | 323 // TODO(marq): Consider moving this so stats are wiped the first time the |
| 320 // proxy settings are actually (not maybe) turned on. | 324 // proxy settings are actually (not maybe) turned on. |
| 321 if (spdy_proxy_auth_enabled_.GetValue() && | 325 if (spdy_proxy_auth_enabled_.GetValue() && |
| 322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { | 326 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { |
| 323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); | 327 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); |
| 324 ResetDataReductionStatistics(); | 328 ResetDataReductionStatistics(); |
| 325 } | 329 } |
| 326 | 330 |
| 327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); | 331 std::string proxy = GetDataReductionProxyOrigin(); |
| 328 | |
| 329 // Configure use of the data reduction proxy if it is enabled and the proxy | 332 // Configure use of the data reduction proxy if it is enabled and the proxy |
| 330 // origin is non-empty. | 333 // origin is non-empty. |
| 331 enabled_by_user_= | 334 enabled_by_user_= spdy_proxy_auth_enabled_.GetValue() && !proxy.empty(); |
| 332 spdy_proxy_auth_enabled_.GetValue() && !spdy_proxy_origin.empty(); | |
| 333 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); | 335 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); |
| 334 | 336 |
| 335 // Check if the proxy has been disabled explicitly by the carrier. | 337 // Check if the proxy has been disabled explicitly by the carrier. |
| 336 if (enabled_by_user_) | 338 if (enabled_by_user_) |
| 337 ProbeWhetherDataReductionProxyIsAvailable(); | 339 ProbeWhetherDataReductionProxyIsAvailable(); |
| 338 } | 340 } |
| 339 | 341 |
| 340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 342 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
| 341 bool at_startup) { | 343 bool at_startup) { |
| 342 LogProxyState(enabled, at_startup); | 344 LogProxyState(enabled, at_startup); |
| 343 PrefService* prefs = GetOriginalProfilePrefs(); | 345 PrefService* prefs = GetOriginalProfilePrefs(); |
| 344 DCHECK(prefs); | 346 DCHECK(prefs); |
| 345 DictionaryPrefUpdate update(prefs, prefs::kProxy); | 347 DictionaryPrefUpdate update(prefs, prefs::kProxy); |
| 346 base::DictionaryValue* dict = update.Get(); | 348 base::DictionaryValue* dict = update.Get(); |
| 347 if (enabled) { | 349 if (enabled) { |
| 350 std::string fallback = GetDataReductionProxyFallback(); |
| 348 std::string proxy_server_config = | 351 std::string proxy_server_config = |
| 349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; | 352 "http=" + GetDataReductionProxyOrigin() + |
| 353 (fallback.empty() ? "" : "," + fallback) + |
| 354 ",direct://;"; |
| 350 dict->SetString("server", proxy_server_config); | 355 dict->SetString("server", proxy_server_config); |
| 351 dict->SetString("mode", | 356 dict->SetString("mode", |
| 352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 357 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
| 353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 358 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
| 354 } else { | 359 } else { |
| 355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 360 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| 356 dict->SetString("server", ""); | 361 dict->SetString("server", ""); |
| 357 dict->SetString("bypass_list", ""); | 362 dict->SetString("bypass_list", ""); |
| 358 } | 363 } |
| 359 } | 364 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 460 } |
| 456 | 461 |
| 457 void | 462 void |
| 458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 463 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
| 459 net::URLFetcher* fetcher = GetURLFetcher(); | 464 net::URLFetcher* fetcher = GetURLFetcher(); |
| 460 if (!fetcher) | 465 if (!fetcher) |
| 461 return; | 466 return; |
| 462 fetcher_.reset(fetcher); | 467 fetcher_.reset(fetcher); |
| 463 fetcher_->Start(); | 468 fetcher_->Start(); |
| 464 } | 469 } |
| OLD | NEW |