Bug 994707 - Write crash submission events. r=ted

--HG--
extra : rebase_source : 11f614bdb0c8f6bf63ddc937957b89b7184eaad9
This commit is contained in:
Steven MacLeod 2014-07-03 14:54:54 -04:00
Родитель eaaaed8472
Коммит 932a12f1d7
2 изменённых файлов: 72 добавлений и 9 удалений

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

@ -32,9 +32,12 @@ namespace CrashReporter {
StringTable gStrings;
string gSettingsPath;
string gEventsPath;
int gArgc;
char** gArgv;
enum SubmissionResult {Succeeded, Failed};
static auto_ptr<ofstream> gLogStream(nullptr);
static string gReporterDumpFile;
static string gExtraFile;
@ -172,6 +175,53 @@ bool WriteStringsToFile(const string& path,
return success;
}
static string Basename(const string& file)
{
string::size_type slashIndex = file.rfind(UI_DIR_SEPARATOR);
if (slashIndex != string::npos)
return file.substr(slashIndex + 1);
else
return file;
}
static string GetDumpLocalID()
{
string localId = Basename(gReporterDumpFile);
string::size_type dot = localId.rfind('.');
if (dot == string::npos)
return "";
return localId.substr(0, dot);
}
static void WriteSubmissionEvent(SubmissionResult result,
const string& remoteId)
{
if (gEventsPath.empty()) {
// If there is no path for writing the submission event, skip it.
return;
}
string localId = GetDumpLocalID();
string fpath = gEventsPath + UI_DIR_SEPARATOR + localId + "-submission";
ofstream* f = UIOpenWrite(fpath.c_str());
time_t tm;
time(&tm);
if (f->is_open()) {
*f << "crash.submission.1\n";
*f << tm << "\n";
*f << localId << "\n";
*f << (result == Succeeded ? "true" : "false") << "\n";
*f << remoteId;
f->close();
}
delete f;
}
void LogMessage(const std::string& message)
{
if (gLogStream.get()) {
@ -218,15 +268,6 @@ static string GetExtraDataFilename(const string& dumpfile)
return filename;
}
static string Basename(const string& file)
{
int slashIndex = file.rfind(UI_DIR_SEPARATOR);
if (slashIndex >= 0)
return file.substr(slashIndex + 1);
else
return file;
}
static bool MoveCrashData(const string& toDir,
string& dumpfile,
string& extrafile)
@ -316,6 +357,7 @@ static bool AddSubmittedReport(const string& serverResponse)
file->close();
delete file;
WriteSubmissionEvent(Succeeded, responseItems["CrashID"]);
return true;
}
@ -343,7 +385,10 @@ void SendCompleted(bool success, const string& serverResponse)
return;
directory.resize(slashpos);
UIPruneSavedDumps(directory);
WriteSubmissionEvent(Failed, "");
}
} else {
WriteSubmissionEvent(Failed, "");
}
}
@ -514,6 +559,23 @@ int main(int argc, char** argv)
OpenLogFile();
#ifdef XP_WIN32
static const wchar_t kEventsDirKey[] = L"MOZ_CRASHREPORTER_EVENTS_DIRECTORY";
const wchar_t *eventsPath = _wgetenv(kEventsDirKey);
if (eventsPath && *eventsPath) {
gEventsPath = WideToUTF8(eventsPath);
}
#else
static const char kEventsDirKey[] = "MOZ_CRASHREPORTER_EVENTS_DIRECTORY";
const char *eventsPath = getenv(kEventsDirKey);
if (eventsPath && *eventsPath) {
gEventsPath = eventsPath;
}
#endif
else {
gEventsPath.clear();
}
if (!UIFileExists(gReporterDumpFile)) {
UIError(gStrings[ST_ERROR_DUMPFILEEXISTS]);
return 0;

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

@ -82,6 +82,7 @@ typedef std::map<std::string, std::string> StringTable;
namespace CrashReporter {
extern StringTable gStrings;
extern std::string gSettingsPath;
extern std::string gEventsPath;
extern int gArgc;
extern char** gArgv;