Bug 717951 - Allow AppendAppNotesToCrashReport to be called from off the main thread in the chrome process. r=ted

This commit is contained in:
Ali Juma 2012-01-25 09:43:52 -05:00
parent 3cc60bc3bc
commit 68cc9e12bb
2 changed files with 16 additions and 3 deletions

View File

@ -216,6 +216,7 @@ static const int kOOMAllocationSizeParameterLen =
// this holds additional data sent via the API
static Mutex* crashReporterAPILock;
static Mutex* notesFieldLock;
static AnnotationTable* crashReporterAPIData_Hash;
static nsCString* crashReporterAPIData = nsnull;
static nsCString* notesField = nsnull;
@ -657,6 +658,8 @@ nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
NS_ASSERTION(!crashReporterAPILock, "Shouldn't have a lock yet");
crashReporterAPILock = new Mutex("crashReporterAPILock");
NS_ASSERTION(!notesFieldLock, "Shouldn't have a lock yet");
notesFieldLock = new Mutex("notesFieldLock");
crashReporterAPIData_Hash =
new nsDataHashtable<nsCStringHashKey,nsCString>();
@ -1086,6 +1089,9 @@ nsresult UnsetExceptionHandler()
delete crashReporterAPILock;
crashReporterAPILock = nsnull;
delete notesFieldLock;
notesFieldLock = nsnull;
delete crashReporterAPIData;
crashReporterAPIData = nsnull;
@ -1255,6 +1261,10 @@ nsresult AppendAppNotesToCrashReport(const nsACString& data)
return NS_ERROR_INVALID_ARG;
if (XRE_GetProcessType() != GeckoProcessType_Default) {
if (!NS_IsMainThread()) {
NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
return NS_ERROR_FAILURE;
}
PCrashReporterChild* reporter = CrashReporterChild::GetCrashReporter();
if (!reporter) {
EnqueueDelayedNote(new DelayedNote(data));
@ -1274,6 +1284,8 @@ nsresult AppendAppNotesToCrashReport(const nsACString& data)
return NS_OK;
}
MutexAutoLock lock(*notesFieldLock);
notesField->Append(data);
return AnnotateCrashReport(NS_LITERAL_CSTRING("Notes"), *notesField);
}

View File

@ -66,11 +66,12 @@ bool GetMinidumpPath(nsAString& aPath);
nsresult SetMinidumpPath(const nsAString& aPath);
// AnnotateCrashReport may be called from any thread in a chrome process,
// but may only be called from the main thread in a content process.
// AnnotateCrashReport and AppendAppNotesToCrashReport may be called from any
// thread in a chrome process, but may only be called from the main thread in
// a content process.
nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
nsresult AppendAppNotesToCrashReport(const nsACString& data);
nsresult SetRestartArgs(int argc, char** argv);
nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
const nsACString& aBuildID);