Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings.cc

Issue 30883003: Simple fallback implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patched
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
60 } 69 }
61 70
71 bool IsProxyOriginSetOnCommandLine() {
72 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
73 return command_line.HasSwitch(switches::kSpdyProxyAuthOrigin);
74 }
75
62 } // namespace 76 } // namespace
63 77
64 DataReductionProxySettings::DataReductionProxySettings() 78 DataReductionProxySettings::DataReductionProxySettings()
65 : has_turned_on_(false), 79 : has_turned_on_(false),
66 has_turned_off_(false), 80 has_turned_off_(false),
67 disabled_by_carrier_(false), 81 disabled_by_carrier_(false),
68 enabled_by_user_(false) { 82 enabled_by_user_(false) {
69 } 83 }
70 84
71 DataReductionProxySettings::~DataReductionProxySettings() { 85 DataReductionProxySettings::~DataReductionProxySettings() {
(...skipping 28 matching lines...) Expand all
100 RecordDataReductionInit(); 114 RecordDataReductionInit();
101 if (spdy_proxy_auth_enabled_.GetValue() || 115 if (spdy_proxy_auth_enabled_.GetValue() ||
102 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) { 116 command_line.HasSwitch(switches::kEnableSpdyProxyAuth)) {
103 MaybeActivateDataReductionProxy(true); 117 MaybeActivateDataReductionProxy(true);
104 } else { 118 } else {
105 // This is logged so we can use this information in user feedback. 119 // This is logged so we can use this information in user feedback.
106 LogProxyState(false /* enabled */, true /* at startup */); 120 LogProxyState(false /* enabled */, true /* at startup */);
107 } 121 }
108 } 122 }
109 123
124 void DataReductionProxySettings::InitDataReductionProxySession(
125 net::HttpNetworkSession* session) {
126 // This is a no-op unless the authentication parameters are compiled in.
127 // (even though values for them may be specified on the command line).
128 // Authentication will still work if the command line parameters are used,
129 // however there will be a round-trip overhead for each challenge/response
130 // (typically once per session).
131 #if defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE)
132 DCHECK(session);
133 net::HttpAuthCache* auth_cache = session->http_auth_cache();
134 DCHECK(auth_cache);
135 InitDataReductionAuthentication(auth_cache);
136 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) && defined(SPDY_PROXY_AUTH_VALUE)
137 }
138
139 void DataReductionProxySettings::InitDataReductionAuthentication(
140 net::HttpAuthCache* auth_cache) {
141 DCHECK(auth_cache);
142 int64 timestamp =
143 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000;
144
145 DataReductionProxyList proxies = GetDataReductionProxies();
146 for (DataReductionProxyList::iterator it = proxies.begin();
147 it != proxies.end(); ++it) {
148 GURL auth_origin = (*it).GetOrigin();
149 int32 rand1, rand2, rand3;
150 crypto::RandBytes(&rand1, sizeof(rand1));
151 crypto::RandBytes(&rand2, sizeof(rand2));
152 crypto::RandBytes(&rand3, sizeof(rand3));
bengr 2013/10/23 01:38:16 would it be possible to have something like: int32
marq (ping after 24h) 2013/10/23 12:23:20 That doesn't randomize the last two elements of th
153
154 std::string realm =
155 base::StringPrintf("%s%lld", kAuthenticationRealmName, timestamp);
156 std::string challenge = base::StringPrintf(
157 "%s realm=\"%s\", ps=\"%lld-%u-%u-%u\"",
158 kAuthenticationRealmName, realm.data(), timestamp, rand1, rand2, rand3);
159 base::string16 password = AuthHashForSalt(timestamp);
160
161 DVLOG(1) << "origin: [" << auth_origin << "] realm: [" << realm
162 << "] challenge: [" << challenge << "] password: [" << password << "]";
163
164 net::AuthCredentials credentials(base::string16(), password);
165 auth_cache->Add(auth_origin,
166 realm,
167 net::HttpAuth::AUTH_SCHEME_SPDYPROXY,
168 challenge,
169 credentials,
170 std::string()); // Proxy auth uses an empty path for lookup.
171 }
172 }
173
110 void DataReductionProxySettings::AddHostPatternToBypass( 174 void DataReductionProxySettings::AddHostPatternToBypass(
111 const std::string& pattern) { 175 const std::string& pattern) {
112 bypass_rules_.push_back(pattern); 176 bypass_rules_.push_back(pattern);
113 } 177 }
114 178
115 void DataReductionProxySettings::AddURLPatternToBypass( 179 void DataReductionProxySettings::AddURLPatternToBypass(
116 const std::string& pattern) { 180 const std::string& pattern) {
117 size_t pos = pattern.find("/"); 181 size_t pos = pattern.find("/");
118 if (pattern.find("/", pos + 1) == pos + 1) 182 if (pattern.find("/", pos + 1) == pos + 1)
119 pos = pattern.find("/", pos + 2); 183 pos = pattern.find("/", pos + 2);
(...skipping 23 matching lines...) Expand all
143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 207 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) 208 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin))
145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); 209 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin);
146 #if defined(SPDY_PROXY_AUTH_ORIGIN) 210 #if defined(SPDY_PROXY_AUTH_ORIGIN)
147 return SPDY_PROXY_AUTH_ORIGIN; 211 return SPDY_PROXY_AUTH_ORIGIN;
148 #else 212 #else
149 return std::string(); 213 return std::string();
150 #endif 214 #endif
151 } 215 }
152 216
153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { 217 std::string DataReductionProxySettings::GetDataReductionProxyFallback() {
154 if (!IsDataReductionProxyAllowed()) 218 // Regardless of what else is defined, only return a value if the main proxy
219 // origin is defined.
220 if (GetDataReductionProxyOrigin().empty())
155 return std::string(); 221 return std::string();
156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 222 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { 223 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback))
158 // If an origin is provided via a switch, then only consider the value 224 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback);
159 // that is provided by a switch. Do not use the preprocessor constant. 225 #if defined(DATA_REDUCTION_FALLBACK_HOST)
160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command 226 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 227 #else
169 return std::string(); 228 return std::string();
170 #endif 229 #endif
171 } 230 }
172 231
232 bool DataReductionProxySettings::IsAcceptableAuthChallenge(
233 net::AuthChallengeInfo* auth_info) {
234 // Challenge realm must start with the authentication realm name.
235 std::string realm_prefix =
236 auth_info->realm.substr(0, strlen(kAuthenticationRealmName));
237 if (realm_prefix != kAuthenticationRealmName)
238 return false;
239
240 // The challenger must be one of the configured proxies.
241 DataReductionProxyList proxies = GetDataReductionProxies();
242 for (DataReductionProxyList::iterator it = proxies.begin();
243 it != proxies.end(); ++it) {
244 net::HostPortPair origin_host = net::HostPortPair::FromURL(*it);
245 if (origin_host.Equals(auth_info->challenger))
246 return true;
247 }
248 return false;
249 }
250
251 base::string16 DataReductionProxySettings::GetTokenForAuthChallenge(
252 net::AuthChallengeInfo* auth_info) {
253 if (auth_info->realm.length() > strlen(kAuthenticationRealmName)) {
254 int64 salt;
255 std::string realm_suffix =
256 auth_info->realm.substr(strlen(kAuthenticationRealmName));
257 if (base::StringToInt64(realm_suffix, &salt)) {
258 return AuthHashForSalt(salt);
259 } else {
260 DVLOG(1) << "Unable to parse realm name " << auth_info->realm
261 << "into an int for salting.";
262 return base::string16();
263 }
264 } else {
265 return base::string16();
266 }
267 }
268
173 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { 269 bool DataReductionProxySettings::IsDataReductionProxyEnabled() {
174 return spdy_proxy_auth_enabled_.GetValue(); 270 return spdy_proxy_auth_enabled_.GetValue();
175 } 271 }
176 272
177 bool DataReductionProxySettings::IsDataReductionProxyManaged() { 273 bool DataReductionProxySettings::IsDataReductionProxyManaged() {
178 return spdy_proxy_auth_enabled_.IsManaged(); 274 return spdy_proxy_auth_enabled_.IsManaged();
179 } 275 }
180 276
277 DataReductionProxySettings::DataReductionProxyList
278 DataReductionProxySettings::GetDataReductionProxies() {
279 DataReductionProxyList proxies;
280 std::string proxy = GetDataReductionProxyOrigin();
281 std::string fallback = GetDataReductionProxyFallback();
282
283 if (!proxy.empty())
284 proxies.push_back(GURL(proxy));
285
286 if (!fallback.empty()) {
287 // Sanity check: fallback isn't the only proxy.
288 DCHECK(!proxies.empty());
289 proxies.push_back(GURL(fallback));
290 }
291
292 return proxies;
293 }
294
181 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { 295 void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) {
182 // Prevent configuring the proxy when it is not allowed to be used. 296 // Prevent configuring the proxy when it is not allowed to be used.
183 if (!IsDataReductionProxyAllowed()) 297 if (!IsDataReductionProxyAllowed())
184 return; 298 return;
185 299
186 spdy_proxy_auth_enabled_.SetValue(enabled); 300 spdy_proxy_auth_enabled_.SetValue(enabled);
187 OnProxyEnabledPrefChange(); 301 OnProxyEnabledPrefChange();
188 } 302 }
189 303
190 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { 304 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() {
191 PrefService* local_state = GetLocalStatePrefs(); 305 PrefService* local_state = GetLocalStatePrefs();
192 int64 last_update_internal = 306 int64 last_update_internal =
193 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); 307 local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
194 base::Time last_update = base::Time::FromInternalValue(last_update_internal); 308 base::Time last_update = base::Time::FromInternalValue(last_update_internal);
195 return static_cast<int64>(last_update.ToJsTime()); 309 return static_cast<int64>(last_update.ToJsTime());
196 } 310 }
197 311
198 std::vector<long long> 312 DataReductionProxySettings::ContentLengthList
199 DataReductionProxySettings::GetDailyOriginalContentLengths() { 313 DataReductionProxySettings::GetDailyOriginalContentLengths() {
200 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); 314 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength);
201 } 315 }
202 316
203 std::vector<long long> 317 DataReductionProxySettings::ContentLengthList
204 DataReductionProxySettings::GetDailyReceivedContentLengths() { 318 DataReductionProxySettings::GetDailyReceivedContentLengths() {
205 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength); 319 return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength);
206 } 320 }
207 321
208 void DataReductionProxySettings::OnURLFetchComplete( 322 void DataReductionProxySettings::OnURLFetchComplete(
209 const net::URLFetcher* source) { 323 const net::URLFetcher* source) {
210 net::URLRequestStatus status = source->GetStatus(); 324 net::URLRequestStatus status = source->GetStatus();
211 if (status.status() == net::URLRequestStatus::FAILED && 325 if (status.status() == net::URLRequestStatus::FAILED &&
212 status.error() == net::ERR_INTERNET_DISCONNECTED) { 326 status.error() == net::ERR_INTERNET_DISCONNECTED) {
213 return; 327 return;
(...skipping 16 matching lines...) Expand all
230 } 344 }
231 DVLOG(1) << "The data reduction proxy is blocked."; 345 DVLOG(1) << "The data reduction proxy is blocked.";
232 346
233 if (enabled_by_user_ && !disabled_by_carrier_) { 347 if (enabled_by_user_ && !disabled_by_carrier_) {
234 // Disable the proxy. 348 // Disable the proxy.
235 SetProxyConfigs(false, false); 349 SetProxyConfigs(false, false);
236 } 350 }
237 disabled_by_carrier_ = true; 351 disabled_by_carrier_ = true;
238 } 352 }
239 353
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() { 354 void DataReductionProxySettings::OnIPAddressChanged() {
252 if (enabled_by_user_) { 355 if (enabled_by_user_) {
253 DCHECK(IsDataReductionProxyAllowed()); 356 DCHECK(IsDataReductionProxyAllowed());
254 ProbeWhetherDataReductionProxyIsAvailable(); 357 ProbeWhetherDataReductionProxyIsAvailable();
255 } 358 }
256 } 359 }
257 360
258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { 361 void DataReductionProxySettings::OnProxyEnabledPrefChange() {
259 if (!IsDataReductionProxyAllowed()) 362 if (!DataReductionProxySettings::IsDataReductionProxyAllowed())
260 return; 363 return;
261 MaybeActivateDataReductionProxy(false); 364 MaybeActivateDataReductionProxy(false);
262 } 365 }
263 366
264 void DataReductionProxySettings::AddDefaultProxyBypassRules() { 367 void DataReductionProxySettings::AddDefaultProxyBypassRules() {
265 // localhost 368 // localhost
266 AddHostPatternToBypass("<local>"); 369 AddHostPatternToBypass("<local>");
267 // RFC1918 private addresses. 370 // RFC1918 private addresses.
268 AddHostPatternToBypass("10.0.0.0/8"); 371 AddHostPatternToBypass("10.0.0.0/8");
269 AddHostPatternToBypass("172.16.0.0/12"); 372 AddHostPatternToBypass("172.16.0.0/12");
(...skipping 16 matching lines...) Expand all
286 389
287 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { 390 PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() {
288 return g_browser_process->profile_manager()->GetLastUsedProfile()-> 391 return g_browser_process->profile_manager()->GetLastUsedProfile()->
289 GetOriginalProfile()->GetPrefs(); 392 GetOriginalProfile()->GetPrefs();
290 } 393 }
291 394
292 PrefService* DataReductionProxySettings::GetLocalStatePrefs() { 395 PrefService* DataReductionProxySettings::GetLocalStatePrefs() {
293 return g_browser_process->local_state(); 396 return g_browser_process->local_state();
294 } 397 }
295 398
296 bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() {
297 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
298 return command_line.HasSwitch(switches::kSpdyProxyAuthOrigin);
299 }
300
301 void DataReductionProxySettings::ResetDataReductionStatistics() { 399 void DataReductionProxySettings::ResetDataReductionStatistics() {
302 PrefService* prefs = GetLocalStatePrefs(); 400 PrefService* prefs = GetLocalStatePrefs();
303 if (!prefs) 401 if (!prefs)
304 return; 402 return;
305 ListPrefUpdate original_update(prefs, prefs::kDailyHttpOriginalContentLength); 403 ListPrefUpdate original_update(prefs, prefs::kDailyHttpOriginalContentLength);
306 ListPrefUpdate received_update(prefs, prefs::kDailyHttpReceivedContentLength); 404 ListPrefUpdate received_update(prefs, prefs::kDailyHttpReceivedContentLength);
307 original_update->Clear(); 405 original_update->Clear();
308 received_update->Clear(); 406 received_update->Clear();
309 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { 407 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) {
310 original_update->AppendString(base::Int64ToString(0)); 408 original_update->AppendString(base::Int64ToString(0));
311 received_update->AppendString(base::Int64ToString(0)); 409 received_update->AppendString(base::Int64ToString(0));
312 } 410 }
313 } 411 }
314 412
315 void DataReductionProxySettings::MaybeActivateDataReductionProxy( 413 void DataReductionProxySettings::MaybeActivateDataReductionProxy(
316 bool at_startup) { 414 bool at_startup) {
317 PrefService* prefs = GetOriginalProfilePrefs(); 415 PrefService* prefs = GetOriginalProfilePrefs();
318 416
319 // TODO(marq): Consider moving this so stats are wiped the first time the 417 // TODO(marq): Consider moving this so stats are wiped the first time the
320 // proxy settings are actually (not maybe) turned on. 418 // proxy settings are actually (not maybe) turned on.
321 if (spdy_proxy_auth_enabled_.GetValue() && 419 if (spdy_proxy_auth_enabled_.GetValue() &&
322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { 420 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) {
323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); 421 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true);
324 ResetDataReductionStatistics(); 422 ResetDataReductionStatistics();
325 } 423 }
326 424
327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); 425 std::string proxy = GetDataReductionProxyOrigin();
328
329 // Configure use of the data reduction proxy if it is enabled and the proxy 426 // Configure use of the data reduction proxy if it is enabled and the proxy
330 // origin is non-empty. 427 // origin is non-empty.
331 enabled_by_user_= 428 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); 429 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup);
334 430
335 // Check if the proxy has been disabled explicitly by the carrier. 431 // Check if the proxy has been disabled explicitly by the carrier.
336 if (enabled_by_user_) 432 if (enabled_by_user_)
337 ProbeWhetherDataReductionProxyIsAvailable(); 433 ProbeWhetherDataReductionProxyIsAvailable();
338 } 434 }
339 435
340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, 436 void DataReductionProxySettings::SetProxyConfigs(bool enabled,
341 bool at_startup) { 437 bool at_startup) {
342 LogProxyState(enabled, at_startup); 438 LogProxyState(enabled, at_startup);
343 PrefService* prefs = GetOriginalProfilePrefs(); 439 PrefService* prefs = GetOriginalProfilePrefs();
344 DCHECK(prefs); 440 DCHECK(prefs);
345 DictionaryPrefUpdate update(prefs, prefs::kProxy); 441 DictionaryPrefUpdate update(prefs, prefs::kProxy);
346 base::DictionaryValue* dict = update.Get(); 442 base::DictionaryValue* dict = update.Get();
347 if (enabled) { 443 if (enabled) {
444 std::string fallback = GetDataReductionProxyFallback();
348 std::string proxy_server_config = 445 std::string proxy_server_config =
349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; 446 "http=" + GetDataReductionProxyOrigin() +
447 (fallback.empty() ? "" : "," + fallback) +
448 ",direct://;";
350 dict->SetString("server", proxy_server_config); 449 dict->SetString("server", proxy_server_config);
351 dict->SetString("mode", 450 dict->SetString("mode",
352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); 451 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS));
353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); 452 dict->SetString("bypass_list", JoinString(bypass_rules_, ", "));
354 } else { 453 } else {
355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); 454 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM));
356 dict->SetString("server", ""); 455 dict->SetString("server", "");
357 dict->SetString("bypass_list", ""); 456 dict->SetString("bypass_list", "");
358 } 457 }
359 } 458 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return command_line.GetSwitchValueASCII( 528 return command_line.GetSwitchValueASCII(
430 switches::kDataReductionProxyProbeURL); 529 switches::kDataReductionProxyProbeURL);
431 } 530 }
432 #if defined(DATA_REDUCTION_PROXY_PROBE_URL) 531 #if defined(DATA_REDUCTION_PROXY_PROBE_URL)
433 return DATA_REDUCTION_PROXY_PROBE_URL; 532 return DATA_REDUCTION_PROXY_PROBE_URL;
434 #else 533 #else
435 return std::string(); 534 return std::string();
436 #endif 535 #endif
437 } 536 }
438 537
538 base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) {
539 if (!IsDataReductionProxyAllowed())
540 return base::string16();
541
542 std::string key;
543
544 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
545 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) {
546 // If an origin is provided via a switch, then only consider the value
547 // that is provided by a switch. Do not use the preprocessor constant.
548 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command
549 // line.
550 if (!command_line.HasSwitch(switches::kSpdyProxyAuthValue))
551 return base::string16();
552 key = command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthValue);
553 } else {
554 #if defined(SPDY_PROXY_AUTH_VALUE)
555 key = SPDY_PROXY_AUTH_VALUE;
556 #else
557 return base::string16();
558 #endif
559 }
560
561 DCHECK(!key.empty());
562
563 std::string salted_key =
564 base::StringPrintf("%lld%s%lld", salt, key.c_str(), salt);
565 return UTF8ToUTF16(base::MD5String(salted_key));
566 }
567
439 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { 568 net::URLFetcher* DataReductionProxySettings::GetURLFetcher() {
440 std::string url = GetProxyCheckURL(); 569 std::string url = GetProxyCheckURL();
441 if (url.empty()) 570 if (url.empty())
442 return NULL; 571 return NULL;
443 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), 572 net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url),
444 net::URLFetcher::GET, 573 net::URLFetcher::GET,
445 this); 574 this);
446 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 575 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
447 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY); 576 fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY);
448 Profile* profile = g_browser_process->profile_manager()-> 577 Profile* profile = g_browser_process->profile_manager()->
449 GetDefaultProfile(); 578 GetDefaultProfile();
450 fetcher->SetRequestContext(profile->GetRequestContext()); 579 fetcher->SetRequestContext(profile->GetRequestContext());
451 // Configure max retries to be at most kMaxRetries times for 5xx errors. 580 // Configure max retries to be at most kMaxRetries times for 5xx errors.
452 static const int kMaxRetries = 5; 581 static const int kMaxRetries = 5;
453 fetcher->SetMaxRetriesOn5xx(kMaxRetries); 582 fetcher->SetMaxRetriesOn5xx(kMaxRetries);
454 return fetcher; 583 return fetcher;
455 } 584 }
456 585
457 void 586 void
458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { 587 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
459 net::URLFetcher* fetcher = GetURLFetcher(); 588 net::URLFetcher* fetcher = GetURLFetcher();
460 if (!fetcher) 589 if (!fetcher)
461 return; 590 return;
462 fetcher_.reset(fetcher); 591 fetcher_.reset(fetcher);
463 fetcher_->Start(); 592 fetcher_->Start();
464 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698