bug 394490 - pending extra and dmp files should be deleted when not submitting report. r=dcamp
authorted.mielczarek@gmail.com
Fri, 25 Jan 2008 03:24:02 -0800
changeset 10665 0fd0dea96bcf77e6983c8c42ca01918733f227d1
parent 10664 6d4b453b928c51ff722473b1b2c3b237e7336e9e
child 10666 02883e6daa8864c684a137e4d40604b05421db63
push idunknown
push userunknown
push dateunknown
reviewersdcamp
bugs394490
milestone1.9b3pre
bug 394490 - pending extra and dmp files should be deleted when not submitting report. r=dcamp
toolkit/crashreporter/client/crashreporter.cpp
toolkit/crashreporter/client/crashreporter.h
toolkit/crashreporter/client/crashreporter_linux.cpp
toolkit/crashreporter/client/crashreporter_osx.h
toolkit/crashreporter/client/crashreporter_osx.mm
toolkit/crashreporter/client/crashreporter_win.cpp
--- a/toolkit/crashreporter/client/crashreporter.cpp
+++ b/toolkit/crashreporter/client/crashreporter.cpp
@@ -319,27 +319,31 @@ static bool AddSubmittedReport(const str
   }
 
   file->close();
   delete file;
 
   return true;
 }
 
+void DeleteDump()
+{
+  const char* noDelete = getenv("MOZ_CRASHREPORTER_NO_DELETE_DUMP");
+  if (!noDelete || *noDelete == '\0') {
+    if (!gDumpFile.empty())
+      UIDeleteFile(gDumpFile);
+    if (!gExtraFile.empty())
+      UIDeleteFile(gExtraFile);
+  }
+}
+
 bool SendCompleted(bool success, const string& serverResponse)
 {
   if (success) {
-    const char* noDelete = getenv("MOZ_CRASHREPORTER_NO_DELETE_DUMP");
-    if (!noDelete || *noDelete == '\0') {
-      if (!gDumpFile.empty())
-        UIDeleteFile(gDumpFile);
-      if (!gExtraFile.empty())
-        UIDeleteFile(gExtraFile);
-    }
-
+    DeleteDump();
     return AddSubmittedReport(serverResponse);
   }
   return true;
 }
 
 } // namespace CrashReporter
 
 using namespace CrashReporter;
@@ -503,17 +507,18 @@ int main(int argc, char** argv)
     // allow override of the server url via environment variable
     //XXX: remove this in the far future when our robot
     // masters force everyone to use XULRunner
     char* urlEnv = getenv("MOZ_CRASHREPORTER_URL");
     if (urlEnv && *urlEnv) {
       sendURL = urlEnv;
     }
 
-    UIShowCrashUI(gDumpFile, queryParameters, sendURL, restartArgs);
+    if (!UIShowCrashUI(gDumpFile, queryParameters, sendURL, restartArgs))
+      DeleteDump();
   }
 
   UIShutdown();
 
   return 0;
 }
 
 #if defined(XP_WIN) && !defined(__GNUC__)
--- a/toolkit/crashreporter/client/crashreporter.h
+++ b/toolkit/crashreporter/client/crashreporter.h
@@ -95,30 +95,33 @@ namespace CrashReporter {
                     const std::string& header,
                     StringTable& strings,
                     bool escape);
   bool WriteStringsToFile(const std::string& path,
                           const std::string& header,
                           StringTable& strings,
                           bool escape);
   void LogMessage(const std::string& message);
+  void DeleteDump();
 }
 
 //=============================================================================
 // implemented in the platform-specific files
 //=============================================================================
 
 bool UIInit();
 void UIShutdown();
 
 // Run the UI for when the app was launched without a dump file
 void UIShowDefaultUI();
 
 // Run the UI for when the app was launched with a dump file
