зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1273882 - Don't prefetch on origin predictions. r=mayhemer
MozReview-Commit-ID: 13QQarCBaRr
This commit is contained in:
Родитель
d4291f218b
Коммит
f0f573815e
|
@ -142,6 +142,8 @@ static const char PREDICTOR_MAX_URI_LENGTH_PREF[] =
|
||||||
"network.predictor.max-uri-length";
|
"network.predictor.max-uri-length";
|
||||||
static const uint32_t PREDICTOR_MAX_URI_LENGTH_DEFAULT = 500;
|
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";
|
static const char PREDICTOR_CLEANED_UP_PREF[] = "network.predictor.cleaned-up";
|
||||||
|
|
||||||
// All these time values are in sec
|
// All these time values are in sec
|
||||||
|
@ -355,6 +357,7 @@ Predictor::Predictor()
|
||||||
,mMaxResourcesPerEntry(PREDICTOR_MAX_RESOURCES_DEFAULT)
|
,mMaxResourcesPerEntry(PREDICTOR_MAX_RESOURCES_DEFAULT)
|
||||||
,mStartupCount(1)
|
,mStartupCount(1)
|
||||||
,mMaxURILength(PREDICTOR_MAX_URI_LENGTH_DEFAULT)
|
,mMaxURILength(PREDICTOR_MAX_URI_LENGTH_DEFAULT)
|
||||||
|
,mDoingTests(false)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(!sSelf, "multiple Predictor instances!");
|
MOZ_ASSERT(!sSelf, "multiple Predictor instances!");
|
||||||
sSelf = this;
|
sSelf = this;
|
||||||
|
@ -455,6 +458,8 @@ Predictor::InstallObserver()
|
||||||
Preferences::AddUintVarCache(&mMaxURILength, PREDICTOR_MAX_URI_LENGTH_PREF,
|
Preferences::AddUintVarCache(&mMaxURILength, PREDICTOR_MAX_URI_LENGTH_PREF,
|
||||||
PREDICTOR_MAX_URI_LENGTH_DEFAULT);
|
PREDICTOR_MAX_URI_LENGTH_DEFAULT);
|
||||||
|
|
||||||
|
Preferences::AddBoolVarCache(&mDoingTests, PREDICTOR_DOING_TESTS_PREF, false);
|
||||||
|
|
||||||
if (!mCleanedUp) {
|
if (!mCleanedUp) {
|
||||||
mCleanupTimer = do_CreateInstance("@mozilla.org/timer;1");
|
mCleanupTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||||
mCleanupTimer->Init(this, 60 * 1000, nsITimer::TYPE_ONE_SHOT);
|
mCleanupTimer->Init(this, 60 * 1000, nsITimer::TYPE_ONE_SHOT);
|
||||||
|
@ -981,10 +986,10 @@ Predictor::PredictInternal(PredictorPredictReason reason, nsICacheEntry *entry,
|
||||||
|
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case nsINetworkPredictor::PREDICT_LOAD:
|
case nsINetworkPredictor::PREDICT_LOAD:
|
||||||
rv = PredictForPageload(entry, targetURI, stackCount, verifier);
|
rv = PredictForPageload(entry, targetURI, stackCount, fullUri, verifier);
|
||||||
break;
|
break;
|
||||||
case nsINetworkPredictor::PREDICT_STARTUP:
|
case nsINetworkPredictor::PREDICT_STARTUP:
|
||||||
rv = PredictForStartup(entry, verifier);
|
rv = PredictForStartup(entry, fullUri, verifier);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PREDICTOR_LOG((" invalid reason"));
|
PREDICTOR_LOG((" invalid reason"));
|
||||||
|
@ -1027,7 +1032,7 @@ Predictor::PredictForLink(nsIURI *targetURI, nsIURI *sourceURI,
|
||||||
static const uint8_t MAX_PAGELOAD_DEPTH = 10;
|
static const uint8_t MAX_PAGELOAD_DEPTH = 10;
|
||||||
bool
|
bool
|
||||||
Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
|
Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
|
||||||
uint8_t stackCount,
|
uint8_t stackCount, bool fullUri,
|
||||||
nsINetworkPredictorVerifier *verifier)
|
nsINetworkPredictorVerifier *verifier)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
@ -1073,7 +1078,7 @@ Predictor::PredictForPageload(nsICacheEntry *entry, nsIURI *targetURI,
|
||||||
return RunPredictions(nullptr, verifier);
|
return RunPredictions(nullptr, verifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
CalculatePredictions(entry, targetURI, lastLoad, loadCount, globalDegradation);
|
CalculatePredictions(entry, targetURI, lastLoad, loadCount, globalDegradation, fullUri);
|
||||||
|
|
||||||
return RunPredictions(targetURI, verifier);
|
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
|
// This is the driver for predicting at browser startup time based on pages that
|
||||||
// have previously been loaded close to startup.
|
// have previously been loaded close to startup.
|
||||||
bool
|
bool
|
||||||
Predictor::PredictForStartup(nsICacheEntry *entry,
|
Predictor::PredictForStartup(nsICacheEntry *entry, bool fullUri,
|
||||||
nsINetworkPredictorVerifier *verifier)
|
nsINetworkPredictorVerifier *verifier)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
@ -1089,7 +1094,7 @@ Predictor::PredictForStartup(nsICacheEntry *entry,
|
||||||
PREDICTOR_LOG(("Predictor::PredictForStartup"));
|
PREDICTOR_LOG(("Predictor::PredictForStartup"));
|
||||||
int32_t globalDegradation = CalculateGlobalDegradation(mLastStartupTime);
|
int32_t globalDegradation = CalculateGlobalDegradation(mLastStartupTime);
|
||||||
CalculatePredictions(entry, nullptr, mLastStartupTime, mStartupCount,
|
CalculatePredictions(entry, nullptr, mLastStartupTime, mStartupCount,
|
||||||
globalDegradation);
|
globalDegradation, fullUri);
|
||||||
return RunPredictions(nullptr, verifier);
|
return RunPredictions(nullptr, verifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,7 +1247,7 @@ Predictor::SanitizePrefs()
|
||||||
void
|
void
|
||||||
Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
|
Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
|
||||||
uint32_t lastLoad, uint32_t loadCount,
|
uint32_t lastLoad, uint32_t loadCount,
|
||||||
int32_t globalDegradation)
|
int32_t globalDegradation, bool fullUri)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
@ -1270,9 +1275,15 @@ Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
|
||||||
|
|
||||||
int32_t confidence = CalculateConfidence(hitCount, loadCount, lastHit,
|
int32_t confidence = CalculateConfidence(hitCount, loadCount, lastHit,
|
||||||
lastLoad, globalDegradation);
|
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));
|
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 referrer means we can't prefetch, so pretend it's non-cacheable,
|
||||||
// no matter what.
|
// no matter what.
|
||||||
PREDICTOR_LOG((" forcing non-cacheability - no referrer"));
|
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
|
// 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
|
// so that all the work that normally happens behind the scenes in a
|
||||||
// page load can be done for testing purposes.
|
// page load can be done for testing purposes.
|
||||||
if (fullUri) {
|
if (fullUri && mDoingTests) {
|
||||||
PREDICTOR_LOG((" WARNING - updating rolling load count. "
|
PREDICTOR_LOG((" WARNING - updating rolling load count. "
|
||||||
"If you see this outside tests, you did it wrong"));
|
"If you see this outside tests, you did it wrong"));
|
||||||
SanitizePrefs();
|
SanitizePrefs();
|
||||||
|
|
|
@ -265,12 +265,14 @@ private:
|
||||||
bool PredictForPageload(nsICacheEntry *entry,
|
bool PredictForPageload(nsICacheEntry *entry,
|
||||||
nsIURI *targetURI,
|
nsIURI *targetURI,
|
||||||
uint8_t stackCount,
|
uint8_t stackCount,
|
||||||
|
bool fullUri,
|
||||||
nsINetworkPredictorVerifier *verifier);
|
nsINetworkPredictorVerifier *verifier);
|
||||||
|
|
||||||
// Used when predicting pages that will be used near browser startup. All
|
// Used when predicting pages that will be used near browser startup. All
|
||||||
// arguments are the same as for PredictInternal. Returns true if any
|
// arguments are the same as for PredictInternal. Returns true if any
|
||||||
// predictions were queued up.
|
// predictions were queued up.
|
||||||
bool PredictForStartup(nsICacheEntry *entry,
|
bool PredictForStartup(nsICacheEntry *entry,
|
||||||
|
bool fullUri,
|
||||||
nsINetworkPredictorVerifier *verifier);
|
nsINetworkPredictorVerifier *verifier);
|
||||||
|
|
||||||
// Utilities related to prediction
|
// Utilities related to prediction
|
||||||
|
@ -316,9 +318,10 @@ private:
|
||||||
// * loadCount - number of times this page has been loaded
|
// * loadCount - number of times this page has been loaded
|
||||||
// * gloablDegradation - value calculated by CalculateGlobalDegradation for
|
// * gloablDegradation - value calculated by CalculateGlobalDegradation for
|
||||||
// this page
|
// this page
|
||||||
|
// * fullUri - whether we're predicting for a full URI or origin-only
|
||||||
void CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
|
void CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
|
||||||
uint32_t lastLoad, uint32_t loadCount,
|
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
|
// Used to prepare any necessary prediction for a resource on a page
|
||||||
// * confidence - value calculated by CalculateConfidence for this resource
|
// * confidence - value calculated by CalculateConfidence for this resource
|
||||||
|
@ -466,6 +469,8 @@ private:
|
||||||
nsTArray<nsCOMPtr<nsIURI>> mPreconnects;
|
nsTArray<nsCOMPtr<nsIURI>> mPreconnects;
|
||||||
nsTArray<nsCOMPtr<nsIURI>> mPreresolves;
|
nsTArray<nsCOMPtr<nsIURI>> mPreresolves;
|
||||||
|
|
||||||
|
bool mDoingTests;
|
||||||
|
|
||||||
static Predictor *sSelf;
|
static Predictor *sSelf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -568,6 +568,7 @@ function run_test_real() {
|
||||||
Services.prefs.setBoolPref("network.predictor.cleaned-up", true);
|
Services.prefs.setBoolPref("network.predictor.cleaned-up", true);
|
||||||
Services.prefs.setBoolPref("browser.cache.use_new_backend_temp", true);
|
Services.prefs.setBoolPref("browser.cache.use_new_backend_temp", true);
|
||||||
Services.prefs.setIntPref("browser.cache.use_new_backend", 1);
|
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);
|
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.preresolve-min-confidence");
|
||||||
Services.prefs.clearUserPref("network.predictor.enable-prefetch");
|
Services.prefs.clearUserPref("network.predictor.enable-prefetch");
|
||||||
Services.prefs.clearUserPref("network.predictor.prefetch-rolling-load-count");
|
Services.prefs.clearUserPref("network.predictor.prefetch-rolling-load-count");
|
||||||
|
Services.prefs.clearUserPref("network.predictor.doing-tests");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_next_test();
|
run_next_test();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче