Bug 870782 - call NS_GetSpecialDirectory on the main thread rather than off-mainthread in telemetry; r=vladan

This commit is contained in:
Nathan Froyd 2013-05-10 11:37:13 -04:00
parent a987f7a594
commit 45c54d22ef

View File

@ -314,7 +314,7 @@ private:
static bool AddonReflector(AddonEntryType *entry, JSContext *cx, JS::Handle<JSObject*> obj);
static bool CreateHistogramForAddon(const nsACString &name,
AddonHistogramInfo &info);
void ReadLateWritesStacks();
void ReadLateWritesStacks(nsIFile* aProfileDir);
AddonMapType mAddonMap;
// This is used for speedy string->Telemetry::ID conversions
@ -743,14 +743,11 @@ GetFailedLockCount(nsIInputStream* inStream, uint32_t aCount,
}
nsresult
GetFailedProfileLockFile(nsIFile* *aFile, nsIFile* aProfileDir = nullptr)
GetFailedProfileLockFile(nsIFile* *aFile, nsIFile* aProfileDir)
{
nsresult rv;
if (aProfileDir) {
rv = aProfileDir->Clone(aFile);
} else {
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, aFile);
}
NS_ENSURE_ARG_POINTER(aProfileDir);
nsresult rv = aProfileDir->Clone(aFile);
NS_ENSURE_SUCCESS(rv, rv);
(*aFile)->AppendNative(NS_LITERAL_CSTRING("Telemetry.FailedProfileLocks.txt"));
@ -761,10 +758,12 @@ class nsFetchTelemetryData : public nsRunnable
{
public:
nsFetchTelemetryData(const char* aShutdownTimeFilename,
nsIFile* aFailedProfileLockFile)
nsIFile* aFailedProfileLockFile,
nsIFile* aProfileDir)
: mShutdownTimeFilename(aShutdownTimeFilename),
mFailedProfileLockFile(aFailedProfileLockFile),
mTelemetry(TelemetryImpl::sTelemetry)
mTelemetry(TelemetryImpl::sTelemetry),
mProfileDir(aProfileDir)
{
}
@ -772,6 +771,7 @@ private:
const char* mShutdownTimeFilename;
nsCOMPtr<nsIFile> mFailedProfileLockFile;
nsCOMPtr<TelemetryImpl> mTelemetry;
nsCOMPtr<nsIFile> mProfileDir;
public:
void MainThread() {
@ -786,7 +786,7 @@ public:
LoadFailedLockCount(mTelemetry->mFailedLockCount);
mTelemetry->mLastShutdownTime =
ReadLastShutdownDuration(mShutdownTimeFilename);
mTelemetry->ReadLateWritesStacks();
mTelemetry->ReadLateWritesStacks(mProfileDir);
nsCOMPtr<nsIRunnable> e =
NS_NewRunnableMethod(this, &nsFetchTelemetryData::MainThread);
NS_ENSURE_STATE(e);
@ -921,8 +921,18 @@ TelemetryImpl::AsyncFetchTelemetryData(nsIFetchTelemetryDataCallback *aCallback)
return NS_OK;
}
nsCOMPtr<nsIFile> profileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
if (NS_FAILED(rv)) {
mCachedTelemetryData = true;
aCallback->Complete();
return NS_OK;
}
nsCOMPtr<nsIFile> failedProfileLockFile;
nsresult rv = GetFailedProfileLockFile(getter_AddRefs(failedProfileLockFile));
rv = GetFailedProfileLockFile(getter_AddRefs(failedProfileLockFile),
profileDir);
if (NS_FAILED(rv)) {
mCachedTelemetryData = true;
aCallback->Complete();
@ -930,8 +940,10 @@ TelemetryImpl::AsyncFetchTelemetryData(nsIFetchTelemetryDataCallback *aCallback)
}
mCallbacks.AppendObject(aCallback);
nsCOMPtr<nsIRunnable> event = new nsFetchTelemetryData(shutdownTimeFilename,
failedProfileLockFile);
failedProfileLockFile,
profileDir);
targetThread->Dispatch(event, NS_DISPATCH_NORMAL);
return NS_OK;
@ -1710,17 +1722,10 @@ ReadStack(const char *aFileName, Telemetry::ProcessedStack &aStack)
}
void
TelemetryImpl::ReadLateWritesStacks()
TelemetryImpl::ReadLateWritesStacks(nsIFile* aProfileDir)
{
nsCOMPtr<nsIFile> profileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
if (!profileDir || NS_FAILED(rv)) {
return;
}
nsAutoCString nativePath;
rv = profileDir->GetNativePath(nativePath);
nsresult rv = aProfileDir->GetNativePath(nativePath);
if (NS_FAILED(rv)) {
return;
}