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

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, 2 months 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"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 143 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) 144 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin))
145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); 145 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin);
146 #if defined(SPDY_PROXY_AUTH_ORIGIN) 146 #if defined(SPDY_PROXY_AUTH_ORIGIN)
147 return SPDY_PROXY_AUTH_ORIGIN; 147 return SPDY_PROXY_AUTH_ORIGIN;
148 #else 148 #else
149 return std::string(); 149 return std::string();
150 #endif 150 #endif
151 } 151 }
152 152
153 std::string DataReductionProxySettings::GetDataReductionProxyFallback() {
bengr 2013/10/20 18:19:31 I think we should enforce that a fallback only has
marq (ping after 24h) 2013/10/20 20:43:52 Yeah, good point. When I do the Great Renaming CL
154 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
155 if (command_line.HasSwitch(switches::kSpdyProxyAuthFallback))
156 return command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthFallback);
157 #if defined(DATA_REDUCTION_FALLBACK_HOST)
bengr 2013/10/20 18:19:31 I hate names. If we are going to move over to usin
marq (ping after 24h) 2013/10/20 20:43:52 This implementation mirrors the one for getDataRed
bengr 2013/10/20 21:51:48 Let's verify that we don't also need to adjust chr
158 return DATA_REDUCTION_FALLBACK_HOST;
159 #else
160 return std::string();
161 #endif
162 }
163
bengr 2013/10/20 18:19:31 We should have a different SPDY_PROXY_AUTH_VALUE f
bengr 2013/10/20 18:19:31 We should have a different SPDY_PROXY_AUTH_VALUE f
marq (ping after 24h) 2013/10/20 20:43:52 Ack.
153 std::string DataReductionProxySettings::GetDataReductionProxyAuth() { 164 std::string DataReductionProxySettings::GetDataReductionProxyAuth() {
154 if (!IsDataReductionProxyAllowed()) 165 if (!IsDataReductionProxyAllowed())
155 return std::string(); 166 return std::string();
156 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 167 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
157 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { 168 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) {
158 // If an origin is provided via a switch, then only consider the value 169 // If an origin is provided via a switch, then only consider the value
159 // that is provided by a switch. Do not use the preprocessor constant. 170 // that is provided by a switch. Do not use the preprocessor constant.
160 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command 171 // Don't expose SPDY_PROXY_AUTH_VALUE to a proxy passed in via the command
161 // line. 172 // line.
162 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue)) 173 if (command_line.HasSwitch(switches::kSpdyProxyAuthValue))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 241 }
231 DVLOG(1) << "The data reduction proxy is blocked."; 242 DVLOG(1) << "The data reduction proxy is blocked.";
232 243
233 if (enabled_by_user_ && !disabled_by_carrier_) { 244 if (enabled_by_user_ && !disabled_by_carrier_) {
234 // Disable the proxy. 245 // Disable the proxy.
235 SetProxyConfigs(false, false); 246 SetProxyConfigs(false, false);
236 } 247 }
237 disabled_by_carrier_ = true; 248 disabled_by_carrier_ = true;
238 } 249 }
239 250
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() { 251 void DataReductionProxySettings::OnIPAddressChanged() {
252 if (enabled_by_user_) { 252 if (enabled_by_user_) {
253 DCHECK(IsDataReductionProxyAllowed()); 253 DCHECK(IsDataReductionProxyAllowed());
254 ProbeWhetherDataReductionProxyIsAvailable(); 254 ProbeWhetherDataReductionProxyIsAvailable();
255 } 255 }
256 } 256 }
257 257
258 void DataReductionProxySettings::OnProxyEnabledPrefChange() { 258 void DataReductionProxySettings::OnProxyEnabledPrefChange() {
259 if (!IsDataReductionProxyAllowed()) 259 if (!IsDataReductionProxyAllowed())
260 return; 260 return;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 PrefService* prefs = GetOriginalProfilePrefs(); 317 PrefService* prefs = GetOriginalProfilePrefs();
318 318
319 // TODO(marq): Consider moving this so stats are wiped the first time the 319 // TODO(marq): Consider moving this so stats are wiped the first time the
320 // proxy settings are actually (not maybe) turned on. 320 // proxy settings are actually (not maybe) turned on.
321 if (spdy_proxy_auth_enabled_.GetValue() && 321 if (spdy_proxy_auth_enabled_.GetValue() &&
322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) { 322 !prefs->GetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore)) {
323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true); 323 prefs->SetBoolean(prefs::kSpdyProxyAuthWasEnabledBefore, true);
324 ResetDataReductionStatistics(); 324 ResetDataReductionStatistics();
325 } 325 }
326 326
327 std::string spdy_proxy_origin = GetDataReductionProxyOriginHostPort(); 327 std::string main_proxy = GetDataReductionProxyOrigin();
328 328 std::string fallback_proxy = GetDataReductionProxyFallback();
329 // Configure use of the data reduction proxy if it is enabled and the proxy 329 // Configure use of the data reduction proxy if it is enabled and the proxy
330 // origin is non-empty. 330 // origin is non-empty.
331 enabled_by_user_= 331 enabled_by_user_= spdy_proxy_auth_enabled_.GetValue()
332 spdy_proxy_auth_enabled_.GetValue() && !spdy_proxy_origin.empty(); 332 && ( !main_proxy.empty() || !fallback_proxy.empty() );
bengr 2013/10/20 18:19:31 Requiring both will be easier reason about.
marq (ping after 24h) 2013/10/20 20:43:52 Done.
333 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup); 333 SetProxyConfigs(enabled_by_user_ && !disabled_by_carrier_, at_startup);
334 334
335 // Check if the proxy has been disabled explicitly by the carrier. 335 // Check if the proxy has been disabled explicitly by the carrier.
336 if (enabled_by_user_) 336 if (enabled_by_user_)
337 ProbeWhetherDataReductionProxyIsAvailable(); 337 ProbeWhetherDataReductionProxyIsAvailable();
338 } 338 }
339 339
340 void DataReductionProxySettings::SetProxyConfigs(bool enabled, 340 void DataReductionProxySettings::SetProxyConfigs(bool enabled,
341 bool at_startup) { 341 bool at_startup) {
342 LogProxyState(enabled, at_startup); 342 LogProxyState(enabled, at_startup);
343 PrefService* prefs = GetOriginalProfilePrefs(); 343 PrefService* prefs = GetOriginalProfilePrefs();
344 DCHECK(prefs); 344 DCHECK(prefs);
345 DictionaryPrefUpdate update(prefs, prefs::kProxy); 345 DictionaryPrefUpdate update(prefs, prefs::kProxy);
346 base::DictionaryValue* dict = update.Get(); 346 base::DictionaryValue* dict = update.Get();
347 if (enabled) { 347 if (enabled) {
348 std::string fallback = GetDataReductionProxyFallback();
348 std::string proxy_server_config = 349 std::string proxy_server_config =
349 "http=" + GetDataReductionProxyOrigin() + ",direct://;"; 350 "http=" + GetDataReductionProxyOrigin() +
351 (fallback.empty() ? "" : "," + fallback) +
352 ",direct://;";
350 dict->SetString("server", proxy_server_config); 353 dict->SetString("server", proxy_server_config);
351 dict->SetString("mode", 354 dict->SetString("mode",
352 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); 355 ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS));
353 dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); 356 dict->SetString("bypass_list", JoinString(bypass_rules_, ", "));
354 } else { 357 } else {
355 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); 358 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM));
356 dict->SetString("server", ""); 359 dict->SetString("server", "");
357 dict->SetString("bypass_list", ""); 360 dict->SetString("bypass_list", "");
358 } 361 }
359 } 362 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 458 }
456 459
457 void 460 void
458 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() { 461 DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
459 net::URLFetcher* fetcher = GetURLFetcher(); 462 net::URLFetcher* fetcher = GetURLFetcher();
460 if (!fetcher) 463 if (!fetcher)
461 return; 464 return;
462 fetcher_.reset(fetcher); 465 fetcher_.reset(fetcher);
463 fetcher_->Start(); 466 fetcher_->Start();
464 } 467 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698