-void UIShowCrashUI(const std::string& dumpfile,
+// Return true if the user sent (or tried to send) the crash report,
+// false if they chose not to, and it should be deleted.
+bool UIShowCrashUI(const std::string& dumpfile,
                    const StringTable& queryParameters,
                    const std::string& sendURL,
                    const std::vector<std::string>& restartArgs);
 
 void UIError_impl(const std::string& message);
 
 bool UIGetIniPath(std::string& path);
 bool UIGetSettingsPath(const std::string& vendor,
--- a/toolkit/crashreporter/client/crashreporter_linux.cpp
+++ b/toolkit/crashreporter/client/crashreporter_linux.cpp
@@ -68,16 +68,17 @@ static GtkWidget* gIncludeURLCheck = 0;
 static GtkWidget* gEmailMeCheck = 0;
 static GtkWidget* gEmailEntry = 0;
 static GtkWidget* gThrobber = 0;
 static GtkWidget* gProgressLabel = 0;
 static GtkWidget* gCloseButton = 0;
 static GtkWidget* gRestartButton = 0;
 
 static bool gInitialized = false;
+static bool gDidTrySend = false;
 static string gDumpFile;
 static StringTable gQueryParameters;
 static string gSendURL;
 static vector<string> gRestartArgs;
 static string gURLParameter;
 
 static bool gEmailFieldHint = true;
 static bool gCommentFieldHint = true;
@@ -273,16 +274,17 @@ static void CloseClicked(GtkButton* butt
 
 static void RestartClicked(GtkButton* button,
                            gpointer userData)
 {
   SaveSettings();
   RestartApplication();
 
   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))) {
+    gDidTrySend = true;
     SendReport();
   } else {
     gtk_main_quit();
   }
 }
 
 static void UpdateSubmit()
 {
@@ -540,17 +542,17 @@ void UIShowDefaultUI()
                            GTK_BUTTONS_CLOSE,
                            "%s", gStrings[ST_CRASHREPORTERDEFAULT].c_str());
 
   gtk_window_set_title(GTK_WINDOW(errorDialog),
                        gStrings[ST_CRASHREPORTERTITLE].c_str());
   gtk_dialog_run(GTK_DIALOG(errorDialog));
 }
 
