Use app.getPath directly for temp path
authorKevin Sawicki <kevinsawicki@gmail.com>
Wed, 5 Oct 2016 22:23:51 +0000 (15:23 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 6 Oct 2016 16:02:02 +0000 (09:02 -0700)
atom/common/crash_reporter/crash_reporter.cc
atom/common/crash_reporter/crash_reporter.h
atom/common/crash_reporter/crash_reporter_linux.cc
atom/common/crash_reporter/crash_reporter_linux.h
atom/common/crash_reporter/crash_reporter_mac.h
atom/common/crash_reporter/crash_reporter_mac.mm
atom/common/crash_reporter/crash_reporter_win.cc
lib/common/api/crash-reporter.js

index 7a962da..f7ddd76 100644 (file)
@@ -8,7 +8,6 @@
 #include "atom/common/atom_version.h"
 #include "base/command_line.h"
 #include "base/files/file_util.h"
-#include "base/path_service.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_split.h"
 #include "content/public/common/content_switches.h"
@@ -26,29 +25,19 @@ CrashReporter::~CrashReporter() {
 void CrashReporter::Start(const std::string& product_name,
                           const std::string& company_name,
                           const std::string& submit_url,
+                          const std::string& temp_path,
                           bool auto_submit,
                           bool skip_system_crash_handler,
                           const StringMap& extra_parameters) {
   SetUploadParameters(extra_parameters);
 
   InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url,
-               auto_submit, skip_system_crash_handler);
+               temp_path, auto_submit, skip_system_crash_handler);
 }
 
