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

Side by Side Diff: handler/mac/crash_report_upload_thread.h

Issue 918743002: handler: Add crash report upload. Almost (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 10 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_HANDLER_MAC_CRASH_REPORT_UPLOAD_THREAD_H_
16 #define CRASHPAD_HANDLER_MAC_CRASH_REPORT_UPLOAD_THREAD_H_
17
18 #include "base/basictypes.h"
19
20 #include <pthread.h>
21
22 #include "client/crash_report_database.h"
23 #include "util/synchronization/semaphore.h"
24
25 namespace crashpad {
26
27 //! \brief A thread that processes pending crash reports in a
28 //! CrashReportDatabase by uploading them or marking them as completed
29 //! without upload, as desired.
30 //!
31 //! A producer of crash reports should notify an object of this class that a new
32 //! report has been added to the database by calling ReportPending().
33 //!
34 //! Independently of being triggered by ReportPending(), objects of this class
35 //! periodically examine the database for pending reports. This allows failed
36 //! upload attempts for reports left in the pending state to be retried. It also
37 //! catches reports that are added without a ReportPending() signal being
38 //! caught. This may happen if crash reports are added to the database by other
39 //! processes.
40 class CrashReportUploadThread {
41 public:
42 explicit CrashReportUploadThread(CrashReportDatabase* database);
43 ~CrashReportUploadThread();
44
45 //! \brief Starts a dedicated upload thread, which executes ThreadMain().
46 //!
47 //! This method may only be be called on a newly-constructed object or after
48 //! a call to Stop().
49 void Start();
50
51 //! \brief Stops the upload thread.
52 //!
53 //! The upload thread will terminate after completing whatever task it is
54 //! performing. If it is not performing any task, it will terminate
55 //! immediately. This method blocks while waiting for the upload thread to
56 //! terminate.
57 //!
58 //! This method must only be called after Start(). If Start() has been called,
59 //! this method must be called before destroying an object of this class.
60 //!
61 //! This method may be called from any thread other than the upload thread.
62 //! It is expected to only be called from the same thread that called Start().
63 void Stop();
64
65 //! \brief Informs the upload thread that a new pending report has been added
66 //! to the database.
67 //!
68 //! This method may be called from any thread.
69 void ReportPending();
70
71 private:
72 //! \brief Calls ProcessPendingReports() in response to ReportPending() having
73 //! been called on any thread, as well as periodically on a timer.
74 void ThreadMain();
75
76 //! \brief Obtains all pending reports from the database, and calls
77 //! ProcessPendingReport() to process each one.
78 void ProcessPendingReports();
79
80 //! \brief Processes a single pending report from the database.
81 //!
82 //! \param[in] report The crash report to process.
83 //!
84 //! If report upload is enabled, this method attempts to upload \a report. If
85 //! the upload is successful, the report will be marked as “completed” in the
86 //! database. If the upload fails and more retries are desired, the report’s
87 //! upload-attempt count and last-upload-attempt time will be updated in the
88 //! database and it will remain in the “pending” state. If the upload fails
89 //! and no more retries are desired, or report upload is disabled, it will be
90 //! marked as “completed” in the database without ever having been uploaded.
91 void ProcessPendingReport(const CrashReportDatabase::Report& report);
92
93 //! \brief Cals ThreadMain().
94 //!
95 //! \param[in] arg A pointer to the object on which to invoke ThreadMain().
96 //!
97 //! \return `nullptr`.
98 static void* RunThreadMain(void* arg);
99
100 CrashReportDatabase* database_; // weak
101 Semaphore semaphore_; // TODO(mark): Use a condition variable instead?
102 pthread_t thread_;
103 bool running_;
104 };
105
106 } // namespace crashpad
107
108 #endif // CRASHPAD_HANDLER_MAC_CRASH_REPORT_UPLOAD_THREAD_H_
OLDNEW
« no previous file with comments | « handler/mac/crash_report_exception_handler.cc ('k') | handler/mac/crash_report_upload_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698