Chromium Code Reviews| 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" |
| 11 #include "base/prefs/pref_member.h" | 11 #include "base/prefs/pref_member.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/prefs/proxy_prefs.h" | 18 #include "chrome/browser/prefs/proxy_prefs.h" |
| 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "crypto/random.h" | |
| 25 #include "net/base/auth.h" | |
| 24 #include "net/base/host_port_pair.h" | 26 #include "net/base/host_port_pair.h" |
| 25 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
| 26 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 29 #include "net/http/http_auth.h" | |
| 30 #include "net/http/http_network_session.h" | |
| 27 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_fetcher_delegate.h" | 32 #include "net/url_request/url_fetcher_delegate.h" |
| 29 #include "net/url_request/url_request_status.h" | 33 #include "net/url_request/url_request_status.h" |
| 30 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 31 | 35 |
| 32 using base::FieldTrialList; | 36 using base::FieldTrialList; |
| 33 using base::StringPrintf; | 37 using base::StringPrintf; |
| 34 | 38 |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 37 // Key of the UMA DataReductionProxy.StartupState histogram. | 41 // Key of the UMA DataReductionProxy.StartupState histogram. |
| 38 const char kUMAProxyStartupStateHistogram[] = | 42 const char kUMAProxyStartupStateHistogram[] = |
| 39 "DataReductionProxy.StartupState"; | 43 "DataReductionProxy.StartupState"; |
| 40 // Values of the UMA DataReductionProxy.StartupState histogram. | 44 // Values of the UMA DataReductionProxy.StartupState histogram. |
| 41 enum ProxyStartupState { | 45 enum ProxyStartupState { |
| 42 PROXY_NOT_AVAILABLE = 0, | 46 PROXY_NOT_AVAILABLE = 0, |
| 43 PROXY_DISABLED, | 47 PROXY_DISABLED, |
| 44 PROXY_ENABLED, | 48 PROXY_ENABLED, |
| 45 PROXY_STARTUP_STATE_COUNT, | 49 PROXY_STARTUP_STATE_COUNT, |
| 46 }; | 50 }; |
| 47 | 51 |
| 48 const char kEnabled[] = "Enabled"; | 52 const char kEnabled[] = "Enabled"; |
| 49 | 53 |
| 54 // TODO(marq): factor this string out into a constant here and in | |
| 55 // http_auth_handler_spdyproxy. | |
| 56 const char kAuthenticationRealmName[] = "SpdyProxy"; | |
| 57 | |
| 50 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { | 58 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { |
| 51 int64 val = 0; | 59 int64 val = 0; |
| 52 std::string pref_value; | 60 std::string pref_value; |
| 53 bool rv = list_value.GetString(index, &pref_value); | 61 bool rv = list_value.GetString(index, &pref_value); |
| 54 DCHECK(rv); | 62 DCHECK(rv); |
| 55 if (rv) { | 63 if (rv) { |
| 56 rv = base::StringToInt64(pref_value, &val); | 64 rv = base::StringToInt64(pref_value, &val); |
| 57 DCHECK(rv); | 65 DCHECK(rv); |
| 58 } | 66 } |
| 59 return val; | 67 return val; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 RecordDataReductionInit(); | 108 RecordDataReductionInit(); |
| 101 if (spdy_proxy_auth_enabled_.GetValue() || | 109 if (spdy_proxy_auth_enabled_.GetValue() || |
| 102 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { | 110 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { |
| 103 MaybeActivateDataReductionProxy(true); | 111 MaybeActivateDataReductionProxy(true); |
| 104 } else { | 112 } else { |
| 105 // This is logged so we can use this information in user feedback. | 113 // This is logged so we can use this information in user feedback. |
| 106 LogProxyState(false /* enabled */, true /* at startup */); | 114 LogProxyState(false /* enabled */, true /* at startup */); |
| 107 } | 115 } |
| 108 } | 116 } |
| 109 | 117 |
| 118 void DataReductionProxySettings::InitDataReductionProxySession( | |
| 119 net::HttpNetworkSession* session) { | |
| 120 // This is a no-op unless the authentication params are compiled in. | |
| 121 // (even though values for them may be specified on the command line). | |
| 122 #if defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE) | |
| 123 DCHECK(session); | |
| 124 int64 timestamp = | |
| 125 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000; | |
| 126 | |
| 127 DataReductionProxyList proxies = GetDataReductionProxies(); | |
| 128 for (DataReductionProxyList::iterator it = proxies.begin(); | |
| 129 it != proxies.end(); ++it) { | |
| 130 net::HostPortPair auth_origin = *it; | |
| 131 int32 rand1, rand2, rand3; | |
| 132 crypto::RandBytes(&rand1, sizeof(rand1)); | |
| 133 crypto::RandBytes(&rand2, sizeof(rand2)); | |
| 134 crypto::RandBytes(&rand3, sizeof(rand3)); | |
| 135 | |
| 136 std::string realm = | |
| 137 base::StringPrintf("%s%lld", kAuthenticationRealmName, timestamp); | |
| 138 std::string challenge = base::StringPrintf( | |
| 139 "%s realm=\"%s\", ps=\"%lld-%u-%u-%u\"", | |
| 140 kAuthenticationRealmName, realm.data(), timestamp, rand1, rand2, rand3); | |
| 141 base::string16 password = AuthHashForSalt(timestamp); | |
| 142 | |
| 143 DVLOG(1) << "origin: [" << auth_origin.ToString() << "] realm: [" << realm | |
| 144 << "] challenge: [" << challenge << "] password: [" << password << "]"; | |
| 145 | |
| 146 net::AuthCredentials credentials(base::string16(), password); | |
| 147 session->http_auth_cache()->Add(GURL(auth_origin.ToString()), realm, | |
| 148 net::HttpAuth::AUTH_SCHEME_SPDYPROXY, | |
| 149 challenge, credentials, std::string("/")); | |
| 150 } | |
| 151 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE) | |
| 152 } | |
| 153 | |
| 110 void DataReductionProxySettings::AddHostPatternToBypass( | 154 void DataReductionProxySettings::AddHostPatternToBypass( |
| 111 const std::string& pattern) { | 155 const std::string& pattern) { |
| 112 bypass_rules_.push_back(pattern); | 156 bypass_rules_.push_back(pattern); |
| 113 } | 157 } |
| 114 | 158 |
| 115 void DataReductionProxySettings::AddURLPatternToBypass( | 159 void DataReductionProxySettings::AddURLPatternToBypass( |
| 116 const std::string& pattern) { | 160 const std::string& pattern) { |
| 117 size_t pos = pattern.find("/"); | 161 size_t pos = pattern.find("/"); |
| 118 if (pattern.find("/", pos + 1) == pos + 1) | 162 if (pattern.find("/", pos + 1) == pos + 1) |
| 119 pos = pattern.find("/", pos + 2); | 163 pos = pattern.find("/", pos + 2); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 187 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) | 188 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) |
| 145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); | 189 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); |
| 146 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 190 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 147 return SPDY_PROXY_AUTH_ORIGIN; | 191 return SPDY_PROXY_AUTH_ORIGIN; |
| 148 #else | 192 #else |
| 149 return std::string(); | 193 return std::string(); |
| 150 #endif | 194 #endif |
| 151 } | 195 } |
| 152 | 196 |
| 153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { | 197 std::string DataReductionProxySettings::GetDataReductionProxyFallback() { |
| 154 if (!IsDataReductionProxyAllowed()) | 198 // Regardless of what else is defined, only return a value if the main proxy |
| 199 // origin is defined. | |
| 200 if (GetDataReductionProxyOrigin().empty()) | |
| 155 return std::string(); | 201 return std::string(); |
| 156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 202 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | 203 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback)) |
| 158 // If an origin is provided via a switch, then only consider the value | 204 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback); |
| 159 // that is provided by a switch. Do not use the preprocessor constant. | 205 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
| 160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | 206 return DATA_REDUCTION_FALLBACK_HOST; |
| 161 // line. | |
| 162 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | |
| 163 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); | |
| 164 return std::string(); | |
| 165 } | |
| 166 #if defined(SPDY_PROXY_AUTH_VALUE) | |
| 167 return SPDY_PROXY_AUTH_VALUE; | |
| 168 #else | 207 #else |
| 169 return std::string(); | 208 return std::string(); |
| 170 #endif | 209 #endif |
| 171 } | 210 } |
| 172 | 211 |
| 212 bool DataReductionProxySettings::IsAcceptableAuthChallenge( | |
| 213 net::AuthChallengeInfo* auth_info) { | |
| 214 // Challenge realm must start with the authentication realm name. | |
| 215 if (auth_info->realm.substr(0, strlen(kAuthenticationRealmName)) != | |
| 216 kAuthenticationRealmName) | |
|
bengr
2013/10/22 01:02:09
I'd move from '0, strlen' down to new line. indent
marq (ping after 24h)
2013/10/22 14:44:20
Rewrote for clarity.
| |
| 217 return false; | |
| 218 | |
| 219 // The challenger must be one of the configured proxies. | |
| 220 DataReductionProxyList proxies = GetDataReductionProxies(); | |
| 221 for (DataReductionProxyList::iterator it = proxies.begin(); | |
| 222 it != proxies.end(); ++it) { | |
|
bengr
2013/10/22 01:02:09
indent +1
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
| 223 net::HostPortPair origin_host = *it; | |
| 224 if (origin_host.Equals(auth_info->challenger)) | |
| 225 return true; | |
| 226 } | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( | |
| 231 net::AuthChallengeInfo* auth_info) { | |
| 232 if (auth_info->realm.length() > strlen(kAuthenticationRealmName)) { | |
| 233 int64 salt; | |
| 234 std::string realm_suffix = | |
| 235 auth_info->realm.substr(strlen(kAuthenticationRealmName)); | |
| 236 if (base::StringToInt64(realm_suffix, &salt)) { | |
| 237 return AuthHashForSalt(salt); | |
| 238 } else { | |
| 239 DVLOG(1) << "Unable to parse realm name " << auth_info->realm | |
| 240 << "into an int for salting."; | |
| 241 return base::string16(); | |
| 242 } | |
| 243 } else { | |
| 244 // TODO(marq): Can we just deprecate unsalted auth? If so, remove this. | |
|
bengr
2013/10/22 01:02:09
Yes.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
| 245 #if defined(SPDY_PROXY_AUTH_PROPERTY) | |
| 246 return UTF8ToUTF16(SPDY_PROXY_AUTH_PROPERTY); | |
| 247 #else | |
| 248 return base::string16(); | |
| 249 #endif | |
| 250 } | |
| 251 } | |
| 252 | |
| 173 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { | 253 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { |
| 174 return spdy_proxy_auth_enabled_.GetValue(); | 254 return spdy_proxy_auth_enabled_.GetValue(); |
| 175 } | 255 } |
| 176 | 256 |
| 177 bool DataReductionProxySettings::IsDataReductionProxyManaged() { | 257 bool DataReductionProxySettings::IsDataReductionProxyManaged() { |
| 178 return spdy_proxy_auth_enabled_.IsManaged(); | 258 return spdy_proxy_auth_enabled_.IsManaged(); |
| 179 } | 259 } |
| 180 | 260 |
| 261 DataReductionProxySettings::DataReductionProxyList | |
| 262 DataReductionProxySettings::GetDataReductionProxies() { | |
| 263 DataReductionProxyList proxies; | |
| 264 std::string proxy = GetDataReductionProxyOrigin(); | |
| 265 std::string fallback = GetDataReductionProxyFallback(); | |
| 266 if (!proxy.empty()) | |
| 267 proxies.push_back(net::HostPortPair::FromURL(GURL(proxy))); | |
| 268 if (!fallback.empty()) { | |
| 269 // Sanity check: fallback isn't the only proxy. | |
| 270 DCHECK(!proxies.empty()); | |
| 271 proxies.push_back(net::HostPortPair::FromURL(GURL(fallback))); | |
| 272 } | |
| 273 return proxies; | |
| 274 } | |
| 275 | |
| 181 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { | 276 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { |
| 182 // Prevent configuring the proxy when it is not allowed to be used. | 277 // Prevent configuring the proxy when it is not allowed to be used. |
| 183 if (!IsDataReductionProxyAllowed()) | 278 if (!IsDataReductionProxyAllowed()) |
| 184 return; | 279 return; |
| 185 | 280 |
| 186 spdy_proxy_auth_enabled_.SetValue(enabled); | 281 spdy_proxy_auth_enabled_.SetValue(enabled); |
| 187 OnProxyEnabledPrefChange(); | 282 OnProxyEnabledPrefChange(); |
| 188 } | 283 } |
| 189 | 284 |
| 190 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { | 285 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { |
| 191 PrefService* local_state = GetLocalStatePrefs(); | 286 PrefService* local_state = GetLocalStatePrefs(); |
| 192 int64 last_update_internal = | 287 int64 last_update_internal = |
| 193 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); | 288 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
| 194 base::Time last_update = base::Time::FromInternalValue(last_update_internal); | 289 base::Time last_update = base::Time::FromInternalValue(last_update_internal); |
| 195 return static_cast<int64>(last_update.ToJsTime()); | 290 return static_cast<int64>(last_update.ToJsTime()); |
| 196 } | 291 } |
| 197 | 292 |
| 198 std::vector<long long> | 293 DataReductionProxySettings::ContentLengthList |
| 199 DataReductionProxySettings::GetDailyOriginalContentLengths() { | 294 DataReductionProxySettings::GetDailyOriginalContentLengths() { |
| 200 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); | 295 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); |
| 201 } | 296 } |
| 202 | 297 |
| 203 std::vector<long long> | 298 DataReductionProxySettings::ContentLengthList |
| 204 DataReductionProxySettings::GetDailyReceivedContentLengths() { | 299 DataReductionProxySettings::GetDailyReceivedContentLengths() { |
| 205 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); | 300 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
| 206 } | 301 } |
| 207 | 302 |
| 208 void DataReductionProxySettings::OnURLFetchComplete( | 303 void DataReductionProxySettings::OnURLFetchComplete( |
| 209 const net::URLFetcher* source) { | 304 const net::URLFetcher* source) { |
| 210 net::URLRequestStatus status = source->GetStatus(); | 305 net::URLRequestStatus status = source->GetStatus(); |
| 211 if (status.status() == net::URLRequestStatus::FAILED && | 306 if (status.status() == net::URLRequestStatus::FAILED && |
| 212 status.error() == net::ERR_INTERNET_DISCONNECTED) { | 307 status.error() == net::ERR_INTERNET_DISCONNECTED) { |
| 213 return; | 308 return; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 230 } | 325 } |
| 231 DVLOG(1) << "The data reduction proxy is blocked."; | 326 DVLOG(1) << "The data reduction proxy is blocked."; |
| 232 | 327 |
| 233 if (enabled_by_user_ && !disabled_by_carrier_) { | 328 if (enabled_by_user_ && !disabled_by_carrier_) { |
| 234 // Disable the proxy. | 329 // Disable the proxy. |
| 235 SetProxyConfigs(false, false); | 330 SetProxyConfigs(false, false); |
| 236 } | 331 } |
| 237 disabled_by_carrier_ = true; | 332 disabled_by_carrier_ = true; |
| 238 } | 333 } |
| 239 | 334 |
| 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() { | 335 void DataReductionProxySettings::OnIPAddressChanged() { |
| 252 if (enabled_by_user_) { | 336 if (enabled_by_user_) { |
| 253 DCHECK(IsDataReductionProxyAllowed()); | 337 DCHECK(IsDataReductionProxyAllowed()); |
| 254 ProbeWhetherDataReductionProxyIsAvailable(); | 338 ProbeWhetherDataReductionProxyIsAvailable(); |
| 255 } | 339 } |
| 256 } | 340 } |
| 257 | 341 |
| 258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 342 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
| 259 if (!IsDataReductionProxyAllowed()) | 343 if (!IsDataReductionProxyAllowed()) |
| 260 return; | 344 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 PrefService* prefs = GetOriginalProfilePrefs(); | 401 PrefService* prefs = GetOriginalProfilePrefs(); |
| 318 | 402 |
| 319 // TODO(marq): Consider moving this so stats are wiped the first time the | 403 // TODO(marq): Consider moving this so stats are wiped the first time the |
| 320 // proxy settings are actually (not maybe) turned on. | 404 // proxy settings are actually (not maybe) turned on. |
| 321 if (spdy_proxy_auth_enabled_.GetValue() && | 405 if (spdy_proxy_auth_enabled_.GetValue() && |
| 322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { | 406 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { |
| 323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); | 407 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); |
| 324 ResetDataReductionStatistics(); | 408 ResetDataReductionStatistics(); |
| 325 } | 409 } |
| 326 | 410 |
| 327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); | 411 std::string proxy = GetDataReductionProxyOrigin(); |
| 328 | |
| 329 // Configure use of the data reduction proxy if it is enabled and the proxy | 412 // Configure use of the data reduction proxy if it is enabled and the proxy |
| 330 // origin is non-empty. | 413 // origin is non-empty. |
| 331 enabled_by_user_= | 414 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); | 415 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); |
| 334 | 416 |
| 335 // Check if the proxy has been disabled explicitly by the carrier. | 417 // Check if the proxy has been disabled explicitly by the carrier. |
| 336 if (enabled_by_user_) | 418 if (enabled_by_user_) |
| 337 ProbeWhetherDataReductionProxyIsAvailable(); | 419 ProbeWhetherDataReductionProxyIsAvailable(); |
| 338 } | 420 } |
| 339 | 421 |
| 340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 422 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
| 341 bool at_startup) { | 423 bool at_startup) { |
| 342 LogProxyState(enabled, at_startup); | 424 LogProxyState(enabled, at_startup); |
| 343 PrefService* prefs = GetOriginalProfilePrefs(); | 425 PrefService* prefs = GetOriginalProfilePrefs(); |
| 344 DCHECK(prefs); | 426 DCHECK(prefs); |
| 345 DictionaryPrefUpdate update(prefs, prefs::kProxy); | 427 DictionaryPrefUpdate update(prefs, prefs::kProxy); |
| 346 base::DictionaryValue* dict = update.Get(); | 428 base::DictionaryValue* dict = update.Get(); |
| 347 if (enabled) { | 429 if (enabled) { |
| 430 std::string fallback = GetDataReductionProxyFallback(); | |
| 348 std::string proxy_server_config = | 431 std::string proxy_server_config = |
| 349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; | 432 "http=" + GetDataReductionProxyOrigin() + |
| 433 (fallback.empty() ? "" : "," + fallback) + | |
| 434 ",direct://;"; | |
| 350 dict->SetString("server", proxy_server_config); | 435 dict->SetString("server", proxy_server_config); |
| 351 dict->SetString("mode", | 436 dict->SetString("mode", |
| 352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 437 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
| 353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 438 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
| 354 } else { | 439 } else { |
| 355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 440 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| 356 dict->SetString("server", ""); | 441 dict->SetString("server", ""); |
| 357 dict->SetString("bypass_list", ""); | 442 dict->SetString("bypass_list", ""); |
| 358 } | 443 } |
| 359 } | 444 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 return command_line.GetSwitchValueASCII( | 514 return command_line.GetSwitchValueASCII( |
| 430 switches::kDataReductionProxyProbeURL); | 515 switches::kDataReductionProxyProbeURL); |
| 431 } | 516 } |
| 432 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) | 517 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) |
| 433 return DATA_REDUCTION_PROXY_PROBE_URL; | 518 return DATA_REDUCTION_PROXY_PROBE_URL; |
| 434 #else | 519 #else |
| 435 return std::string(); | 520 return std::string(); |
| 436 #endif | 521 #endif |
| 437 } | 522 } |
| 438 | 523 |
| 524 base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) { | |
| 525 if (!IsDataReductionProxyAllowed()) | |
| 526 return base::string16(); | |
| 527 | |
| 528 std::string key; | |
| 529 | |
| 530 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 531 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | |
| 532 // If an origin is provided via a switch, then only consider the value | |
| 533 // that is provided by a switch. Do not use the preprocessor constant. | |
| 534 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | |
| 535 // line. | |
| 536 if (!command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | |
| 537 return base::string16(); | |
| 538 key = command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); | |
| 539 } else { | |
| 540 #if defined(SPDY_PROXY_AUTH_VALUE) | |
| 541 key = SPDY_PROXY_AUTH_VALUE; | |
| 542 #else | |
| 543 return base::string16; | |
| 544 #endif | |
| 545 } | |
| 546 | |
| 547 DCHECK(!key.empty()); | |
| 548 | |
| 549 std::string salted_key = | |
| 550 base::StringPrintf("%lld%s%lld", salt, key.c_str(), salt); | |
| 551 return UTF8ToUTF16(base::MD5String(salted_key)); | |
| 552 } | |
| 553 | |
| 439 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { | 554 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { |
| 440 std::string url = GetProxyCheckURL(); | 555 std::string url = GetProxyCheckURL(); |
| 441 if (url.empty()) | 556 if (url.empty()) |
| 442 return NULL; | 557 return NULL; |
| 443 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), | 558 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), |
| 444 net::URLFetcher::GET, | 559 net::URLFetcher::GET, |
| 445 this); | 560 this); |
| 446 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 561 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 447 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); | 562 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); |
| 448 Profile* profile = g_browser_process->profile_manager()-> | 563 Profile* profile = g_browser_process->profile_manager()-> |
| 449 GetDefaultProfile(); | 564 GetDefaultProfile(); |
| 450 fetcher->SetRequestContext(profile->GetRequestContext()); | 565 fetcher->SetRequestContext(profile->GetRequestContext()); |
| 451 // Configure max retries to be at most kMaxRetries times for 5xx errors. | 566 // Configure max retries to be at most kMaxRetries times for 5xx errors. |
| 452 static const int kMaxRetries = 5; | 567 static const int kMaxRetries = 5; |
| 453 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 568 fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
| 454 return fetcher; | 569 return fetcher; |
| 455 } | 570 } |
| 456 | 571 |
| 457 void | 572 void |
| 458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 573 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
| 459 net::URLFetcher* fetcher = GetURLFetcher(); | 574 net::URLFetcher* fetcher = GetURLFetcher(); |
| 460 if (!fetcher) | 575 if (!fetcher) |
| 461 return; | 576 return; |
| 462 fetcher_.reset(fetcher); | 577 fetcher_.reset(fetcher); |
| 463 fetcher_->Start(); | 578 fetcher_->Start(); |
| 464 } | 579 } |
| OLD | NEW |