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

Side by Side Diff: handler/crash_report_upload_thread.h

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 4 years, 12 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
« no previous file with comments | « no previous file | handler/crash_report_upload_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #ifndef CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ 15 #ifndef CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_
16 #define CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ 16 #define CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_
17 17
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 19
20 #include <string> 20 #include <string>
21 21
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "client/crash_report_database.h" 23 #include "client/crash_report_database.h"
24 #include "util/synchronization/semaphore.h" 24 #include "util/thread/worker_thread.h"
25 25
26 namespace crashpad { 26 namespace crashpad {
27 27
28 namespace internal {
29 class CrashReportUploadHelperThread;
30 } // namespace internal
31
32 //! \brief A thread that processes pending crash reports in a 28 //! \brief A thread that processes pending crash reports in a
33 //! CrashReportDatabase by uploading them or marking them as completed 29 //! CrashReportDatabase by uploading them or marking them as completed
34 //! without upload, as desired. 30 //! without upload, as desired.
35 //! 31 //!
36 //! A producer of crash reports should notify an object of this class that a new 32 //! A producer of crash reports should notify an object of this class that a new
37 //! report has been added to the database by calling ReportPending(). 33 //! report has been added to the database by calling ReportPending().
38 //! 34 //!
39 //! Independently of being triggered by ReportPending(), objects of this class 35 //! Independently of being triggered by ReportPending(), objects of this class
40 //! periodically examine the database for pending reports. This allows failed 36 //! periodically examine the database for pending reports. This allows failed
41 //! upload attempts for reports left in the pending state to be retried. It also 37 //! upload attempts for reports left in the pending state to be retried. It also
42 //! catches reports that are added without a ReportPending() signal being 38 //! catches reports that are added without a ReportPending() signal being
43 //! caught. This may happen if crash reports are added to the database by other 39 //! caught. This may happen if crash reports are added to the database by other
44 //! processes. 40 //! processes.
45 class CrashReportUploadThread { 41 class CrashReportUploadThread : public WorkerThread::Delegate {
46 public: 42 public:
47 //! \brief Constructs a new object. 43 //! \brief Constructs a new object.
48 //! 44 //!
49 //! \param[in] database The database to upload crash reports from. 45 //! \param[in] database The database to upload crash reports from.
50 //! \param[in] url The URL of the server to upload crash reports to. 46 //! \param[in] url The URL of the server to upload crash reports to.
51 CrashReportUploadThread(CrashReportDatabase* database, 47 CrashReportUploadThread(CrashReportDatabase* database,
52 const std::string& url); 48 const std::string& url);
53 ~CrashReportUploadThread(); 49 ~CrashReportUploadThread();
54 50
55 //! \brief Starts a dedicated upload thread, which executes ThreadMain(). 51 //! \brief Starts a dedicated upload thread, which executes ThreadMain().
(...skipping 16 matching lines...) Expand all
72 //! It is expected to only be called from the same thread that called Start(). 68 //! It is expected to only be called from the same thread that called Start().
73 void Stop(); 69 void Stop();
74 70
75 //! \brief Informs the upload thread that a new pending report has been added 71 //! \brief Informs the upload thread that a new pending report has been added
76 //! to the database. 72 //! to the database.
77 //! 73 //!
78 //! This method may be called from any thread. 74 //! This method may be called from any thread.
79 void ReportPending(); 75 void ReportPending();
80 76
81 private: 77 private:
82 friend internal::CrashReportUploadHelperThread;
83
84 //! \brief The result code from UploadReport(). 78 //! \brief The result code from UploadReport().
85 enum class UploadResult { 79 enum class UploadResult {
86 //! \brief The crash report was uploaded successfully. 80 //! \brief The crash report was uploaded successfully.
87 kSuccess, 81 kSuccess,
88 82
89 //! \brief The crash report upload failed in such a way that recovery is 83 //! \brief The crash report upload failed in such a way that recovery is
90 //! impossible. 84 //! impossible.
91 //! 85 //!
92 //! No further upload attempts should be made for the report. 86 //! No further upload attempts should be made for the report.
93 kPermanentFailure, 87 kPermanentFailure,
94 88
95 //! \brief The crash report upload failed, but it might succeed again if 89 //! \brief The crash report upload failed, but it might succeed again if
96 //! retried in the future. 90 //! retried in the future.
97 //! 91 //!
98 //! If the report has not already been retried too many times, the caller 92 //! If the report has not already been retried too many times, the caller
99 //! may arrange to call UploadReport() for the report again in the future, 93 //! may arrange to call UploadReport() for the report again in the future,
100 //! after a suitable delay. 94 //! after a suitable delay.
101 kRetry, 95 kRetry,
102 }; 96 };
103 97
104 //! \brief Calls ProcessPendingReports() in response to ReportPending() having
105 //! been called on any thread, as well as periodically on a timer.
106 void ThreadMain();
107
108 //! \brief Obtains all pending reports from the database, and calls 98 //! \brief Obtains all pending reports from the database, and calls
109 //! ProcessPendingReport() to process each one. 99 //! ProcessPendingReport() to process each one.
110 void ProcessPendingReports(); 100 void ProcessPendingReports();
111 101
112 //! \brief Processes a single pending report from the database. 102 //! \brief Processes a single pending report from the database.
113 //! 103 //!
114 //! \param[in] report The crash report to process. 104 //! \param[in] report The crash report to process.
115 //! 105 //!
116 //! If report upload is enabled, this method attempts to upload \a report by 106 //! If report upload is enabled, this method attempts to upload \a report by
117 //! calling UplaodReport(). If the upload is successful, the report will be 107 //! calling UplaodReport(). If the upload is successful, the report will be
(...skipping 13 matching lines...) Expand all
131 //! CrashReportDatabase::RecordUploadAttempt() after calling this method. 121 //! CrashReportDatabase::RecordUploadAttempt() after calling this method.
132 //! \param[out] response_body If the upload attempt is successful, this will 122 //! \param[out] response_body If the upload attempt is successful, this will
133 //! be set to the response body sent by the server. Breakpad-type servers 123 //! be set to the response body sent by the server. Breakpad-type servers
134 //! provide the crash ID assigned by the server in the response body. 124 //! provide the crash ID assigned by the server in the response body.
135 //! 125 //!
136 //! \return A member of UploadResult indicating the result of the upload 126 //! \return A member of UploadResult indicating the result of the upload
137 //! attempt. 127 //! attempt.
138 UploadResult UploadReport(const CrashReportDatabase::Report* report, 128 UploadResult UploadReport(const CrashReportDatabase::Report* report,
139 std::string* response_body); 129 std::string* response_body);
140 130
131 // WorkerThread::Delegate:
132 //! \brief Calls ProcessPendingReports() in response to ReportPending() having
133 //! been called on any thread, as well as periodically on a timer.
134 void DoWork(const WorkerThread* thread) override;
135
141 std::string url_; 136 std::string url_;
137 WorkerThread thread_;
142 CrashReportDatabase* database_; // weak 138 CrashReportDatabase* database_; // weak
143 Semaphore semaphore_; // TODO(mark): Use a condition variable instead?
144 scoped_ptr<internal::CrashReportUploadHelperThread> thread_;
145 bool running_;
146 }; 139 };
147 140
148 } // namespace crashpad 141 } // namespace crashpad
149 142
150 #endif // CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ 143 #endif // CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_
OLDNEW
« no previous file with comments | « no previous file | handler/crash_report_upload_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698