about:startup - cache app launch timestamp
authorDaniel Brooks <db48x@db48x.net>
Sun, 24 Oct 2010 11:24:09 -0500
changeset 58859 4727f6e61ee658d78af0a9cf30054f44cff1e5dc
parent 58858 a70bc23ad10f0e53e547a592d4dee7a6410b5407
child 58860 6b47fb70ea30405f3b29acf4996ad06036a55732
push idunknown
push userunknown
push dateunknown
milestone2.0b7pre
about:startup - cache app launch timestamp
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -834,16 +834,22 @@ nsXULAppInfo::InvalidateCachesOnRestart(
       return rv;
   }
   return NS_OK;
 }
 
 /* readonly attribute unsigned long launchTimestamp; */
 NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
 {
+  static PRUint64 cached = 0;
+  if (cached)
+  {
+    *aTimestamp = cached;
+    return NS_OK;
+  }
 #ifdef XP_UNIX
   FILE *uptime;
   long tickspersecond = sysconf(_SC_CLK_TCK);
   unsigned long long sec, ssec;
 
   uptime = fopen("/proc/uptime", "r");
   fscanf(uptime, "%lld.%lld", &sec, &ssec);
   PRTime boottime = PR_Now() - (((sec * PR_MSEC_PER_SEC) + (ssec * 10)) * PR_USEC_PER_MSEC);
@@ -865,29 +871,29 @@ NS_IMETHODIMP nsXULAppInfo::GetLaunchTim
   PR_smprintf_free(statpath);
 
   PRTime starttime = 0;
   sscanf(strrchr(stat, ')') + 2,
          "%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u "
          "%*u %*u %*u %*u %*u %*d %*d %*d %*d %llu",
          &starttime);
 
-  *aTimestamp = boottime + ((starttime / tickspersecond) * PR_USEC_PER_SEC);
+  *aTimestamp = cached = boottime + ((starttime / tickspersecond) * PR_USEC_PER_SEC);;
   return NS_OK;
 #elif XP_WIN
   FILETIME start, foo, bar, baz;
   bool success = GetProcessTimes(GetCurrentProcess(), &start, &foo, &bar, &baz);
   if (success)
   {
     // copied from NSPR _PR_FileTimeToPRTime
     CopyMemory(aTimestamp, &start, sizeof(PRTime));
 #ifdef __GNUC__
-    *aTimestamp = (*aTimestamp - 116444736000000000LL) / 10LL;
+    *aTimestamp = cached = (*aTimestamp - 116444736000000000LL) / 10LL;
 #else
-    *aTimestamp = (*aTimestamp - 116444736000000000i64) / 10i64;
+    *aTimestamp = cached = (*aTimestamp - 116444736000000000i64) / 10i64;
 #endif    
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }