summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-19 01:03:21 +0000
committerbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-19 01:03:21 +0000
commitbec6a9985134812204bb4d6dc472dc789437e122 (patch)
tree53fbbb948c222d56fc44f3d568d61ae2584696aa
parentec092a17df1acdd67fa0a4522cb42aba2ce00d65 (diff)
downloadchromium_src-bec6a9985134812204bb4d6dc472dc789437e122.zip
chromium_src-bec6a9985134812204bb4d6dc472dc789437e122.tar.gz
chromium_src-bec6a9985134812204bb4d6dc472dc789437e122.tar.bz2
Add probe to warm data reduction proxy
On startup and on network changes, a request is made to the data reduction proxy to warm the connection. This reduces the page load time for first loads. BUG=354438 Review URL: https://codereview.chromium.org/338723002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278210 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/common.gypi8
-rw-r--r--chrome/browser/net/chrome_network_delegate.cc8
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc8
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_params.cc12
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_params.h12
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc45
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings.h16
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc26
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h15
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc75
-rw-r--r--components/data_reduction_proxy/common/data_reduction_proxy_switches.cc4
-rw-r--r--components/data_reduction_proxy/common/data_reduction_proxy_switches.h1
12 files changed, 197 insertions, 33 deletions
diff --git a/build/common.gypi b/build/common.gypi
index 5b15e70..6d356ef 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -562,6 +562,7 @@
'spdy_proxy_auth_property%' : '',
'spdy_proxy_auth_value%' : '',
'data_reduction_proxy_probe_url%' : '',
+ 'data_reduction_proxy_warmup_url%' : '',
'data_reduction_proxy_ssl_origin%' : '',
'data_reduction_proxy_alt_origin%' : '',
'data_reduction_proxy_alt_fallback_origin%' : '',
@@ -925,12 +926,14 @@
'icu_use_data_file_flag%' : 1,
'spdy_proxy_auth_origin%': '',
'data_reduction_proxy_probe_url%': '',
+ 'data_reduction_proxy_warmup_url%': '',
'data_reduction_dev_host%': '',
'data_reduction_fallback_host%': '',
}, {
'icu_use_data_file_flag%' : 0,
'spdy_proxy_auth_origin%': 'https://proxy.googlezip.net:443/',
'data_reduction_proxy_probe_url%': 'http://check.googlezip.net/connect',
+ 'data_reduction_proxy_warmup_url%': 'http://www.gstatic.com/generate_204',
'data_reduction_dev_host%': 'http://proxy-dev.googlezip.net:80/',
'data_reduction_fallback_host%': 'http://compress.googlezip.net:80/',
}],
@@ -1118,6 +1121,7 @@
'spdy_proxy_auth_property%': '<(spdy_proxy_auth_property)',
'spdy_proxy_auth_value%': '<(spdy_proxy_auth_value)',
'data_reduction_proxy_probe_url%': '<(data_reduction_proxy_probe_url)',
+ 'data_reduction_proxy_warmup_url%': '<(data_reduction_proxy_warmup_url)',
'data_reduction_proxy_ssl_origin%' : '<(data_reduction_proxy_ssl_origin)',
'data_reduction_proxy_alt_origin%' : '<(data_reduction_proxy_alt_origin)',
'data_reduction_proxy_alt_fallback_origin%' : '<(data_reduction_proxy_alt_fallback_origin)',
@@ -2752,6 +2756,10 @@
'defines': [
'DATA_REDUCTION_PROXY_PROBE_URL="<(data_reduction_proxy_probe_url)"'],
}],
+ ['data_reduction_proxy_warmup_url != ""', {
+ 'defines': [
+ 'DATA_REDUCTION_PROXY_WARMUP_URL="<(data_reduction_proxy_warmup_url)"'],
+ }],
['data_reduction_proxy_ssl_origin != ""', {
'defines': [
'DATA_REDUCTION_PROXY_SSL_ORIGIN="<(data_reduction_proxy_ssl_origin)"'],
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index 72ec539..c8fce3a 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -461,9 +461,11 @@ int ChromeNetworkDelegate::OnBeforeURLRequest(
// only non-null profiles are considered.
if (first_request_ && profile_) {
bool record_timing = true;
-#if defined(DATA_REDUCTION_PROXY_PROBE_URL)
- record_timing = (request->url() != GURL(DATA_REDUCTION_PROXY_PROBE_URL));
-#endif
+ if (data_reduction_proxy_params_) {
+ record_timing =
+ (request->url() != data_reduction_proxy_params_->probe_url()) &&
+ (request->url() != data_reduction_proxy_params_->warmup_url());
+ }
if (record_timing) {
first_request_ = false;
net::LoadTimingInfo timing_info;
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
index 65d97d9..84ff76d 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
@@ -45,7 +45,7 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
EXPECT_CALL(*settings, GetLocalStatePrefs())
.Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_));
- EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
settings_.reset(settings);
}
@@ -53,6 +53,7 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
template <class C>
void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult(
const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
@@ -60,11 +61,11 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult(
MockDataReductionProxySettings<C>* settings =
static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
if (0 == expected_calls) {
- EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
} else {
EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*settings, GetURLFetcher())
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
.Times(expected_calls)
.WillRepeatedly(Return(new net::FakeURLFetcher(
GURL(test_url),
@@ -86,6 +87,7 @@ data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
template void
data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult<
DataReductionProxySettingsAndroid>(const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
index 16e0d20..d3a3890 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
@@ -199,6 +199,8 @@ void DataReductionProxyParams::InitWithoutChecks() {
std::string probe_url = command_line.GetSwitchValueASCII(
switches::kDataReductionProxyProbeURL);
+ std::string warmup_url = command_line.GetSwitchValueASCII(
+ switches::kDataReductionProxyWarmupURL);
// Set from preprocessor constants those params that are not specified on the
// command line.
@@ -216,6 +218,8 @@ void DataReductionProxyParams::InitWithoutChecks() {
alt_fallback_origin = GetDefaultAltFallbackOrigin();
if (probe_url.empty())
probe_url = GetDefaultProbeURL();
+ if (warmup_url.empty())
+ warmup_url = GetDefaultWarmupURL();
origin_ = GURL(origin);
fallback_origin_ = GURL(fallback_origin);
@@ -223,6 +227,7 @@ void DataReductionProxyParams::InitWithoutChecks() {
alt_origin_ = GURL(alt_origin);
alt_fallback_origin_ = GURL(alt_fallback_origin);
probe_url_ = GURL(probe_url);
+ warmup_url_ = GURL(warmup_url);
}
@@ -342,4 +347,11 @@ std::string DataReductionProxyParams::GetDefaultProbeURL() const {
return std::string();
}
+std::string DataReductionProxyParams::GetDefaultWarmupURL() const {
+#if defined(DATA_REDUCTION_PROXY_WARMUP_URL)
+ return DATA_REDUCTION_PROXY_WARMUP_URL;
+#endif
+ return std::string();
+}
+
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h b/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
index 0285001..5ae00b8 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
@@ -58,8 +58,8 @@ class DataReductionProxyParams {
// bypassed or disabled. If |kAlternativeAllowed| then an alternative proxy
// configuration is allowed to be used. This alternative configuration would
// replace the primary and fallback proxy configurations if enabled. Finally
- // if |kPromoAllowed|, the client may show a promotion for the data
- // reduction proxy.
+ // if |kPromoAllowed|, the client may show a promotion for the data reduction
+ // proxy.
//
// A standard configuration has a primary proxy, and a fallback proxy for
// HTTP traffic. The alternative configuration has a different primary and
@@ -119,6 +119,11 @@ class DataReductionProxyParams {
return probe_url_;
}
+ // Returns the URL to fetch to warm the data reduction proxy connection.
+ const GURL& warmup_url() const {
+ return warmup_url_;
+ }
+
// Set the proxy authentication key.
void set_key(const std::string& key) {
key_ = key;
@@ -180,6 +185,7 @@ class DataReductionProxyParams {
virtual std::string GetDefaultAltOrigin() const;
virtual std::string GetDefaultAltFallbackOrigin() const;
virtual std::string GetDefaultProbeURL() const;
+ virtual std::string GetDefaultWarmupURL() const;
private:
GURL origin_;
@@ -188,6 +194,7 @@ class DataReductionProxyParams {
GURL alt_origin_;
GURL alt_fallback_origin_;
GURL probe_url_;
+ GURL warmup_url_;
std::string key_;
@@ -196,7 +203,6 @@ class DataReductionProxyParams {
bool alt_allowed_;
const bool promo_allowed_;
-
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
};
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
index 5fc9213e..dc87a52 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
@@ -304,6 +304,13 @@ DataReductionProxySettings::GetDailyReceivedContentLengths() {
void DataReductionProxySettings::OnURLFetchComplete(
const net::URLFetcher* source) {
DCHECK(thread_checker_.CalledOnValidThread());
+
+ // The purpose of sending a request for the warmup URL is to warm the
+ // connection to the data_reduction_proxy. The result is ignored.
+ if (source == warmup_fetcher_.get())
+ return;
+
+ DCHECK(source == fetcher_.get());
net::URLRequestStatus status = source->GetStatus();
if (status.status() == net::URLRequestStatus::FAILED &&
status.error() == net::ERR_INTERNET_DISCONNECTED) {
@@ -399,6 +406,7 @@ void DataReductionProxySettings::OnIPAddressChanged() {
if (enabled_by_user_) {
DCHECK(params_->allowed());
ProbeWhetherDataReductionProxyIsAvailable();
+ WarmProxyConnection();
}
}
@@ -451,8 +459,10 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy(
at_startup);
// Check if the proxy has been restricted explicitly by the carrier.
- if (enabled_by_user_)
+ if (enabled_by_user_) {
ProbeWhetherDataReductionProxyIsAvailable();
+ WarmProxyConnection();
+ }
}
void DataReductionProxySettings::SetProxyConfigs(bool enabled,
@@ -581,12 +591,15 @@ base::string16 DataReductionProxySettings::AuthHashForSalt(
return base::UTF8ToUTF16(base::MD5String(salted_key));
}
-net::URLFetcher* DataReductionProxySettings::GetURLFetcher() {
- DCHECK(url_request_context_getter_);
- net::URLFetcher* fetcher = net::URLFetcher::Create(params_->probe_url(),
+net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
+ const GURL& gurl,
+ int load_flags) {
+
+ net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
net::URLFetcher::GET,
this);
- fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
+ fetcher->SetLoadFlags(load_flags);
+ DCHECK(url_request_context_getter_);
fetcher->SetRequestContext(url_request_context_getter_);
// Configure max retries to be at most kMaxRetries times for 5xx errors.
static const int kMaxRetries = 5;
@@ -595,12 +608,32 @@ net::URLFetcher* DataReductionProxySettings::GetURLFetcher() {
return fetcher;
}
+
+net::URLFetcher*
+DataReductionProxySettings::GetURLFetcherForAvailabilityCheck() {
+ return GetBaseURLFetcher(params_->probe_url(),
+ net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
+}
+
+
void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
- net::URLFetcher* fetcher = GetURLFetcher();
+ net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck();
if (!fetcher)
return;
fetcher_.reset(fetcher);
fetcher_->Start();
}
+net::URLFetcher* DataReductionProxySettings::GetURLFetcherForWarmup() {
+ return GetBaseURLFetcher(params_->warmup_url(), net::LOAD_DISABLE_CACHE);
+}
+
+void DataReductionProxySettings::WarmProxyConnection() {
+ net::URLFetcher* fetcher = GetURLFetcherForWarmup();
+ if (!fetcher)
+ return;
+ warmup_fetcher_.reset(fetcher);
+ warmup_fetcher_->Start();
+}
+
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
index c7fb154..eb68f67 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
@@ -173,7 +173,13 @@ class DataReductionProxySettings
protected:
void InitPrefMembers();
- virtual net::URLFetcher* GetURLFetcher();
+ // Returns a fetcher for the probe to check if OK for the proxy to use SPDY.
+ // Virtual for testing.
+ virtual net::URLFetcher* GetURLFetcherForAvailabilityCheck();
+
+ // Returns a fetcher to warm up the connection to the data reduction proxy.
+ // Virtual for testing.
+ virtual net::URLFetcher* GetURLFetcherForWarmup();
// Virtualized for unit test support.
virtual PrefService* GetOriginalProfilePrefs();
@@ -273,6 +279,12 @@ class DataReductionProxySettings
// failure.
void ProbeWhetherDataReductionProxyIsAvailable();
+ // Warms the connection to the data reduction proxy.
+ void WarmProxyConnection();
+
+ // Generic method to get a URL fetcher.
+ net::URLFetcher* GetBaseURLFetcher(const GURL& gurl, int load_flags);
+
// Returns a UTF16 string that's the hash of the configured authentication
// |key| and |salt|. Returns an empty UTF16 string if no key is configured or
// the data reduction proxy feature isn't available.
@@ -284,6 +296,8 @@ class DataReductionProxySettings
bool enabled_by_user_;
scoped_ptr<net::URLFetcher> fetcher_;
+ scoped_ptr<net::URLFetcher> warmup_fetcher_;
+
BooleanPrefMember spdy_proxy_auth_enabled_;
BooleanPrefMember data_reduction_proxy_alternative_enabled_;
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc
index a985683..62a5d4b 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc
@@ -23,6 +23,7 @@ const char kDataReductionProxyFallback[] = "http://bar.com:80/";
const char kDataReductionProxyKey[] = "12345";
const char kProbeURLWithOKResponse[] = "http://ok.org/";
+const char kWarmupURLWithNoContentResponse[] = "http://warm.org/";
const char kProxy[] = "proxy";
@@ -151,7 +152,8 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
EXPECT_CALL(*settings, GetLocalStatePrefs())
.Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_));
- EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
settings_.reset(settings);
settings_->configurator_.reset(new TestDataReductionProxyConfig());
@@ -165,6 +167,7 @@ DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
template <class C>
void DataReductionProxySettingsTestBase::SetProbeResult(
const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
@@ -172,11 +175,12 @@ void DataReductionProxySettingsTestBase::SetProbeResult(
MockDataReductionProxySettings<C>* settings =
static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
if (0 == expected_calls) {
- EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
+ EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
} else {
EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*settings, GetURLFetcher())
+ EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
.Times(expected_calls)
.WillRepeatedly(Return(new net::FakeURLFetcher(
GURL(test_url),
@@ -185,6 +189,15 @@ void DataReductionProxySettingsTestBase::SetProbeResult(
success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
success ? net::URLRequestStatus::SUCCESS :
net::URLRequestStatus::FAILED)));
+ EXPECT_CALL(*settings, GetURLFetcherForWarmup())
+ .Times(expected_calls)
+ .WillRepeatedly(Return(new net::FakeURLFetcher(
+ GURL(warmup_test_url),
+ settings,
+ "",
+ success ? net::HTTP_NO_CONTENT : net::HTTP_INTERNAL_SERVER_ERROR,
+ success ? net::URLRequestStatus::SUCCESS :
+ net::URLRequestStatus::FAILED)));
}
}
@@ -192,6 +205,7 @@ void DataReductionProxySettingsTestBase::SetProbeResult(
template void
DataReductionProxySettingsTestBase::SetProbeResult<DataReductionProxySettings>(
const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
@@ -212,6 +226,7 @@ void DataReductionProxySettingsTestBase::CheckProxyConfigs(
void DataReductionProxySettingsTestBase::CheckProbe(
bool initially_enabled,
const std::string& probe_url,
+ const std::string& warmup_url,
const std::string& response,
bool request_succeeded,
bool expected_enabled,
@@ -223,6 +238,7 @@ void DataReductionProxySettingsTestBase::CheckProbe(
settings_->enabled_by_user_ = true;
settings_->restricted_by_carrier_ = false;
SetProbeResult(probe_url,
+ warmup_url,
response,
FetchResult(initially_enabled,
request_succeeded && (response == "OK")),
@@ -237,11 +253,13 @@ void DataReductionProxySettingsTestBase::CheckProbe(
void DataReductionProxySettingsTestBase::CheckProbeOnIPChange(
const std::string& probe_url,
+ const std::string& warmup_url,
const std::string& response,
bool request_succeeded,
bool expected_restricted,
bool expected_fallback_restricted) {
SetProbeResult(probe_url,
+ warmup_url,
response,
FetchResult(!settings_->restricted_by_carrier_,
request_succeeded && (response == "OK")),
@@ -258,6 +276,7 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange(
bool managed) {
// Always have a sucessful probe for pref change tests.
SetProbeResult(kProbeURLWithOKResponse,
+ kWarmupURLWithNoContentResponse,
"OK",
FetchResult(enabled, true),
true,
@@ -277,6 +296,7 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
bool enabled_at_startup) {
base::MessageLoopForUI loop;
SetProbeResult(kProbeURLWithOKResponse,
+ kWarmupURLWithNoContentResponse,
"OK",
FetchResult(enabled_at_startup, true),
true,
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h
index eae8bae..fbe4d45 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h
@@ -61,7 +61,8 @@ class MockDataReductionProxySettings : public C {
DataReductionProxyParams::kPromoAllowed)) {}
MockDataReductionProxySettings<C>(int flags)
: C(new DataReductionProxyParams(flags)) {}
- MOCK_METHOD0(GetURLFetcher, net::URLFetcher*());
+ MOCK_METHOD0(GetURLFetcherForAvailabilityCheck, net::URLFetcher*());
+ MOCK_METHOD0(GetURLFetcherForWarmup, net::URLFetcher*());
MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*());
MOCK_METHOD0(GetLocalStatePrefs, PrefService*());
MOCK_METHOD3(LogProxyState, void(
@@ -107,11 +108,13 @@ class DataReductionProxySettingsTestBase : public testing::Test {
template <class C> void SetProbeResult(
const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult state,
bool success,
int expected_calls);
virtual void SetProbeResult(const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
@@ -122,12 +125,14 @@ class DataReductionProxySettingsTestBase : public testing::Test {
bool expected_fallback_restricted);
void CheckProbe(bool initially_enabled,
const std::string& probe_url,
+ const std::string& warmup_url,
const std::string& response,
bool request_success,
bool expected_enabled,
bool expected_restricted,
bool expected_fallback_restricted);
void CheckProbeOnIPChange(const std::string& probe_url,
+ const std::string& warmup_url,
const std::string& response,
bool request_success,
bool expected_enabled,
@@ -157,12 +162,18 @@ class ConcreteDataReductionProxySettingsTest
}
virtual void SetProbeResult(const std::string& test_url,
+ const std::string& warmup_test_url,
const std::string& response,
ProbeURLFetchResult result,
bool success,
int expected_calls) OVERRIDE {
return DataReductionProxySettingsTestBase::SetProbeResult<C>(
- test_url, response, result, success, expected_calls);
+ test_url,
+ warmup_test_url,
+ response,
+ result,
+ success,
+ expected_calls);
}
};
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc
index fcb78fe..0dd2a6a 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc
@@ -31,6 +31,7 @@ const char kDataReductionProxySSL[] = "http://ssl.com:80";
const char kProbeURLWithOKResponse[] = "http://ok.org/";
const char kProbeURLWithBadResponse[] = "http://bad.org/";
const char kProbeURLWithNoResponse[] = "http://no.org/";
+const char kWarmupURLWithNoContentResponse[] = "http://warm.org/";
} // namespace
@@ -157,10 +158,10 @@ TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) {
TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
settings_->InitPrefMembers();
- base::MessageLoopForUI loop;
- // The proxy is disabled initially.
- settings_->enabled_by_user_ = false;
- settings_->SetProxyConfigs(false, false, false, false);
+ base::MessageLoopForUI loop;
+ // The proxy is disabled initially.
+ settings_->enabled_by_user_ = false;
+ settings_->SetProxyConfigs(false, false, false, false);
EXPECT_FALSE(settings_->IsDataReductionProxyEnabled());
EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
@@ -172,6 +173,8 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
CheckOnPrefChange(true, true, true);
EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
+
+ base::MessageLoop::current()->RunUntilIdle();
}
TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) {
@@ -309,14 +312,42 @@ TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) {
base::MessageLoopForUI loop;
// The proxy is enabled and unrestructed initially.
// Request succeeded but with bad response, expect proxy to be restricted.
- CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false);
+ CheckProbe(true,
+ kProbeURLWithBadResponse,
+ kWarmupURLWithNoContentResponse,
+ "Bad",
+ true,
+ true,
+ true,
+ false);
// Request succeeded with valid response, expect proxy to be unrestricted.
- CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false);
+ CheckProbe(true,
+ kProbeURLWithOKResponse,
+ kWarmupURLWithNoContentResponse,
+ "OK",
+ true,
+ true,
+ false,
+ false);
// Request failed, expect proxy to be enabled but restricted.
- CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false);
+ CheckProbe(true,
+ kProbeURLWithNoResponse,
+ kWarmupURLWithNoContentResponse,
+ "",
+ false,
+ true,
+ true,
+ false);
// The proxy is disabled initially. Probes should not be emitted to change
// state.
- CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false);
+ CheckProbe(false,
+ kProbeURLWithOKResponse,
+ kWarmupURLWithNoContentResponse,
+ "OK",
+ true,
+ false,
+ false,
+ false);
}
TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
@@ -334,13 +365,33 @@ TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
settings_->SetProxyConfigs(true, false, false, true);
// IP address change triggers a probe that succeeds. Proxy remains
// unrestricted.
- CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false);
+ CheckProbeOnIPChange(kProbeURLWithOKResponse,
+ kWarmupURLWithNoContentResponse,
+ "OK",
+ true,
+ false,
+ false);
// IP address change triggers a probe that fails. Proxy is restricted.
- CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false);
+ CheckProbeOnIPChange(kProbeURLWithBadResponse,
+ kWarmupURLWithNoContentResponse,
+ "Bad",
+ true,
+ true,
+ false);
// IP address change triggers a probe that fails. Proxy remains restricted.
- CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false);
+ CheckProbeOnIPChange(kProbeURLWithBadResponse,
+ kWarmupURLWithNoContentResponse,
+ "Bad",
+ true,
+ true,
+ false);
// IP address change triggers a probe that succeed. Proxy is unrestricted.
- CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false);
+ CheckProbeOnIPChange(kProbeURLWithBadResponse,
+ kWarmupURLWithNoContentResponse,
+ "OK",
+ true,
+ false,
+ false);
}
TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) {
diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc b/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc
index 780dbeb..1dd1df7 100644
--- a/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc
+++ b/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc
@@ -30,6 +30,10 @@ const char kDataReductionProxyKey[] = "spdy-proxy-auth-value";
// proxy. Note this canary does not go through the data reduction proxy.
const char kDataReductionProxyProbeURL[] = "data-reduction-proxy-probe-url";
+// Sets a URL to fetch to warm up the data reduction proxy on startup and
+// network changes.
+const char kDataReductionProxyWarmupURL[] = "data-reduction-proxy-warmup-url";
+
// The origin of the data reduction SSL proxy.
const char kDataReductionSSLProxy[] = "data-reduction-ssl-proxy";
diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_switches.h b/components/data_reduction_proxy/common/data_reduction_proxy_switches.h
index 3a68011..837a07f 100644
--- a/components/data_reduction_proxy/common/data_reduction_proxy_switches.h
+++ b/components/data_reduction_proxy/common/data_reduction_proxy_switches.h
@@ -18,6 +18,7 @@ extern const char kDataReductionProxyDev[];
extern const char kDataReductionProxyFallback[];
extern const char kDataReductionProxyKey[];
extern const char kDataReductionProxyProbeURL[];
+extern const char kDataReductionProxyWarmupURL[];
extern const char kDataReductionSSLProxy[];
extern const char kDisableDataReductionProxyDev[];
extern const char kEnableDataReductionProxyDev[];