From 0beec89aabebee2f12e18ebd57b444bc727fc6a5 Mon Sep 17 00:00:00 2001 From: "mconnor%steelgryphon.com" Date: Mon, 26 Sep 2005 15:05:17 +0000 Subject: [PATCH] bug 290254 - search engine isn't validated for the first time until updateCheckDays after first use, r=me, sr=neil, a=asa git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@180962 18797224-902f-48f8-a5cc-f745e15eee43 --- .../search/src/nsInternetSearchService.cpp | 79 +++++++++---------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp index eea80c3583e..a1f8b4959bd 100755 --- a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp @@ -3891,51 +3891,47 @@ InternetSearchDataSource::validateEngine(nsIRDFResource *engine) PRInt32 updateCheckSecs = updateCheckDays * 60; #endif - // get the current date/time [from microseconds (PRTime) to seconds] - PRTime now64 = PR_Now(), temp64, million; - LL_I2L(million, PR_USEC_PER_SEC); - LL_DIV(temp64, now64, million); - PRInt32 now32; - LL_L2I(now32, temp64); - nsCOMPtr aNode; rv = mLocalstore->GetTarget(engine, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(aNode)); 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); + // if aNode is a valid entry, we should check the durationSecs. + if (rv != NS_RDF_NO_VALUE) { + // get last validate date/time + nsCOMPtr 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] + PRTime now64 = PR_Now(), temp64, million; + LL_I2L(million, PR_USEC_PER_SEC); + LL_DIV(temp64, now64, million); + PRInt32 now32; + LL_L2I(now32, temp64); + + // calculate duration since last validation + // just return if it's too early to check again + PRInt32 durationSecs = now32 - lastCheckInt; + + if (durationSecs < updateCheckSecs) { #ifdef DEBUG_SEARCH_UPDATES - printf(" Search engine '%s' marked valid as of now.\n", engineURI); + printf(" Search engine '%s' is valid for %d more seconds.\n", + engineURI, (updateCheckSecs-durationSecs)); #endif - - return(NS_OK); - } - - // get last validate date/time - nsCOMPtr 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; - if (durationSecs < updateCheckSecs) - { -#ifdef DEBUG_SEARCH_UPDATES - printf(" Search engine '%s' is valid for %d more seconds.\n", - engineURI, (updateCheckSecs-durationSecs)); -#endif - return(NS_OK); - } + return NS_OK; + } + } // search engine needs to be checked again, so add it into the to-be-validated array PRInt32 elementIndex = mUpdateArray->IndexOf(engine); @@ -3944,8 +3940,9 @@ InternetSearchDataSource::validateEngine(nsIRDFResource *engine) mUpdateArray->AppendElement(engine); #ifdef DEBUG_SEARCH_UPDATES - printf(" Search engine '%s' is now queued to be validated via HTTP HEAD method.\n", - engineURI, durationSecs); + printf(" Search engine '%s' is now queued to be validated" + " via HTTP HEAD method.\n", + engineURI); #endif } else