bug 376720 - send time-since-install with crash report

This commit is contained in:
ted.mielczarek%gmail.com 2007-07-25 01:07:15 +00:00
Родитель b07d1f8bad
Коммит c8cc7dd03c
2 изменённых файлов: 46 добавлений и 15 удалений

Просмотреть файл

@ -66,6 +66,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <prenv.h> #include <prenv.h>
#include <prio.h> #include <prio.h>
#include "nsDebug.h" #include "nsDebug.h"
@ -399,21 +400,33 @@ typedef nsresult (*InitDataFunc)(nsACString&);
// does not exist, create it and initialize its contents // does not exist, create it and initialize its contents
// by calling aInitFunc for the data. // by calling aInitFunc for the data.
static nsresult static nsresult
GetOrInit(nsIFile* aFile, nsACString& aContents, InitDataFunc aInitFunc) GetOrInit(nsILocalFile* aDir, const nsAString& filename,
nsACString& aContents, InitDataFunc aInitFunc)
{ {
PRBool exists; PRBool exists;
nsresult rv = aFile->Exists(&exists);
nsCOMPtr<nsIFile> 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); NS_ENSURE_SUCCESS(rv, rv);
if (!exists) { if (!exists) {
// get the initial value and write it to the file // get the initial value and write it to the file
rv = aInitFunc(aContents); rv = aInitFunc(aContents);
NS_ENSURE_SUCCESS(rv, rv); 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 rv;
return GetFileContents(aFile, aContents);
} }
// Generate a unique user ID. We're using a GUID form, // Generate a unique user ID. We're using a GUID form,
@ -453,23 +466,40 @@ InitUserID(nsACString& aUserID)
return NS_OK; 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. // Annotate the crash report with a Unique User ID.
// TODO: also add time since install, and time since last crash. // TODO: also add time since install, and time since last crash.
// (bug 376720 and bug 376721) // (bug 376720 and bug 376721)
// If any piece of data doesn't exist, initialize it first. // 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")); nsresult rv = aAppDataDirectory->Append(NS_LITERAL_STRING("Crash Reports"));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> userIDfile; nsCAutoString data;
if (NS_SUCCEEDED(aAppDataDirectory->Clone(getter_AddRefs(userIDfile))) if(NS_SUCCEEDED(GetOrInit(aAppDataDirectory, NS_LITERAL_STRING("UserID"),
&& NS_SUCCEEDED(userIDfile->Append(NS_LITERAL_STRING("UserID")))) { data, InitUserID)))
nsCAutoString userID; AnnotateCrashReport(NS_LITERAL_CSTRING("UserID"), data);
if (NS_SUCCEEDED(GetOrInit(userIDfile, userID, InitUserID))) {
AnnotateCrashReport(NS_LITERAL_CSTRING("UserID"), userID); if(NS_SUCCEEDED(GetOrInit(aAppDataDirectory,
} NS_LITERAL_STRING("InstallTime") +
} NS_ConvertASCIItoUTF16(aBuildID),
data, InitInstallTime)))
AnnotateCrashReport(NS_LITERAL_CSTRING("InstallTime"), data);
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -49,7 +49,8 @@ nsresult SetMinidumpPath(const nsAString& aPath);
nsresult UnsetExceptionHandler(); nsresult UnsetExceptionHandler();
nsresult AnnotateCrashReport(const nsACString &key, const nsACString &data); nsresult AnnotateCrashReport(const nsACString &key, const nsACString &data);
nsresult SetRestartArgs(int argc, char **argv); nsresult SetRestartArgs(int argc, char **argv);
nsresult SetupExtraData(nsILocalFile* aAppDataDirectory); nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
const nsACString& aBuildID);
} }
#endif /* nsAirbagExceptionHandler_h__ */ #endif /* nsAirbagExceptionHandler_h__ */