Browse Source

Use GetUploadsEnabled to return GetShouldUpload

Samuel Attard 8 years ago
parent
commit
285a36f9de

+ 2 - 0
atom/common/api/atom_api_crash_reporter.cc

@@ -42,6 +42,8 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
                  base::Bind(&CrashReporter::GetUploadedReports, report));
   dict.SetMethod("_setShouldUpload",
                  base::Bind(&CrashReporter::SetShouldUpload, report));
+  dict.SetMethod("_getShouldUpload",
+                 base::Bind(&CrashReporter::GetShouldUpload, report));
 }
 
 }  // namespace

+ 4 - 0
atom/common/crash_reporter/crash_reporter.cc

@@ -47,6 +47,10 @@ void CrashReporter::SetShouldUpload(const bool should_upload) {
 
 }
 
+bool CrashReporter::GetShouldUpload() {
+  return true;
+}
+
 std::vector<CrashReporter::UploadReportResult>
 CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
   std::string file_content;

+ 1 - 0
atom/common/crash_reporter/crash_reporter.h

@@ -34,6 +34,7 @@ class CrashReporter {
       const base::FilePath& crashes_dir);
 
   virtual void SetShouldUpload(bool should_upload);
+  virtual bool GetShouldUpload();
 
  protected:
   CrashReporter();

+ 1 - 0
atom/common/crash_reporter/crash_reporter_mac.h

@@ -33,6 +33,7 @@ class CrashReporterMac : public CrashReporter {
                     bool skip_system_crash_handler) override;
   void SetUploadParameters() override;
   void SetShouldUpload(bool should_upload) override;
+  bool GetShouldUpload() override;
 
  private:
   friend struct base::DefaultSingletonTraits<CrashReporterMac>;

+ 9 - 3
atom/common/crash_reporter/crash_reporter_mac.mm

@@ -75,10 +75,16 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
   if (is_browser_) {
     database_ =
         crashpad::CrashReportDatabase::Initialize(crashes_dir);
-    if (database_) {
-      database_->GetSettings()->SetUploadsEnabled(should_upload);
-    }
+    SetShouldUpload(should_upload);
+  }
+}
+
+bool CrashReporterMac::GetShouldUpload() {
+  bool enabled = true;
+  if (database_) {
+    database_->GetSettings()->GetUploadsEnabled(&enabled);
   }
+  return enabled;
 }
 
 void CrashReporterMac::SetShouldUpload(const bool should_upload) {

+ 4 - 0
docs/api/crash-reporter.md

@@ -75,12 +75,16 @@ ID.
 Returns `Boolean` - Whether reports should be submitted to the server.  Set through
 the `start` method or `setShouldUpload`.
 
+**NOTE:** This API can only be used from the main process
+
 ### `crashReporter.setShouldUpload(shouldUpload)` _macOS_
 
 * `shouldUpload` Boolean _macOS_ - Whether reports should be submitted to the server
 
 This would normally be controlled by user preferences.
 
+**NOTE:** This API can only be used from the main process
+
 ## Crash Report Payload
 
 The crash reporter will send the following data to the `submitURL` as

+ 10 - 4
lib/common/api/crash-reporter.js

@@ -62,7 +62,6 @@ class CrashReporter {
       })
     }
 
-    this._shouldUpload = shouldUpload
     binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), shouldUpload, ignoreSystemCrashHandler, extra)
   }
 
@@ -104,12 +103,19 @@ class CrashReporter {
   }
 
   getShouldUpload() {
-    return this._shouldUpload
+    if (process.type === 'browser') {
+      return binding._getShouldUpload()
+    } else {
+      throw new Error('getShouldUpload can only be called from the main process')
+    }
   }
 
   setShouldUpload(shouldUpload) {
-    this._shouldUpload = shouldUpload
-    return binding._setShouldUpload(shouldUpload)
+    if (process.type === 'browser') {
+      return binding._setShouldUpload(shouldUpload)
+    } else {
+      throw new Error('setShouldUpload can only be called from the main process')
+    }
   }
 }