diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp index 388ac3fbaf9..effaafe4fae 100755 --- a/toolkit/crashreporter/nsExceptionHandler.cpp +++ b/toolkit/crashreporter/nsExceptionHandler.cpp @@ -66,6 +66,7 @@ #endif #include +#include #include #include #include "nsDebug.h" @@ -399,21 +400,33 @@ typedef nsresult (*InitDataFunc)(nsACString&); // does not exist, create it and initialize its contents // by calling aInitFunc for the data. static nsresult -GetOrInit(nsIFile* aFile, nsACString& aContents, InitDataFunc aInitFunc) +GetOrInit(nsILocalFile* aDir, const nsAString& filename, + nsACString& aContents, InitDataFunc aInitFunc) { PRBool exists; - nsresult rv = aFile->Exists(&exists); + + nsCOMPtr dataFile; + nsresult rv = aDir->Clone(getter_AddRefs(dataFile)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = dataFile->Append(filename); + NS_ENSURE_SUCCESS(rv, rv); + + rv = dataFile->Exists(&exists); NS_ENSURE_SUCCESS(rv, rv); if (!exists) { // get the initial value and write it to the file rv = aInitFunc(aContents); NS_ENSURE_SUCCESS(rv, rv); - return WriteDataToFile(aFile, aContents); + rv = WriteDataToFile(dataFile, aContents); + } + else { + // just get the file's contents + rv = GetFileContents(dataFile, aContents); } - // just get the file's contents - return GetFileContents(aFile, aContents); + return rv; } // Generate a unique user ID. We're using a GUID form, @@ -453,23 +466,40 @@ InitUserID(nsACString& aUserID) return NS_OK; } +// Init the "install time" data. We're taking an easy way out here +// and just setting this to "the time when this version was first run". +static nsresult +InitInstallTime(nsACString& aInstallTime) +{ + time_t t = time(NULL); + char buf[16]; + sprintf(buf, "%ld", t); + aInstallTime = buf; + + return NS_OK; +} + // Annotate the crash report with a Unique User ID. // TODO: also add time since install, and time since last crash. // (bug 376720 and bug 376721) // If any piece of data doesn't exist, initialize it first. -nsresult SetupExtraData(nsILocalFile* aAppDataDirectory) +nsresult SetupExtraData(nsILocalFile* aAppDataDirectory, + const nsACString& aBuildID) { nsresult rv = aAppDataDirectory->Append(NS_LITERAL_STRING("Crash Reports")); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr userIDfile; - if (NS_SUCCEEDED(aAppDataDirectory->Clone(getter_AddRefs(userIDfile))) - && NS_SUCCEEDED(userIDfile->Append(NS_LITERAL_STRING("UserID")))) { - nsCAutoString userID; - if (NS_SUCCEEDED(GetOrInit(userIDfile, userID, InitUserID))) { - AnnotateCrashReport(NS_LITERAL_CSTRING("UserID"), userID); - } - } + nsCAutoString data; + if(NS_SUCCEEDED(GetOrInit(aAppDataDirectory, NS_LITERAL_STRING("UserID"), + data, InitUserID))) + AnnotateCrashReport(NS_LITERAL_CSTRING("UserID"), data); + + if(NS_SUCCEEDED(GetOrInit(aAppDataDirectory, + NS_LITERAL_STRING("InstallTime") + + NS_ConvertASCIItoUTF16(aBuildID), + data, InitInstallTime))) + AnnotateCrashReport(NS_LITERAL_CSTRING("InstallTime"), data); + return NS_OK; } diff --git a/toolkit/crashreporter/nsExceptionHandler.h b/toolkit/crashreporter/nsExceptionHandler.h index 6f9b38b901c..a85bce4c04c 100644 --- a/toolkit/crashreporter/nsExceptionHandler.h +++ b/toolkit/crashreporter/nsExceptionHandler.h @@ -49,7 +49,8 @@ nsresult SetMinidumpPath(const nsAString& aPath); nsresult UnsetExceptionHandler(); nsresult AnnotateCrashReport(const nsACString &key, const nsACString &data); nsresult SetRestartArgs(int argc, char **argv); -nsresult SetupExtraData(nsILocalFile* aAppDataDirectory); +nsresult SetupExtraData(nsILocalFile* aAppDataDirectory, + const nsACString& aBuildID); } #endif /* nsAirbagExceptionHandler_h__ */