-bool CrashReporter::GetTempDirectory(base::FilePath* path) {
-  bool success = PathService::Get(base::DIR_TEMP, path);
-  if (!success)
-    LOG(ERROR) << "Cannot get temp directory";
-  return success;
-}
-
-bool CrashReporter::GetCrashesDirectory(
-    const std::string& product_name, base::FilePath* path) {
-  if (GetTempDirectory(path)) {
-    *path = path->Append(product_name + " Crashes");
-    return true;
-  }
-  return false;
+base::FilePath CrashReporter::GetCrashesDirectory(
+    const std::string& product_name, const std::string& temp_dir) {
+  return base::FilePath(temp_dir).Append(product_name + " Crashes");
 }
 
 void CrashReporter::SetUploadParameters(const StringMap& parameters) {
@@ -60,16 +49,14 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
 }
 
 std::vector<CrashReporter::UploadReportResult>
-CrashReporter::GetUploadedReports(const std::string& product_name) {
+CrashReporter::GetUploadedReports(const std::string& product_name,
+                                  const std::string& temp_path) {
   std::vector<CrashReporter::UploadReportResult> result;
 
-  base::FilePath crashes_dir;
-  if (!GetCrashesDirectory(product_name, &crashes_dir))
-    return result;
-
+  base::FilePath uploads_path =
+      GetCrashesDirectory(product_name, temp_path).Append("uploads.log");
   std::string file_content;
-  if (base::ReadFileToString(crashes_dir.Append("uploads.log"),
-        &file_content)) {
+  if (base::ReadFileToString(uploads_path, &file_content)) {
     std::vector<std::string> reports = base::SplitString(
         file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
     for (const std::string& report : reports) {
@@ -90,6 +77,7 @@ void CrashReporter::InitBreakpad(const std::string& product_name,
                                  const std::string& version,
                                  const std::string& company_name,
                                  const std::string& submit_url,
+                                 const std::string& temp_path,
                                  bool auto_submit,
                                  bool skip_system_crash_handler) {
 }
index 5f59468..84208df 100644 (file)
@@ -25,12 +25,14 @@ class CrashReporter {
   void Start(const std::string& product_name,
              const std::string& company_name,
              const std::string& submit_url,
+             const std::string& temp_path,
              bool auto_submit,
              bool skip_system_crash_handler,
              const StringMap& extra_parameters);
 
   virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
-      const std::string& product_name);
+      const std::string& product_name,
+      const std::string& temp_path);
 
  protected:
   CrashReporter();
@@ -40,13 +42,13 @@ class CrashReporter {
                             const std::string& version,
                             const std::string& company_name,
                             const std::string& submit_url,
+                            const std::string& temp_path,
                             bool auto_submit,
                             bool skip_system_crash_handler);
   virtual void SetUploadParameters();
 
-  bool GetTempDirectory(base::FilePath* path);
-  bool GetCrashesDirectory(const std::string& product_name,
-                           base::FilePath* path);
+  base::FilePath GetCrashesDirectory(const std::string& product_name,
+                                     const std::string& temp_dir);
 
   StringMap upload_parameters_;
   bool is_browser_;
index e1d2389..e2f4c80 100644 (file)
@@ -60,9 +60,10 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name,
                                       const std::string& version,
                                       const std::string& company_name,
                                       const std::string& submit_url,
+                                      const std::string& temp_dir,
                                       bool auto_submit,
                                       bool skip_system_crash_handler) {
-  EnableCrashDumping(product_name);
+  EnableCrashDumping(product_name, temp_dir);
 
   crash_keys_.SetKeyValue("prod", ATOM_PRODUCT_NAME);
   crash_keys_.SetKeyValue("ver", version.c_str());
@@ -77,11 +78,9 @@ void CrashReporterLinux::SetUploadParameters() {
   upload_parameters_["platform"] = "linux";
 }
 
-void CrashReporterLinux::EnableCrashDumping(const std::string& product_name) {
-  base::FilePath dumps_path;
-  if (!GetCrashesDirectory(product_name, &dumps_path))
-    return;
-
+void CrashReporterLinux::EnableCrashDumping(const std::string& product_name,
+                                            const std::string& temp_dir) {
+  base::FilePath dumps_path = GetCrashesDirectory(product_name, temp_dir);
   base::CreateDirectory(dumps_path);
 
   std::string log_file = base::StringPrintf(
index de5a50e..a8f1a68 100644 (file)
@@ -41,7 +41,8 @@ class CrashReporterLinux : public CrashReporter {
   CrashReporterLinux();
   virtual ~CrashReporterLinux();
 
-  void EnableCrashDumping(const std::string& product_name);
+  void EnableCrashDumping(const std::string& product_name,
+                          const std::string& temp_dir);
 
   static bool CrashDone(const google_breakpad::MinidumpDescriptor& minidump,
                         void* context,
index 8acf502..89fb235 100644 (file)
@@ -27,6 +27,7 @@ class CrashReporterMac : public CrashReporter {
                     const std::string& version,
                     const std::string& company_name,
                     const std::string& submit_url,
+                    const std::string& temp_path,
                     bool auto_submit,
                     bool skip_system_crash_handler) override;
   void SetUploadParameters() override;
@@ -42,7 +43,7 @@ class CrashReporterMac : public CrashReporter {
                         const base::StringPiece& value);
 
   std::vector<UploadReportResult> GetUploadedReports(
-      const std::string& path) override;
+      const std::string& path, const std::string& temp_path) override;
 
   std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
 
index 99e8846..8c09e83 100644 (file)
@@ -31,6 +31,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
                                     const std::string& version,
                                     const std::string& company_name,
                                     const std::string& submit_url,
+                                    const std::string& temp_dir,
                                     bool auto_submit,
                                     bool skip_system_crash_handler) {
   // check whether crashpad has been initialized.
@@ -38,10 +39,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
   if (simple_string_dictionary_)
     return;
 
-  base::FilePath database_path;
-  if (!GetCrashesDirectory(product_name, &database_path))
-    return;
-
+  base::FilePath database_path = GetCrashesDirectory(product_name, temp_dir);
   if (is_browser_) {
     @autoreleasepool {
       base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath();
@@ -95,15 +93,14 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
 }
 
 std::vector<CrashReporter::UploadReportResult>
-CrashReporterMac::GetUploadedReports(const std::string& product_name) {
+CrashReporterMac::GetUploadedReports(const std::string& product_name,
+                                     const std::string& temp_path) {
   std::vector<CrashReporter::UploadReportResult> uploaded_reports;
 
-  base::FilePath file_path;
-  if (!GetCrashesDirectory(product_name, &file_path) ||
-      !base::PathExists(file_path)) {
+  base::FilePath file_path = GetCrashesDirectory(product_name, temp_path);
+  if (!base::PathExists(file_path)) {
     return uploaded_reports;
   }
-
   // Load crashpad database.
   std::unique_ptr<crashpad::CrashReportDatabase> database =
     crashpad::CrashReportDatabase::Initialize(file_path);
index 27af3e1..e2fe672 100644 (file)
@@ -149,14 +149,11 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
                                     const std::string& version,
                                     const std::string& company_name,
                                     const std::string& submit_url,
+                                    const std::string& temp_path,
                                     bool auto_submit,
                                     bool skip_system_crash_handler) {
   skip_system_crash_handler_ = skip_system_crash_handler;
 
-  base::FilePath temp_dir;
-  if (!GetTempDirectory(&temp_dir))
-    return;
-
   base::string16 pipe_name = base::ReplaceStringPlaceholders(
       kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL);
   base::string16 wait_name = base::ReplaceStringPlaceholders(
@@ -175,7 +172,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
   breakpad_.reset();
 
   breakpad_.reset(new google_breakpad::ExceptionHandler(
-      temp_dir.value(),
+      temp_path,
       FilterCallback,
       MinidumpCallback,
       this,
index fd7e30b..ca3d33a 100644 (file)
@@ -13,6 +13,7 @@ class CrashReporter {
     let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options
 
     const app = (process.type === 'browser' ? electron : electron.remote).app
+    this.tempDirectory = app.getPath('temp')
     if (this.productName == null) {
       this.productName = app.getName()
     }
@@ -34,7 +35,6 @@ class CrashReporter {
     if (extra._version == null) {
       extra._version = app.getVersion()
     }
-
     if (companyName == null) {
       throw new Error('companyName is a required option to crashReporter.start')
     }
@@ -53,7 +53,7 @@ class CrashReporter {
       })
     }
 
-    binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)
+    binding.start(this.productName, companyName, submitURL, this.tempDirectory, autoSubmit, ignoreSystemCrashHandler, extra)
   }
 
   getLastCrashReport () {
@@ -66,7 +66,7 @@ class CrashReporter {
   }
 
   getUploadedReports () {
-    return binding._getUploadedReports(this.productName)
+    return binding._getUploadedReports(this.productName, this.tempDirectory)
   }
 }