Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Unified Diff: handler/crash_report_upload_thread.cc

Issue 1526563003: Create WorkerThread, an abstraction to perform some work on an interval. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address coments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « handler/crash_report_upload_thread.h ('k') | util/thread/worker_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « handler/crash_report_upload_thread.h ('k') | util/thread/worker_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698