-void UIShowCrashUI(const string& dumpfile,
+bool UIShowCrashUI(const string& dumpfile,
                    const StringTable& queryParameters,
                    const string& sendURL,
                    const vector<string>& restartArgs)
 {
   gDumpFile = dumpfile;
   gQueryParameters = queryParameters;
   gSendURL = sendURL;
   gRestartArgs = restartArgs;
@@ -714,16 +716,18 @@ void UIShowCrashUI(const string& dumpfil
   UpdateHintText(gEmailEntry, FALSE, &gEmailFieldHint,
                  gStrings[ST_EMAILGRAYTEXT].c_str());
 
   gtk_widget_show_all(gWindow);
   // stick this here to avoid the show_all above...
   gtk_widget_hide_all(gThrobber);
 
   gtk_main();
+
+  return gDidTrySend;
 }
 
 void UIError_impl(const string& message)
 {
   if (!gInitialized) {
     // Didn't initialize, this is the best we can do
     printf("Error: %s\n", message.c_str());
     return;
--- a/toolkit/crashreporter/client/crashreporter_osx.h
+++ b/toolkit/crashreporter/client/crashreporter_osx.h
@@ -92,12 +92,13 @@
 - (void)updateURL;
 - (void)updateEmail;
 - (void)sendReport;
 - (bool)setupPost;
 - (void)uploadThread:(id)post;
 - (void)uploadComplete:(id)data;
 
 -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication;
+-(void)applicationWillTerminate:(NSNotification *)aNotification;
 
 @end
 
 #endif
--- a/toolkit/crashreporter/client/crashreporter_osx.mm
+++ b/toolkit/crashreporter/client/crashreporter_osx.mm
@@ -53,16 +53,17 @@ using namespace CrashReporter;
 
 static NSAutoreleasePool* gMainPool;
 static CrashReporterUI* gUI = 0;
 static string gDumpFile;
 static StringTable gQueryParameters;
 static string gURLParameter;
 static string gSendURL;
 static vector<string> gRestartArgs;
+static bool gDidTrySend = false;
 
 #define NSSTR(s) [NSString stringWithUTF8String:(s).c_str()]
 
 static NSString* Str(const char* aName)
 {
   string str = gStrings[aName];
   if (str.empty()) str = "?";
   return NSSTR(str);
@@ -271,29 +272,31 @@ static bool RestartApplication()
 }
 
 -(IBAction)closeAndSendClicked:(id)sender
 {
   if ([submitReportButton state] == NSOnState) {
     // Hide the dialog after "closing", but leave it around to coordinate
     // with the upload thread
     [window orderOut:nil];
+    gDidTrySend = true;
     [self sendReport];
   } else {
     [NSApp terminate:self];
   }
 }
 
 -(IBAction)restartClicked:(id)sender
 {
   RestartApplication();
   if ([submitReportButton state] == NSOnState) {
     // Hide the dialog after "closing", but leave it around to coordinate
     // with the upload thread
     [window orderOut:nil];
+    gDidTrySend = true;
     [self sendReport];
   } else {
     [NSApp terminate:self];
   }
 }
 
 - (IBAction)includeURLClicked:(id)sender
 {
@@ -483,16 +486,24 @@ static bool RestartApplication()
 }
 
 // to get auto-quit when we close the window
 -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication
 {
     return NO;
 }
 
+-(void)applicationWillTerminate:(NSNotification *)aNotification
+{
+  // since we use [NSApp terminate:] we never return to main,
+  // so do our cleanup here
+  if (!gDidTrySend)
+    DeleteDump();
+}
+
 @end
 
 /* === Crashreporter UI Functions === */
 
 bool UIInit()
 {
   gMainPool = [[NSAutoreleasePool alloc] init];
   [NSApplication sharedApplication];
@@ -507,27 +518,29 @@ void UIShutdown()
 }
 
 void UIShowDefaultUI()
 {
   [gUI showErrorUI: gStrings[ST_CRASHREPORTERDEFAULT]];
   [NSApp run];
 }
 
-void UIShowCrashUI(const string& dumpfile,
+bool UIShowCrashUI(const string& dumpfile,
                    const StringTable& queryParameters,
                    const string& sendURL,
                    const vector<string>& restartArgs)
 {
   gRestartArgs = restartArgs;
 
   [gUI showCrashUI: dumpfile
        queryParameters: queryParameters
        sendURL: sendURL];
   [NSApp run];
+
+  return gDidTrySend;
 }
 
 void UIError_impl(const string& message)
 {
   if (!gUI) {
     // UI failed to initialize, printing is the best we can do
     printf("Error: %s\n", message.c_str());
     return;
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -906,17 +906,17 @@ static BOOL CALLBACK CrashReporterDialog
     Animate_Stop(GetDlgItem(hwndDlg, IDC_THROBBER));
     SetDlgItemVisible(hwndDlg, IDC_THROBBER, false);
 
     SetDlgItemText(hwndDlg, IDC_PROGRESSTEXT,
                    success ?
                    Str(ST_REPORTSUBMITSUCCESS).c_str() :
                    Str(ST_SUBMITFAILED).c_str());
     // close dialog after 5 seconds
-    SetTimer(hwndDlg, success ? 1 : 0, 5000, NULL);
+    SetTimer(hwndDlg, 0, 5000, NULL);
     //
     return TRUE;
   }
 
   case WM_LBUTTONDOWN: {
     HWND hwndEmail = GetDlgItem(hwndDlg, IDC_EMAILTEXT);
     POINT p = { LOWORD(lParam), HIWORD(lParam) };
     // if the email edit control is clicked, enable it,
@@ -927,18 +927,19 @@ static BOOL CALLBACK CrashReporterDialog
       CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_CHECKED);
       UpdateEmail(hwndDlg);
       SetFocus(hwndEmail);
     }
     break;
   }
 
   case WM_TIMER: {
-    // wParam is the second parameter from SetTimer above
-    EndCrashReporterDialog(hwndDlg, wParam);
+    // The "1" gets used down in UIShowCrashUI to indicate that we at least
+    // tried to send the report.
+    EndCrashReporterDialog(hwndDlg, 1);
     return FALSE;
   }
 
   case WM_CLOSE: {
     EndCrashReporterDialog(hwndDlg, 0);
     return FALSE;
   }
   }
@@ -1022,17 +1023,17 @@ void UIShutdown()
 
 void UIShowDefaultUI()
 {
   MessageBox(NULL, Str(ST_CRASHREPORTERDEFAULT).c_str(),
              L"Crash Reporter",
              MB_OK | MB_ICONSTOP);
 }
 
-void UIShowCrashUI(const string& dumpFile,
+bool UIShowCrashUI(const string& dumpFile,
                    const StringTable& queryParameters,
                    const string& sendURL,
                    const vector<string>& restartArgs)
 {
   gSendData.hDlg = NULL;
   gSendData.dumpFile = UTF8ToWide(dumpFile);
   gSendData.sendURL = UTF8ToWide(sendURL);
 
@@ -1050,18 +1051,18 @@ void UIShowCrashUI(const string& dumpFil
     gCrashReporterKey += gQueryParameters[L"ProductName"] + L"\\Crash Reporter";
   }
 
   if (gQueryParameters.find(L"URL") != gQueryParameters.end())
     gURLParameter = gQueryParameters[L"URL"];
 
   gRestartArgs = restartArgs;
 
-  DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_SENDDIALOG), NULL,
-                 (DLGPROC)CrashReporterDialogProc, 0);
+  return DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_SENDDIALOG), NULL,
+                        (DLGPROC)CrashReporterDialogProc, 0) == 1;
 }
 
 void UIError_impl(const string& message)
 {
   wstring title = Str(ST_CRASHREPORTERTITLE);
   if (title.empty())
     title = L"Crash Reporter Error";