Bug 509747 - Thunderbird 3.0b4pre checks for new mail every 30 seconds regardless of account settings; (Av1) Force 64-bit multiplication, fix nits; r+sr=bienvenu
authorSerge Gautherie <sgautherie.bz@free.fr>
Fri, 14 Aug 2009 18:00:43 +0200
changeset 3307 9e6af989f3623ddbb9cd51de5d7126039651849d
parent 3306 ccf2369fb4c76bb982701770ff1d0bb21905c2a4
child 3308 ee7ce2ff0a5d01edff4298f1952f5265a1a15166
push idunknown
push userunknown
push dateunknown
bugs509747
Bug 509747 - Thunderbird 3.0b4pre checks for new mail every 30 seconds regardless of account settings; (Av1) Force 64-bit multiplication, fix nits; r+sr=bienvenu
mailnews/base/src/nsMsgBiffManager.cpp
mailnews/base/src/nsMsgBiffManager.h
--- a/mailnews/base/src/nsMsgBiffManager.cpp
+++ b/mailnews/base/src/nsMsgBiffManager.cpp
@@ -221,44 +221,44 @@ nsresult nsMsgBiffManager::AddBiffEntry(
     if (biffEntry.nextBiffTime < mBiffArray[i].nextBiffTime)
       break;
   }
   PR_LOG(MsgBiffLogModule, PR_LOG_ALWAYS, ("inserting biff entry at %d\n", i));
   mBiffArray.InsertElementAt(i, biffEntry);
   return NS_OK;
 }
 
-nsresult nsMsgBiffManager::SetNextBiffTime(nsBiffEntry &biffEntry, nsTime startTime)
+nsresult nsMsgBiffManager::SetNextBiffTime(nsBiffEntry &biffEntry, const nsTime currentTime)
 {
   nsIMsgIncomingServer *server = biffEntry.server;
   if (!server)
     return NS_ERROR_FAILURE;
 
   PRInt32 biffInterval;
   nsresult rv = server->GetBiffMinutes(&biffInterval);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Add biffInterval, converted in microseconds, to current time.
-  // biffEntry.nextBiffTime's constructor makes it the current time.
-  nsTime chosenTimeInterval = biffInterval * 60000000;
-  biffEntry.nextBiffTime = startTime + chosenTimeInterval;
+  // Force 64-bit multiplication.
+  nsTime chosenTimeInterval = biffInterval * 60000000LL;
+  biffEntry.nextBiffTime = currentTime + chosenTimeInterval;
 
   // Check if we should jitter.
   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (prefs)
   {
     PRBool shouldUseBiffJitter = PR_FALSE;
     prefs->GetBoolPref(PREF_BIFF_JITTER, &shouldUseBiffJitter);
     if (shouldUseBiffJitter)
     {
       // Calculate a jitter of +/-5% on chosenTimeInterval
       // - minimum 1 second (to avoid a modulo with 0)
       // - maximum 30 seconds (to avoid problems when biffInterval is very large)
       PRInt64 jitter = (PRInt64)(0.05 * (PRInt64)chosenTimeInterval);
-      jitter = PR_MAX(1000000, PR_MIN(jitter, 30000000));
+      jitter = PR_MAX(1000000LL, PR_MIN(jitter, 30000000LL));
       jitter = ((rand() % 2) ? 1 : -1) * (rand() % jitter);
 
       biffEntry.nextBiffTime += jitter;
     }
   }
 
   return NS_OK;
 }
--- a/mailnews/base/src/nsMsgBiffManager.h
+++ b/mailnews/base/src/nsMsgBiffManager.h
@@ -65,23 +65,20 @@ public:
 	NS_DECL_ISUPPORTS
 	NS_DECL_NSIMSGBIFFMANAGER
 	NS_DECL_NSIINCOMINGSERVERLISTENER
 
 	nsresult PerformBiff();
 
 protected:
 	PRInt32 FindServer(nsIMsgIncomingServer *server);
-	nsresult SetNextBiffTime(nsBiffEntry &biffEntry, nsTime startTime);
+	nsresult SetNextBiffTime(nsBiffEntry &biffEntry, const nsTime currentTime);
 	nsresult SetupNextBiff();
 	nsresult AddBiffEntry(nsBiffEntry &biffEntry);
 
 protected:
   nsCOMPtr<nsITimer> mBiffTimer;
   nsTArray<nsBiffEntry> mBiffArray;
   PRBool mHaveShutdown;
   PRBool mInited;
 };
 
-
-
-#endif
-
+#endif // NSMSGBIFFMANAGER_H