Bug 1273882 - Don't prefetch on origin predictions. r=mayhemer

MozReview-Commit-ID: 13QQarCBaRr
This commit is contained in:
Nicholas Hurley 2016-06-08 14:13:39 -07:00
Родитель d4291f218b
Коммит f0f573815e
3 изменённых файлов: 29 добавлений и 11 удалений

Просмотреть файл

@ -142,6 +142,8 @@ static const char PREDICTOR_MAX_URI_LENGTH_PREF[] =
"network.predictor.max-uri-length";
static const uint32_t PREDICTOR_MAX_URI_LENGTH_DEFAULT = 500;
static const char PREDICTOR_DOING_TESTS_PREF[] = "network.predictor.doing-tests";
static const char PREDICTOR_CLEANED_UP_PREF[] = "network.predictor.cleaned-up";
// All these time values are in sec
@ -355,6 +357,7 @@ Predictor::Predictor()
,mMaxResourcesPerEntry(PREDICTOR_MAX_RESOURCES_DEFAULT)
,mStartupCount(1)
,mMaxURILength(PREDICTOR_MAX_URI_LENGTH_DEFAULT)
,mDoingTests(false)
{
MOZ_ASSERT(!sSelf, "multiple Predictor instances!");
sSelf = this;
@ -455,6 +458,8 @@ Predictor::InstallObserver()
Preferences::AddUintVarCache(&mMaxURILength, PREDICTOR_MAX_URI_LENGTH_PREF,
PREDICTOR_MAX_URI_LENGTH_DEFAULT);
Preferences::AddBoolVarCache(&mDoingTests, PREDICTOR_DOING_TESTS_PREF, false);
if (!mCleanedUp) {
mCleanupTimer = do_CreateInstance("@mozilla.org/timer;1");
mCleanupTimer->Init(this, 60 * 1000, nsITimer::TYPE_ONE_SHOT);
@ -981,10 +986,10 @@ Predictor::PredictInternal(PredictorPredictReason reason, nsICacheEntry *entry,
switch (reason) {
case nsINetworkPredictor::PREDICT_LOAD:
rv = PredictForPageload(entry, targetURI, stackCount, verifier);
rv = PredictForPageload(entry, targetURI, stackCount, fullUri, verifier);
break;
case nsINetworkPredictor::PREDICT_STARTUP:
rv = PredictForStartup(entry, verifier);
rv = PredictForStartup(entry, fullUri, verifier);
break;
default:
PREDICTOR_LOG((" invalid reason"));
@ -1027,7 +1032,7 @@ Predictor::PredictForLink(nsIURI *targetURI, nsIURI *sourceURI,
static const uint8_t MAX_PAGELOAD_DEPTH = 10;
bool
Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
uint8_t stackCount,
uint8_t stackCount, bool fullUri,
nsINetworkPredictorVerifier *verifier)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1073,7 +1078,7 @@ Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
return RunPredictions(nullptr, verifier);
}
CalculatePredictions(entry, targetURI, lastLoad, loadCount, globalDegradation);
CalculatePredictions(entry, targetURI, lastLoad, loadCount, globalDegradation, fullUri);
return RunPredictions(targetURI, verifier);
}
@ -1081,7 +1086,7 @@ Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
// This is the driver for predicting at browser startup time based on pages that
// have previously been loaded close to startup.
bool
Predictor::PredictForStartup(nsICacheEntry *entry,
Predictor::PredictForStartup(nsICacheEntry *entry, bool fullUri,
nsINetworkPredictorVerifier *verifier)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1089,7 +1094,7 @@ Predictor::PredictForStartup(nsICacheEntry *entry,
PREDICTOR_LOG(("Predictor::PredictForStartup"));
int32_t globalDegradation = CalculateGlobalDegradation(mLastStartupTime);
CalculatePredictions(entry, nullptr, mLastStartupTime, mStartupCount,
globalDegradation);
globalDegradation, fullUri);
return RunPredictions(nullptr, verifier);
}
@ -1242,7 +1247,7 @@ Predictor::SanitizePrefs()
void
Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
uint32_t lastLoad, uint32_t loadCount,
int32_t globalDegradation)
int32_t globalDegradation, bool fullUri)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1270,9 +1275,15 @@ Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
int32_t confidence = CalculateConfidence(hitCount, loadCount, lastHit,
lastLoad, globalDegradation);
UpdateRollingLoadCount(entry, flags, key, hitCount, lastHit);
if (fullUri) {
UpdateRollingLoadCount(entry, flags, key, hitCount, lastHit);
}
PREDICTOR_LOG(("CalculatePredictions key=%s value=%s confidence=%d", key, value, confidence));
if (!referrer) {
if (!fullUri) {
// Not full URI - don't prefetch! No sense in it!
PREDICTOR_LOG((" forcing non-cacheability - not full URI"));
flags &= ~FLAG_PREFETCHABLE;
} else if (!referrer) {
// No referrer means we can't prefetch, so pretend it's non-cacheable,
// no matter what.
PREDICTOR_LOG((" forcing non-cacheability - no referrer"));
@ -1645,7 +1656,7 @@ Predictor::LearnInternal(PredictorLearnReason reason, nsICacheEntry *entry,
// have no real page loads in xpcshell, and this is how we fake it up
// so that all the work that normally happens behind the scenes in a
// page load can be done for testing purposes.
if (fullUri) {
if (fullUri && mDoingTests) {
PREDICTOR_LOG((" WARNING - updating rolling load count. "
"If you see this outside tests, you did it wrong"));
SanitizePrefs();

Просмотреть файл

@ -265,12 +265,14 @@ private:
bool PredictForPageload(nsICacheEntry *entry,
nsIURI *targetURI,
uint8_t stackCount,
bool fullUri,
nsINetworkPredictorVerifier *verifier);
// Used when predicting pages that will be used near browser startup. All
// arguments are the same as for PredictInternal. Returns true if any
// predictions were queued up.
bool PredictForStartup(nsICacheEntry *entry,
bool fullUri,
nsINetworkPredictorVerifier *verifier);
// Utilities related to prediction
@ -316,9 +318,10 @@ private:
// * loadCount - number of times this page has been loaded
// * gloablDegradation - value calculated by CalculateGlobalDegradation for
// this page
// * fullUri - whether we're predicting for a full URI or origin-only
void CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
uint32_t lastLoad, uint32_t loadCount,
int32_t globalDegradation);
int32_t globalDegradation, bool fullUri);
// Used to prepare any necessary prediction for a resource on a page
// * confidence - value calculated by CalculateConfidence for this resource
@ -466,6 +469,8 @@ private:
nsTArray<nsCOMPtr<nsIURI>> mPreconnects;
nsTArray<nsCOMPtr<nsIURI>> mPreresolves;
bool mDoingTests;
static Predictor *sSelf;
};

Просмотреть файл

@ -568,6 +568,7 @@ function run_test_real() {
Services.prefs.setBoolPref("network.predictor.cleaned-up", true);
Services.prefs.setBoolPref("browser.cache.use_new_backend_temp", true);
Services.prefs.setIntPref("browser.cache.use_new_backend", 1);
Services.prefs.setBoolPref("network.predictor.doing-tests", true);
predictor = Cc["@mozilla.org/network/predictor;1"].getService(Ci.nsINetworkPredictor);
@ -582,6 +583,7 @@ function run_test_real() {
Services.prefs.clearUserPref("network.predictor.preresolve-min-confidence");
Services.prefs.clearUserPref("network.predictor.enable-prefetch");
Services.prefs.clearUserPref("network.predictor.prefetch-rolling-load-count");
Services.prefs.clearUserPref("network.predictor.doing-tests");
});
run_next_test();