зеркало из https://github.com/mozilla/pjs.git
bug 290254 - search engine isn't validated for the first time until updateCheckDays after first use, r=me, sr=neil
This commit is contained in:
Родитель
2132d92f46
Коммит
5ecc547097
|
@ -3891,6 +3891,28 @@ InternetSearchDataSource::validateEngine(nsIRDFResource *engine)
|
||||||
PRInt32 updateCheckSecs = updateCheckDays * 60;
|
PRInt32 updateCheckSecs = updateCheckDays * 60;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
nsCOMPtr<nsIRDFNode> aNode;
|
||||||
|
rv = mLocalstore->GetTarget(engine, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(aNode));
|
||||||
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
|
||||||
|
// if aNode is a valid entry, we should check the durationSecs.
|
||||||
|
if (rv != NS_RDF_NO_VALUE) {
|
||||||
|
// get last validate date/time
|
||||||
|
nsCOMPtr<nsIRDFLiteral> lastCheckLiteral(do_QueryInterface(aNode));
|
||||||
|
if (!lastCheckLiteral)
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
|
||||||
|
const PRUnichar *lastCheckUni = nsnull;
|
||||||
|
lastCheckLiteral->GetValueConst(&lastCheckUni);
|
||||||
|
if (!lastCheckUni)
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
|
||||||
|
PRInt32 lastCheckInt = 0, err = 0;
|
||||||
|
lastCheckInt = nsDependentString(lastCheckUni).ToInteger(&err);
|
||||||
|
// signed int32 -> unsigned int32
|
||||||
|
rv = (nsresult) err;
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// get the current date/time [from microseconds (PRTime) to seconds]
|
// get the current date/time [from microseconds (PRTime) to seconds]
|
||||||
PRTime now64 = PR_Now(), temp64, million;
|
PRTime now64 = PR_Now(), temp64, million;
|
||||||
LL_I2L(million, PR_USEC_PER_SEC);
|
LL_I2L(million, PR_USEC_PER_SEC);
|
||||||
|
@ -3898,43 +3920,17 @@ InternetSearchDataSource::validateEngine(nsIRDFResource *engine)
|
||||||
PRInt32 now32;
|
PRInt32 now32;
|
||||||
LL_L2I(now32, temp64);
|
LL_L2I(now32, temp64);
|
||||||
|
|
||||||
nsCOMPtr<nsIRDFNode> aNode;
|
// calculate duration since last validation
|
||||||
rv = mLocalstore->GetTarget(engine, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(aNode));
|
// just return if it's too early to check again
|
||||||
if (NS_FAILED(rv)) return(rv);
|
|
||||||
if (rv == NS_RDF_NO_VALUE)
|
|
||||||
{
|
|
||||||
// if we've never validated this engine before,
|
|
||||||
// then start its epoch as of now
|
|
||||||
validateEngineNow(engine);
|
|
||||||
|
|
||||||
#ifdef DEBUG_SEARCH_UPDATES
|
|
||||||
printf(" Search engine '%s' marked valid as of now.\n", engineURI);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return(NS_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get last validate date/time
|
|
||||||
nsCOMPtr<nsIRDFLiteral> lastCheckLiteral (do_QueryInterface(aNode));
|
|
||||||
if (!lastCheckLiteral) return(NS_ERROR_UNEXPECTED);
|
|
||||||
const PRUnichar *lastCheckUni = nsnull;
|
|
||||||
lastCheckLiteral->GetValueConst(&lastCheckUni);
|
|
||||||
if (!lastCheckUni) return(NS_ERROR_UNEXPECTED);
|
|
||||||
nsAutoString lastCheckStr(lastCheckUni);
|
|
||||||
PRInt32 lastCheckInt=0, err=0;
|
|
||||||
lastCheckInt = lastCheckStr.ToInteger(&err);
|
|
||||||
if (err) return(NS_ERROR_UNEXPECTED);
|
|
||||||
|
|
||||||
// calculate duration since last validation and
|
|
||||||
// just return if its too early to check again
|
|
||||||
PRInt32 durationSecs = now32 - lastCheckInt;
|
PRInt32 durationSecs = now32 - lastCheckInt;
|
||||||
if (durationSecs < updateCheckSecs)
|
|
||||||
{
|
if (durationSecs < updateCheckSecs) {
|
||||||
#ifdef DEBUG_SEARCH_UPDATES
|
#ifdef DEBUG_SEARCH_UPDATES
|
||||||
printf(" Search engine '%s' is valid for %d more seconds.\n",
|
printf(" Search engine '%s' is valid for %d more seconds.\n",
|
||||||
engineURI, (updateCheckSecs-durationSecs));
|
engineURI, (updateCheckSecs-durationSecs));
|
||||||
#endif
|
#endif
|
||||||
return(NS_OK);
|
return NS_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// search engine needs to be checked again, so add it into the to-be-validated array
|
// search engine needs to be checked again, so add it into the to-be-validated array
|
||||||
|
@ -3944,8 +3940,9 @@ InternetSearchDataSource::validateEngine(nsIRDFResource *engine)
|
||||||
mUpdateArray->AppendElement(engine);
|
mUpdateArray->AppendElement(engine);
|
||||||
|
|
||||||
#ifdef DEBUG_SEARCH_UPDATES
|
#ifdef DEBUG_SEARCH_UPDATES
|
||||||
printf(" Search engine '%s' is now queued to be validated via HTTP HEAD method.\n",
|
printf(" Search engine '%s' is now queued to be validated"
|
||||||
engineURI, durationSecs);
|
" via HTTP HEAD method.\n",
|
||||||
|
engineURI);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Загрузка…
Ссылка в новой задаче