Index: handler/crash_report_upload_thread.cc |
diff --git a/handler/crash_report_upload_thread.cc b/handler/crash_report_upload_thread.cc |
index 7d29aa11e694c47d7c265e0db66416b8b145d86a..d1429445017b396c103bd3603b30e551fdfa3789 100644 |
--- a/handler/crash_report_upload_thread.cc |
+++ b/handler/crash_report_upload_thread.cc |
@@ -33,7 +33,6 @@ |
#include "util/net/http_multipart_builder.h" |
#include "util/net/http_transport.h" |
#include "util/stdlib/map_insert.h" |
-#include "util/thread/thread.h" |
namespace crashpad { |
@@ -137,78 +136,30 @@ class CallRecordUploadAttempt { |
} // namespace |
-namespace internal { |
- |
-class CrashReportUploadHelperThread final : public Thread { |
- public: |
- explicit CrashReportUploadHelperThread(CrashReportUploadThread* self) |
- : self_(self) {} |
- ~CrashReportUploadHelperThread() override {} |
- |
- void ThreadMain() override { |
- self_->ThreadMain(); |
- } |
- |
- private: |
- CrashReportUploadThread* self_; |
- |
- DISALLOW_COPY_AND_ASSIGN(CrashReportUploadHelperThread); |
-}; |
- |
-} // namespace internal |
- |
CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, |
const std::string& url) |
: url_(url), |
database_(database), |
- semaphore_(0), |
- thread_(), |
- running_(false) { |
+ // Check for pending reports every 15 minutes, even in the absence of a |
+ // signal from the handler thread. This allows for failed uploads to be |
+ // retried periodically, and for pending reports written by other |
+ // processes to be recognized. |
+ thread_(15 * 60, this) { |
} |
CrashReportUploadThread::~CrashReportUploadThread() { |
- DCHECK(!running_); |
- DCHECK(!thread_); |
} |
void CrashReportUploadThread::Start() { |
- DCHECK(!running_); |
- DCHECK(!thread_); |
- |
- running_ = true; |
- thread_.reset(new internal::CrashReportUploadHelperThread(this)); |
- thread_->Start(); |
+ thread_.Start(0); |
} |
void CrashReportUploadThread::Stop() { |
- DCHECK(running_); |
- DCHECK(thread_); |
- |
- if (!running_) { |
- return; |
- } |
- |
- running_ = false; |
- semaphore_.Signal(); |
- |
- thread_->Join(); |
- thread_.reset(); |
+ thread_.Stop(); |
} |
void CrashReportUploadThread::ReportPending() { |
- semaphore_.Signal(); |
-} |
- |
-void CrashReportUploadThread::ThreadMain() { |
- while (running_) { |
- ProcessPendingReports(); |
- |
- // Check for pending reports every 15 minutes, even in the absence of a |
- // signal from the handler thread. This allows for failed uploads to be |
- // retried periodically, and for pending reports written by other processes |
- // to be recognized. |
- semaphore_.TimedWait(15 * 60); |
- } |
+ thread_.DoWorkNow(); |
} |
void CrashReportUploadThread::ProcessPendingReports() { |
@@ -226,7 +177,7 @@ void CrashReportUploadThread::ProcessPendingReports() { |
// Respect Stop() being called after at least one attempt to process a |
// report. |
- if (!running_) { |
+ if (!thread_.is_running()) { |
return; |
} |
} |
@@ -377,4 +328,8 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport( |
return UploadResult::kSuccess; |
} |
+void CrashReportUploadThread::DoWork(const WorkerThread* thread) { |
+ ProcessPendingReports(); |
+} |
+ |
} // namespace crashpad |