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_auth_cache.h" |
| 31 #include "net/http/http_network_session.h" |
27 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
28 #include "net/url_request/url_fetcher_delegate.h" | 33 #include "net/url_request/url_fetcher_delegate.h" |
29 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
30 #include "url/gurl.h" | 35 #include "url/gurl.h" |
31 | 36 |
32 using base::FieldTrialList; | 37 using base::FieldTrialList; |
33 using base::StringPrintf; | 38 using base::StringPrintf; |
34 | 39 |
35 namespace { | 40 namespace { |
36 | 41 |
37 // Key of the UMA DataReductionProxy.StartupState histogram. | 42 // Key of the UMA DataReductionProxy.StartupState histogram. |
38 const char kUMAProxyStartupStateHistogram[] = | 43 const char kUMAProxyStartupStateHistogram[] = |
39 "DataReductionProxy.StartupState"; | 44 "DataReductionProxy.StartupState"; |
40 // Values of the UMA DataReductionProxy.StartupState histogram. | 45 // Values of the UMA DataReductionProxy.StartupState histogram. |
41 enum ProxyStartupState { | 46 enum ProxyStartupState { |
42 PROXY_NOT_AVAILABLE = 0, | 47 PROXY_NOT_AVAILABLE = 0, |
43 PROXY_DISABLED, | 48 PROXY_DISABLED, |
44 PROXY_ENABLED, | 49 PROXY_ENABLED, |
45 PROXY_STARTUP_STATE_COUNT, | 50 PROXY_STARTUP_STATE_COUNT, |
46 }; | 51 }; |
47 | 52 |
48 const char kEnabled[] = "Enabled"; | 53 const char kEnabled[] = "Enabled"; |
49 | 54 |
| 55 // TODO(marq): Factor this string out into a constant here and in |
| 56 // http_auth_handler_spdyproxy. |
| 57 const char kAuthenticationRealmName[] = "SpdyProxy"; |
| 58 |
50 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { | 59 int64 GetInt64PrefValue(const ListValue& list_value, size_t index) { |
51 int64 val = 0; | 60 int64 val = 0; |
52 std::string pref_value; | 61 std::string pref_value; |
53 bool rv = list_value.GetString(index, &pref_value); | 62 bool rv = list_value.GetString(index, &pref_value); |
54 DCHECK(rv); | 63 DCHECK(rv); |
55 if (rv) { | 64 if (rv) { |
56 rv = base::StringToInt64(pref_value, &val); | 65 rv = base::StringToInt64(pref_value, &val); |
57 DCHECK(rv); | 66 DCHECK(rv); |
58 } | 67 } |
59 return val; | 68 return val; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 RecordDataReductionInit(); | 109 RecordDataReductionInit(); |
101 if (spdy_proxy_auth_enabled_.GetValue() || | 110 if (spdy_proxy_auth_enabled_.GetValue() || |
102 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { | 111 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { |
103 MaybeActivateDataReductionProxy(true); | 112 MaybeActivateDataReductionProxy(true); |
104 } else { | 113 } else { |
105 // This is logged so we can use this information in user feedback. | 114 // This is logged so we can use this information in user feedback. |
106 LogProxyState(false /* enabled */, true /* at startup */); | 115 LogProxyState(false /* enabled */, true /* at startup */); |
107 } | 116 } |
108 } | 117 } |
109 | 118 |
| 119 void DataReductionProxySettings::InitDataReductionProxySession( |
| 120 net::HttpNetworkSession* session) { |
| 121 // This is a no-op unless the authentication parameters are compiled in. |
| 122 // (even though values for them may be specified on the command line). |
| 123 // Authentication will still work if the command line parameters are used, |
| 124 // however there will be a round-trip overhead for each challenge/response |
| 125 // (typically once per session). |
| 126 #if defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE) |
| 127 DCHECK(session); |
| 128 net::HttpAuthCache* auth_cache = session->http_auth_cache(); |
| 129 DCHECK(auth_cache); |
| 130 InitDataReductionAuthentication(auth_cache); |
| 131 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE) |
| 132 } |
| 133 |
| 134 void DataReductionProxySettings::InitDataReductionAuthentication( |
| 135 net::HttpAuthCache* auth_cache) { |
| 136 DCHECK(auth_cache); |
| 137 int64 timestamp = |
| 138 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000; |
| 139 |
| 140 DataReductionProxyList proxies = GetDataReductionProxies(); |
| 141 for (DataReductionProxyList::iterator it = proxies.begin(); |
| 142 it != proxies.end(); ++it) { |
| 143 GURL auth_origin = (*it).GetOrigin(); |
| 144 int32 rand1, rand2, rand3; |
| 145 crypto::RandBytes(&rand1, sizeof(rand1)); |
| 146 crypto::RandBytes(&rand2, sizeof(rand2)); |
| 147 crypto::RandBytes(&rand3, sizeof(rand3)); |
| 148 |
| 149 std::string realm = |
| 150 base::StringPrintf("%s%lld", kAuthenticationRealmName, timestamp); |
| 151 std::string challenge = base::StringPrintf( |
| 152 "%s realm=\"%s\", ps=\"%lld-%u-%u-%u\"", |
| 153 kAuthenticationRealmName, realm.data(), timestamp, rand1, rand2, rand3); |
| 154 base::string16 password = AuthHashForSalt(timestamp); |
| 155 |
| 156 DVLOG(1) << "origin: [" << auth_origin << "] realm: [" << realm |
| 157 << "] challenge: [" << challenge << "] password: [" << password << "]"; |
| 158 |
| 159 net::AuthCredentials credentials(base::string16(), password); |
| 160 auth_cache->Add(auth_origin, |
| 161 realm, |
| 162 net::HttpAuth::AUTH_SCHEME_SPDYPROXY, |
| 163 challenge, |
| 164 credentials, |
| 165 std::string()); // Proxy auth uses an empty path for lookup. |
| 166 } |
| 167 } |
| 168 |
110 void DataReductionProxySettings::AddHostPatternToBypass( | 169 void DataReductionProxySettings::AddHostPatternToBypass( |
111 const std::string& pattern) { | 170 const std::string& pattern) { |
112 bypass_rules_.push_back(pattern); | 171 bypass_rules_.push_back(pattern); |
113 } | 172 } |
114 | 173 |
115 void DataReductionProxySettings::AddURLPatternToBypass( | 174 void DataReductionProxySettings::AddURLPatternToBypass( |
116 const std::string& pattern) { | 175 const std::string& pattern) { |
117 size_t pos = pattern.find("/"); | 176 size_t pos = pattern.find("/"); |
118 if (pattern.find("/", pos + 1) == pos + 1) | 177 if (pattern.find("/", pos + 1) == pos + 1) |
119 pos = pattern.find("/", pos + 2); | 178 pos = pattern.find("/", pos + 2); |
(...skipping 16 matching lines...) Expand all Loading... |
136 return IsProxyOriginSetOnCommandLine() || | 195 return IsProxyOriginSetOnCommandLine() || |
137 (IsDataReductionProxyAllowed() && | 196 (IsDataReductionProxyAllowed() && |
138 FieldTrialList::FindFullName("DataCompressionProxyPromoVisibility") == | 197 FieldTrialList::FindFullName("DataCompressionProxyPromoVisibility") == |
139 kEnabled); | 198 kEnabled); |
140 } | 199 } |
141 | 200 |
142 std::string DataReductionProxySettings::GetDataReductionProxyOrigin() { | 201 std::string DataReductionProxySettings::GetDataReductionProxyOrigin() { |
143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 202 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) | 203 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) |
145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); | 204 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); |
146 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 205 return GetDefaultProxyHost(); |
147 return SPDY_PROXY_AUTH_ORIGIN; | |
148 #else | |
149 return std::string(); | |
150 #endif | |
151 } | 206 } |
152 | 207 |
153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { | 208 std::string DataReductionProxySettings::GetDataReductionProxyFallback() { |
154 if (!IsDataReductionProxyAllowed()) | 209 // Regardless of what else is defined, only return a value if the main proxy |
| 210 // origin is defined. |
| 211 if (GetDataReductionProxyOrigin().empty()) |
155 return std::string(); | 212 return std::string(); |
156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 213 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | 214 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback)) |
158 // If an origin is provided via a switch, then only consider the value | 215 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback); |
159 // that is provided by a switch. Do not use the preprocessor constant. | 216 return GetDefaultFallbackProxyHost(); |
160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | 217 } |
161 // line. | 218 |
162 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | 219 bool DataReductionProxySettings::IsAcceptableAuthChallenge( |
163 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); | 220 net::AuthChallengeInfo* auth_info) { |
164 return std::string(); | 221 // Challenge realm must start with the authentication realm name. |
| 222 std::string realm_prefix = |
| 223 auth_info->realm.substr(0, strlen(kAuthenticationRealmName)); |
| 224 if (realm_prefix != kAuthenticationRealmName) |
| 225 return false; |
| 226 |
| 227 // The challenger must be one of the configured proxies. |
| 228 DataReductionProxyList proxies = GetDataReductionProxies(); |
| 229 for (DataReductionProxyList::iterator it = proxies.begin(); |
| 230 it != proxies.end(); ++it) { |
| 231 net::HostPortPair origin_host = net::HostPortPair::FromURL(*it); |
| 232 if (origin_host.Equals(auth_info->challenger)) |
| 233 return true; |
165 } | 234 } |
166 #if defined(SPDY_PROXY_AUTH_VALUE) | 235 return false; |
167 return SPDY_PROXY_AUTH_VALUE; | 236 } |
168 #else | 237 |
169 return std::string(); | 238 base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( |
170 #endif | 239 net::AuthChallengeInfo* auth_info) { |
| 240 if (auth_info->realm.length() > strlen(kAuthenticationRealmName)) { |
| 241 int64 salt; |
| 242 std::string realm_suffix = |
| 243 auth_info->realm.substr(strlen(kAuthenticationRealmName)); |
| 244 if (base::StringToInt64(realm_suffix, &salt)) { |
| 245 return AuthHashForSalt(salt); |
| 246 } else { |
| 247 DVLOG(1) << "Unable to parse realm name " << auth_info->realm |
| 248 << "into an int for salting."; |
| 249 return base::string16(); |
| 250 } |
| 251 } else { |
| 252 return base::string16(); |
| 253 } |
171 } | 254 } |
172 | 255 |
173 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { | 256 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { |
174 return spdy_proxy_auth_enabled_.GetValue(); | 257 return spdy_proxy_auth_enabled_.GetValue(); |
175 } | 258 } |
176 | 259 |
177 bool DataReductionProxySettings::IsDataReductionProxyManaged() { | 260 bool DataReductionProxySettings::IsDataReductionProxyManaged() { |
178 return spdy_proxy_auth_enabled_.IsManaged(); | 261 return spdy_proxy_auth_enabled_.IsManaged(); |
179 } | 262 } |
180 | 263 |
| 264 DataReductionProxySettings::DataReductionProxyList |
| 265 DataReductionProxySettings::GetDataReductionProxies() { |
| 266 DataReductionProxyList proxies; |
| 267 std::string proxy = GetDataReductionProxyOrigin(); |
| 268 std::string fallback = GetDataReductionProxyFallback(); |
| 269 |
| 270 if (!proxy.empty()) |
| 271 proxies.push_back(GURL(proxy)); |
| 272 |
| 273 if (!fallback.empty()) { |
| 274 // Sanity check: fallback isn't the only proxy. |
| 275 DCHECK(!proxies.empty()); |
| 276 proxies.push_back(GURL(fallback)); |
| 277 } |
| 278 |
| 279 return proxies; |
| 280 } |
| 281 |
181 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { | 282 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { |
182 // Prevent configuring the proxy when it is not allowed to be used. | 283 // Prevent configuring the proxy when it is not allowed to be used. |
183 if (!IsDataReductionProxyAllowed()) | 284 if (!IsDataReductionProxyAllowed()) |
184 return; | 285 return; |
185 | 286 |
186 spdy_proxy_auth_enabled_.SetValue(enabled); | 287 spdy_proxy_auth_enabled_.SetValue(enabled); |
187 OnProxyEnabledPrefChange(); | 288 OnProxyEnabledPrefChange(); |
188 } | 289 } |
189 | 290 |
190 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { | 291 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { |
191 PrefService* local_state = GetLocalStatePrefs(); | 292 PrefService* local_state = GetLocalStatePrefs(); |
192 int64 last_update_internal = | 293 int64 last_update_internal = |
193 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); | 294 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
194 base::Time last_update = base::Time::FromInternalValue(last_update_internal); | 295 base::Time last_update = base::Time::FromInternalValue(last_update_internal); |
195 return static_cast<int64>(last_update.ToJsTime()); | 296 return static_cast<int64>(last_update.ToJsTime()); |
196 } | 297 } |
197 | 298 |
198 std::vector<long long> | 299 DataReductionProxySettings::ContentLengthList |
199 DataReductionProxySettings::GetDailyOriginalContentLengths() { | 300 DataReductionProxySettings::GetDailyOriginalContentLengths() { |
200 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); | 301 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); |
201 } | 302 } |
202 | 303 |
203 std::vector<long long> | 304 DataReductionProxySettings::ContentLengthList |
204 DataReductionProxySettings::GetDailyReceivedContentLengths() { | 305 DataReductionProxySettings::GetDailyReceivedContentLengths() { |
205 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); | 306 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
206 } | 307 } |
207 | 308 |
208 void DataReductionProxySettings::OnURLFetchComplete( | 309 void DataReductionProxySettings::OnURLFetchComplete( |
209 const net::URLFetcher* source) { | 310 const net::URLFetcher* source) { |
210 net::URLRequestStatus status = source->GetStatus(); | 311 net::URLRequestStatus status = source->GetStatus(); |
211 if (status.status() == net::URLRequestStatus::FAILED && | 312 if (status.status() == net::URLRequestStatus::FAILED && |
212 status.error() == net::ERR_INTERNET_DISCONNECTED) { | 313 status.error() == net::ERR_INTERNET_DISCONNECTED) { |
213 return; | 314 return; |
(...skipping 16 matching lines...) Expand all Loading... |
230 } | 331 } |
231 DVLOG(1) << "The data reduction proxy is blocked."; | 332 DVLOG(1) << "The data reduction proxy is blocked."; |
232 | 333 |
233 if (enabled_by_user_ && !disabled_by_carrier_) { | 334 if (enabled_by_user_ && !disabled_by_carrier_) { |
234 // Disable the proxy. | 335 // Disable the proxy. |
235 SetProxyConfigs(false, false); | 336 SetProxyConfigs(false, false); |
236 } | 337 } |
237 disabled_by_carrier_ = true; | 338 disabled_by_carrier_ = true; |
238 } | 339 } |
239 | 340 |
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() { | 341 void DataReductionProxySettings::OnIPAddressChanged() { |
252 if (enabled_by_user_) { | 342 if (enabled_by_user_) { |
253 DCHECK(IsDataReductionProxyAllowed()); | 343 DCHECK(IsDataReductionProxyAllowed()); |
254 ProbeWhetherDataReductionProxyIsAvailable(); | 344 ProbeWhetherDataReductionProxyIsAvailable(); |
255 } | 345 } |
256 } | 346 } |
257 | 347 |
258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 348 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
259 if (!IsDataReductionProxyAllowed()) | 349 if (!IsDataReductionProxyAllowed()) |
260 return; | 350 return; |
(...skipping 16 matching lines...) Expand all Loading... |
277 // feedback. | 367 // feedback. |
278 const char kAtStartup[] = "at startup"; | 368 const char kAtStartup[] = "at startup"; |
279 const char kByUser[] = "by user action"; | 369 const char kByUser[] = "by user action"; |
280 const char kOn[] = "ON"; | 370 const char kOn[] = "ON"; |
281 const char kOff[] = "OFF"; | 371 const char kOff[] = "OFF"; |
282 | 372 |
283 LOG(WARNING) << "SPDY proxy " << (enabled ? kOn : kOff) | 373 LOG(WARNING) << "SPDY proxy " << (enabled ? kOn : kOff) |
284 << " " << (at_startup ? kAtStartup : kByUser); | 374 << " " << (at_startup ? kAtStartup : kByUser); |
285 } | 375 } |
286 | 376 |
| 377 std::string DataReductionProxySettings::GetDefaultProxyHost() { |
| 378 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 379 return SPDY_PROXY_AUTH_ORIGIN; |
| 380 #else |
| 381 return std::string(); |
| 382 #endif |
| 383 } |
| 384 |
| 385 std::string DataReductionProxySettings::GetDefaultFallbackProxyHost() { |
| 386 #if defined(DATA_REDUCTION_FALLBACK_HOST) |
| 387 return DATA_REDUCTION_FALLBACK_HOST; |
| 388 #else |
| 389 return std::string(); |
| 390 #endif |
| 391 } |
| 392 |
287 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { | 393 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { |
288 return g_browser_process->profile_manager()->GetLastUsedProfile()-> | 394 return g_browser_process->profile_manager()->GetLastUsedProfile()-> |
289 GetOriginalProfile()->GetPrefs(); | 395 GetOriginalProfile()->GetPrefs(); |
290 } | 396 } |
291 | 397 |
292 PrefService* DataReductionProxySettings::GetLocalStatePrefs() { | 398 PrefService* DataReductionProxySettings::GetLocalStatePrefs() { |
293 return g_browser_process->local_state(); | 399 return g_browser_process->local_state(); |
294 } | 400 } |
295 | 401 |
296 bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() { | 402 bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() { |
(...skipping 20 matching lines...) Expand all Loading... |
317 PrefService* prefs = GetOriginalProfilePrefs(); | 423 PrefService* prefs = GetOriginalProfilePrefs(); |
318 | 424 |
319 // TODO(marq): Consider moving this so stats are wiped the first time the | 425 // TODO(marq): Consider moving this so stats are wiped the first time the |
320 // proxy settings are actually (not maybe) turned on. | 426 // proxy settings are actually (not maybe) turned on. |
321 if (spdy_proxy_auth_enabled_.GetValue() && | 427 if (spdy_proxy_auth_enabled_.GetValue() && |
322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { | 428 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { |
323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); | 429 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); |
324 ResetDataReductionStatistics(); | 430 ResetDataReductionStatistics(); |
325 } | 431 } |
326 | 432 |
327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); | 433 std::string proxy = GetDataReductionProxyOrigin(); |
328 | |
329 // Configure use of the data reduction proxy if it is enabled and the proxy | 434 // Configure use of the data reduction proxy if it is enabled and the proxy |
330 // origin is non-empty. | 435 // origin is non-empty. |
331 enabled_by_user_= | 436 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); | 437 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); |
334 | 438 |
335 // Check if the proxy has been disabled explicitly by the carrier. | 439 // Check if the proxy has been disabled explicitly by the carrier. |
336 if (enabled_by_user_) | 440 if (enabled_by_user_) |
337 ProbeWhetherDataReductionProxyIsAvailable(); | 441 ProbeWhetherDataReductionProxyIsAvailable(); |
338 } | 442 } |
339 | 443 |
340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 444 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
341 bool at_startup) { | 445 bool at_startup) { |
342 LogProxyState(enabled, at_startup); | 446 LogProxyState(enabled, at_startup); |
343 PrefService* prefs = GetOriginalProfilePrefs(); | 447 PrefService* prefs = GetOriginalProfilePrefs(); |
344 DCHECK(prefs); | 448 DCHECK(prefs); |
345 DictionaryPrefUpdate update(prefs, prefs::kProxy); | 449 DictionaryPrefUpdate update(prefs, prefs::kProxy); |
346 base::DictionaryValue* dict = update.Get(); | 450 base::DictionaryValue* dict = update.Get(); |
347 if (enabled) { | 451 if (enabled) { |
| 452 std::string fallback = GetDataReductionProxyFallback(); |
348 std::string proxy_server_config = | 453 std::string proxy_server_config = |
349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; | 454 "http=" + GetDataReductionProxyOrigin() + |
| 455 (fallback.empty() ? "" : "," + fallback) + |
| 456 ",direct://;"; |
350 dict->SetString("server", proxy_server_config); | 457 dict->SetString("server", proxy_server_config); |
351 dict->SetString("mode", | 458 dict->SetString("mode", |
352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 459 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 460 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
354 } else { | 461 } else { |
355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 462 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
356 dict->SetString("server", ""); | 463 dict->SetString("server", ""); |
357 dict->SetString("bypass_list", ""); | 464 dict->SetString("bypass_list", ""); |
358 } | 465 } |
359 } | 466 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 return command_line.GetSwitchValueASCII( | 536 return command_line.GetSwitchValueASCII( |
430 switches::kDataReductionProxyProbeURL); | 537 switches::kDataReductionProxyProbeURL); |
431 } | 538 } |
432 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) | 539 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) |
433 return DATA_REDUCTION_PROXY_PROBE_URL; | 540 return DATA_REDUCTION_PROXY_PROBE_URL; |
434 #else | 541 #else |
435 return std::string(); | 542 return std::string(); |
436 #endif | 543 #endif |
437 } | 544 } |
438 | 545 |
| 546 base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) { |
| 547 if (!IsDataReductionProxyAllowed()) |
| 548 return base::string16(); |
| 549 |
| 550 std::string key; |
| 551 |
| 552 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 553 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { |
| 554 // If an origin is provided via a switch, then only consider the value |
| 555 // that is provided by a switch. Do not use the preprocessor constant. |
| 556 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command |
| 557 // line. |
| 558 if (!command_line.HasSwitch(switches::kSpdyProxyAuthValue)) |
| 559 return base::string16(); |
| 560 key = command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); |
| 561 } else { |
| 562 #if defined(SPDY_PROXY_AUTH_VALUE) |
| 563 key = SPDY_PROXY_AUTH_VALUE; |
| 564 #else |
| 565 return base::string16(); |
| 566 #endif |
| 567 } |
| 568 |
| 569 DCHECK(!key.empty()); |
| 570 |
| 571 std::string salted_key = |
| 572 base::StringPrintf("%lld%s%lld", salt, key.c_str(), salt); |
| 573 return UTF8ToUTF16(base::MD5String(salted_key)); |
| 574 } |
| 575 |
439 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { | 576 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { |
440 std::string url = GetProxyCheckURL(); | 577 std::string url = GetProxyCheckURL(); |
441 if (url.empty()) | 578 if (url.empty()) |
442 return NULL; | 579 return NULL; |
443 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), | 580 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), |
444 net::URLFetcher::GET, | 581 net::URLFetcher::GET, |
445 this); | 582 this); |
446 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 583 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
447 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); | 584 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); |
448 Profile* profile = g_browser_process->profile_manager()-> | 585 Profile* profile = g_browser_process->profile_manager()-> |
449 GetDefaultProfile(); | 586 GetDefaultProfile(); |
450 fetcher->SetRequestContext(profile->GetRequestContext()); | 587 fetcher->SetRequestContext(profile->GetRequestContext()); |
451 // Configure max retries to be at most kMaxRetries times for 5xx errors. | 588 // Configure max retries to be at most kMaxRetries times for 5xx errors. |
452 static const int kMaxRetries = 5; | 589 static const int kMaxRetries = 5; |
453 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 590 fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
454 return fetcher; | 591 return fetcher; |
455 } | 592 } |
456 | 593 |
457 void | 594 void |
458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 595 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
459 net::URLFetcher* fetcher = GetURLFetcher(); | 596 net::URLFetcher* fetcher = GetURLFetcher(); |
460 if (!fetcher) | 597 if (!fetcher) |
461 return; | 598 return; |
462 fetcher_.reset(fetcher); | 599 fetcher_.reset(fetcher); |
463 fetcher_->Start(); | 600 fetcher_->Start(); |
464 } | 601 } |
OLD | NEW |