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 | |
bengr
2013/10/22 17:49:30
Factor
marq (ping after 24h)
2013/10/22 21:18:01
Done.
| |
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) { | |
bengr
2013/10/22 17:49:30
indent +2
marq (ping after 24h)
2013/10/22 21:18:01
Done.
| |
120 // This is a no-op unless the authentication params are compiled in. | |
bengr
2013/10/22 17:49:30
parameters
marq (ping after 24h)
2013/10/22 21:18:01
Done.
| |
121 // (even though values for them may be specified on the command line). | |
bengr
2013/10/22 17:49:30
It's probably worth saying that when specified in
marq (ping after 24h)
2013/10/22 21:18:01
Done.
| |
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; | |
bengr
2013/10/22 17:49:30
indent -1
marq (ping after 24h)
2013/10/22 21:18:01
Done.
| |
126 | |
127 DataReductionProxyList proxies = GetDataReductionProxies(); | |
128 for (DataReductionProxyList::iterator it = proxies.begin(); | |
129 it != proxies.end(); ++it) { | |
130 net::HostPortPair auth_origin = *it; | |
bengr
2013/10/22 17:49:30
const ref?
marq (ping after 24h)
2013/10/22 21:18:01
Yes, but the code's changed slightly.
| |
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 16 matching lines...) Expand all Loading... | |
136 return IsProxyOriginSetOnCommandLine() || | 180 return IsProxyOriginSetOnCommandLine() || |
137 (IsDataReductionProxyAllowed() && | 181 (IsDataReductionProxyAllowed() && |
138 FieldTrialList::FindFullName("DataCompressionProxyPromoVisibility") == | 182 FieldTrialList::FindFullName("DataCompressionProxyPromoVisibility") == |
139 kEnabled); | 183 kEnabled); |
140 } | 184 } |
141 | 185 |
142 std::string DataReductionProxySettings::GetDataReductionProxyOrigin() { | 186 std::string DataReductionProxySettings::GetDataReductionProxyOrigin() { |
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 return GetDefaultProxyHost(); |
147 return SPDY_PROXY_AUTH_ORIGIN; | |
148 #else | |
149 return std::string(); | |
150 #endif | |
151 } | 191 } |
152 | 192 |
153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { | 193 std::string DataReductionProxySettings::GetDataReductionProxyFallback() { |
154 if (!IsDataReductionProxyAllowed()) | 194 // Regardless of what else is defined, only return a value if the main proxy |
195 // origin is defined. | |
196 if (GetDataReductionProxyOrigin().empty()) | |
155 return std::string(); | 197 return std::string(); |
156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 198 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | 199 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback)) |
158 // If an origin is provided via a switch, then only consider the value | 200 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback); |
159 // that is provided by a switch. Do not use the preprocessor constant. | 201 return GetDefaultFallbackProxyHost(); |
160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | 202 } |
161 // line. | 203 |
162 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | 204 bool DataReductionProxySettings::IsAcceptableAuthChallenge( |
163 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); | 205 net::AuthChallengeInfo* auth_info) { |
164 return std::string(); | 206 // Challenge realm must start with the authentication realm name. |
207 std::string realm_prefix = | |
208 auth_info->realm.substr(0, strlen(kAuthenticationRealmName)); | |
209 if (realm_prefix != kAuthenticationRealmName) | |
210 return false; | |
211 | |
212 // The challenger must be one of the configured proxies. | |
213 DataReductionProxyList proxies = GetDataReductionProxies(); | |
214 for (DataReductionProxyList::iterator it = proxies.begin(); | |
215 it != proxies.end(); ++it) { | |
216 net::HostPortPair origin_host = *it; | |
217 if (origin_host.Equals(auth_info->challenger)) | |
218 return true; | |
165 } | 219 } |
166 #if defined(SPDY_PROXY_AUTH_VALUE) | 220 return false; |
167 return SPDY_PROXY_AUTH_VALUE; | 221 } |
168 #else | 222 |
169 return std::string(); | 223 base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( |
170 #endif | 224 net::AuthChallengeInfo* auth_info) { |
225 if (auth_info->realm.length() > strlen(kAuthenticationRealmName)) { | |
226 int64 salt; | |
227 std::string realm_suffix = | |
228 auth_info->realm.substr(strlen(kAuthenticationRealmName)); | |
229 if (base::StringToInt64(realm_suffix, &salt)) { | |
230 return AuthHashForSalt(salt); | |
231 } else { | |
232 DVLOG(1) << "Unable to parse realm name " << auth_info->realm | |
233 << "into an int for salting."; | |
234 return base::string16(); | |
235 } | |
236 } else { | |
237 return base::string16(); | |
238 } | |
171 } | 239 } |
172 | 240 |
173 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { | 241 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { |
174 return spdy_proxy_auth_enabled_.GetValue(); | 242 return spdy_proxy_auth_enabled_.GetValue(); |
175 } | 243 } |
176 | 244 |
177 bool DataReductionProxySettings::IsDataReductionProxyManaged() { | 245 bool DataReductionProxySettings::IsDataReductionProxyManaged() { |
178 return spdy_proxy_auth_enabled_.IsManaged(); | 246 return spdy_proxy_auth_enabled_.IsManaged(); |
179 } | 247 } |
180 | 248 |
249 DataReductionProxySettings::DataReductionProxyList | |
250 DataReductionProxySettings::GetDataReductionProxies() { | |
251 DataReductionProxyList proxies; | |
252 std::string proxy = GetDataReductionProxyOrigin(); | |
253 std::string fallback = GetDataReductionProxyFallback(); | |
254 | |
255 if (!proxy.empty()) | |
256 proxies.push_back(net::HostPortPair::FromURL(GURL(proxy))); | |
257 | |
258 if (!fallback.empty()) { | |
259 // Sanity check: fallback isn't the only proxy. | |
260 DCHECK(!proxies.empty()); | |
261 proxies.push_back(net::HostPortPair::FromURL(GURL(fallback))); | |
262 } | |
263 | |
264 return proxies; | |
265 } | |
266 | |
181 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { | 267 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { |
182 // Prevent configuring the proxy when it is not allowed to be used. | 268 // Prevent configuring the proxy when it is not allowed to be used. |
183 if (!IsDataReductionProxyAllowed()) | 269 if (!IsDataReductionProxyAllowed()) |
184 return; | 270 return; |
185 | 271 |
186 spdy_proxy_auth_enabled_.SetValue(enabled); | 272 spdy_proxy_auth_enabled_.SetValue(enabled); |
187 OnProxyEnabledPrefChange(); | 273 OnProxyEnabledPrefChange(); |
188 } | 274 } |
189 | 275 |
190 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { | 276 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { |
191 PrefService* local_state = GetLocalStatePrefs(); | 277 PrefService* local_state = GetLocalStatePrefs(); |
192 int64 last_update_internal = | 278 int64 last_update_internal = |
193 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); | 279 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
194 base::Time last_update = base::Time::FromInternalValue(last_update_internal); | 280 base::Time last_update = base::Time::FromInternalValue(last_update_internal); |
195 return static_cast<int64>(last_update.ToJsTime()); | 281 return static_cast<int64>(last_update.ToJsTime()); |
196 } | 282 } |
197 | 283 |
198 std::vector<long long> | 284 DataReductionProxySettings::ContentLengthList |
199 DataReductionProxySettings::GetDailyOriginalContentLengths() { | 285 DataReductionProxySettings::GetDailyOriginalContentLengths() { |
200 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); | 286 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); |
201 } | 287 } |
202 | 288 |
203 std::vector<long long> | 289 DataReductionProxySettings::ContentLengthList |
204 DataReductionProxySettings::GetDailyReceivedContentLengths() { | 290 DataReductionProxySettings::GetDailyReceivedContentLengths() { |
205 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); | 291 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); |
206 } | 292 } |
207 | 293 |
208 void DataReductionProxySettings::OnURLFetchComplete( | 294 void DataReductionProxySettings::OnURLFetchComplete( |
209 const net::URLFetcher* source) { | 295 const net::URLFetcher* source) { |
210 net::URLRequestStatus status = source->GetStatus(); | 296 net::URLRequestStatus status = source->GetStatus(); |
211 if (status.status() == net::URLRequestStatus::FAILED && | 297 if (status.status() == net::URLRequestStatus::FAILED && |
212 status.error() == net::ERR_INTERNET_DISCONNECTED) { | 298 status.error() == net::ERR_INTERNET_DISCONNECTED) { |
213 return; | 299 return; |
(...skipping 16 matching lines...) Expand all Loading... | |
230 } | 316 } |
231 DVLOG(1) << "The data reduction proxy is blocked."; | 317 DVLOG(1) << "The data reduction proxy is blocked."; |
232 | 318 |
233 if (enabled_by_user_ && !disabled_by_carrier_) { | 319 if (enabled_by_user_ && !disabled_by_carrier_) { |
234 // Disable the proxy. | 320 // Disable the proxy. |
235 SetProxyConfigs(false, false); | 321 SetProxyConfigs(false, false); |
236 } | 322 } |
237 disabled_by_carrier_ = true; | 323 disabled_by_carrier_ = true; |
238 } | 324 } |
239 | 325 |
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() { | 326 void DataReductionProxySettings::OnIPAddressChanged() { |
252 if (enabled_by_user_) { | 327 if (enabled_by_user_) { |
253 DCHECK(IsDataReductionProxyAllowed()); | 328 DCHECK(IsDataReductionProxyAllowed()); |
254 ProbeWhetherDataReductionProxyIsAvailable(); | 329 ProbeWhetherDataReductionProxyIsAvailable(); |
255 } | 330 } |
256 } | 331 } |
257 | 332 |
258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 333 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
259 if (!IsDataReductionProxyAllowed()) | 334 if (!IsDataReductionProxyAllowed()) |
260 return; | 335 return; |
(...skipping 16 matching lines...) Expand all Loading... | |
277 // feedback. | 352 // feedback. |
278 const char kAtStartup[] = "at startup"; | 353 const char kAtStartup[] = "at startup"; |
279 const char kByUser[] = "by user action"; | 354 const char kByUser[] = "by user action"; |
280 const char kOn[] = "ON"; | 355 const char kOn[] = "ON"; |
281 const char kOff[] = "OFF"; | 356 const char kOff[] = "OFF"; |
282 | 357 |
283 LOG(WARNING) << "SPDY proxy " << (enabled ? kOn : kOff) | 358 LOG(WARNING) << "SPDY proxy " << (enabled ? kOn : kOff) |
284 << " " << (at_startup ? kAtStartup : kByUser); | 359 << " " << (at_startup ? kAtStartup : kByUser); |
285 } | 360 } |
286 | 361 |
362 std::string DataReductionProxySettings::GetDefaultProxyHost() { | |
bengr
2013/10/22 17:49:30
Why isn't the handling of command line switch valu
marq (ping after 24h)
2013/10/22 21:18:01
These two methods are used so that unit tests can
| |
363 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
364 return SPDY_PROXY_AUTH_ORIGIN; | |
365 #else | |
366 return std::string(); | |
367 #endif | |
368 } | |
369 | |
370 std::string DataReductionProxySettings::GetDefaultFallbackProxyHost() { | |
371 #if defined(DATA_REDUCTION_FALLBACK_HOST) | |
372 return DATA_REDUCTION_FALLBACK_HOST; | |
bengr
2013/10/22 17:49:30
why not check in this function if GetDefaultProxyH
marq (ping after 24h)
2013/10/22 21:18:01
I don't think the default value here is of necessi
| |
373 #else | |
374 return std::string(); | |
375 #endif | |
376 } | |
377 | |
287 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { | 378 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { |
288 return g_browser_process->profile_manager()->GetLastUsedProfile()-> | 379 return g_browser_process->profile_manager()->GetLastUsedProfile()-> |
289 GetOriginalProfile()->GetPrefs(); | 380 GetOriginalProfile()->GetPrefs(); |
290 } | 381 } |
291 | 382 |
292 PrefService* DataReductionProxySettings::GetLocalStatePrefs() { | 383 PrefService* DataReductionProxySettings::GetLocalStatePrefs() { |
293 return g_browser_process->local_state(); | 384 return g_browser_process->local_state(); |
294 } | 385 } |
295 | 386 |
296 bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() { | 387 bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() { |
(...skipping 20 matching lines...) Expand all Loading... | |
317 PrefService* prefs = GetOriginalProfilePrefs(); | 408 PrefService* prefs = GetOriginalProfilePrefs(); |
318 | 409 |
319 // TODO(marq): Consider moving this so stats are wiped the first time the | 410 // TODO(marq): Consider moving this so stats are wiped the first time the |
320 // proxy settings are actually (not maybe) turned on. | 411 // proxy settings are actually (not maybe) turned on. |
321 if (spdy_proxy_auth_enabled_.GetValue() && | 412 if (spdy_proxy_auth_enabled_.GetValue() && |
322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { | 413 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { |
323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); | 414 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); |
324 ResetDataReductionStatistics(); | 415 ResetDataReductionStatistics(); |
325 } | 416 } |
326 | 417 |
327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); | 418 std::string proxy = GetDataReductionProxyOrigin(); |
328 | |
329 // Configure use of the data reduction proxy if it is enabled and the proxy | 419 // Configure use of the data reduction proxy if it is enabled and the proxy |
330 // origin is non-empty. | 420 // origin is non-empty. |
331 enabled_by_user_= | 421 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); | 422 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); |
334 | 423 |
335 // Check if the proxy has been disabled explicitly by the carrier. | 424 // Check if the proxy has been disabled explicitly by the carrier. |
336 if (enabled_by_user_) | 425 if (enabled_by_user_) |
337 ProbeWhetherDataReductionProxyIsAvailable(); | 426 ProbeWhetherDataReductionProxyIsAvailable(); |
338 } | 427 } |
339 | 428 |
340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, | 429 void DataReductionProxySettings::SetProxyConfigs(bool enabled, |
341 bool at_startup) { | 430 bool at_startup) { |
342 LogProxyState(enabled, at_startup); | 431 LogProxyState(enabled, at_startup); |
343 PrefService* prefs = GetOriginalProfilePrefs(); | 432 PrefService* prefs = GetOriginalProfilePrefs(); |
344 DCHECK(prefs); | 433 DCHECK(prefs); |
345 DictionaryPrefUpdate update(prefs, prefs::kProxy); | 434 DictionaryPrefUpdate update(prefs, prefs::kProxy); |
346 base::DictionaryValue* dict = update.Get(); | 435 base::DictionaryValue* dict = update.Get(); |
347 if (enabled) { | 436 if (enabled) { |
437 std::string fallback = GetDataReductionProxyFallback(); | |
348 std::string proxy_server_config = | 438 std::string proxy_server_config = |
349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; | 439 "http=" + GetDataReductionProxyOrigin() + |
440 (fallback.empty() ? "" : "," + fallback) + | |
441 ",direct://;"; | |
350 dict->SetString("server", proxy_server_config); | 442 dict->SetString("server", proxy_server_config); |
351 dict->SetString("mode", | 443 dict->SetString("mode", |
352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); | 444 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); |
353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); | 445 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); |
354 } else { | 446 } else { |
355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 447 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
356 dict->SetString("server", ""); | 448 dict->SetString("server", ""); |
357 dict->SetString("bypass_list", ""); | 449 dict->SetString("bypass_list", ""); |
358 } | 450 } |
359 } | 451 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 return command_line.GetSwitchValueASCII( | 521 return command_line.GetSwitchValueASCII( |
430 switches::kDataReductionProxyProbeURL); | 522 switches::kDataReductionProxyProbeURL); |
431 } | 523 } |
432 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) | 524 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) |
433 return DATA_REDUCTION_PROXY_PROBE_URL; | 525 return DATA_REDUCTION_PROXY_PROBE_URL; |
434 #else | 526 #else |
435 return std::string(); | 527 return std::string(); |
436 #endif | 528 #endif |
437 } | 529 } |
438 | 530 |
531 base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) { | |
532 if (!IsDataReductionProxyAllowed()) | |
533 return base::string16(); | |
534 | |
535 std::string key; | |
536 | |
537 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
538 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { | |
539 // If an origin is provided via a switch, then only consider the value | |
540 // that is provided by a switch. Do not use the preprocessor constant. | |
541 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command | |
542 // line. | |
543 if (!command_line.HasSwitch(switches::kSpdyProxyAuthValue)) | |
544 return base::string16(); | |
545 key = command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue); | |
546 } else { | |
547 #if defined(SPDY_PROXY_AUTH_VALUE) | |
548 key = SPDY_PROXY_AUTH_VALUE; | |
549 #else | |
550 return base::string16(); | |
551 #endif | |
552 } | |
553 | |
554 DCHECK(!key.empty()); | |
555 | |
556 std::string salted_key = | |
557 base::StringPrintf("%lld%s%lld", salt, key.c_str(), salt); | |
558 return UTF8ToUTF16(base::MD5String(salted_key)); | |
559 } | |
560 | |
439 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { | 561 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { |
440 std::string url = GetProxyCheckURL(); | 562 std::string url = GetProxyCheckURL(); |
441 if (url.empty()) | 563 if (url.empty()) |
442 return NULL; | 564 return NULL; |
443 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), | 565 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), |
444 net::URLFetcher::GET, | 566 net::URLFetcher::GET, |
445 this); | 567 this); |
446 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 568 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
447 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); | 569 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); |
448 Profile* profile = g_browser_process->profile_manager()-> | 570 Profile* profile = g_browser_process->profile_manager()-> |
449 GetDefaultProfile(); | 571 GetDefaultProfile(); |
450 fetcher->SetRequestContext(profile->GetRequestContext()); | 572 fetcher->SetRequestContext(profile->GetRequestContext()); |
451 // Configure max retries to be at most kMaxRetries times for 5xx errors. | 573 // Configure max retries to be at most kMaxRetries times for 5xx errors. |
452 static const int kMaxRetries = 5; | 574 static const int kMaxRetries = 5; |
453 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 575 fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
454 return fetcher; | 576 return fetcher; |
455 } | 577 } |
456 | 578 |
457 void | 579 void |
458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { | 580 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { |
459 net::URLFetcher* fetcher = GetURLFetcher(); | 581 net::URLFetcher* fetcher = GetURLFetcher(); |
460 if (!fetcher) | 582 if (!fetcher) |
461 return; | 583 return; |
462 fetcher_.reset(fetcher); | 584 fetcher_.reset(fetcher); |
463 fetcher_->Start(); | 585 fetcher_->Start(); |
464 } | 586 } |
OLD | NEW |