OLD | NEW |
---|---|
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 Loading... | |
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 |
98 // WorkerThread::Delegate: | |
Mark Mentovai
2015/12/15 17:56:58
Can you sort this below UploadReport() (and in the
Robert Sesek
2015/12/23 19:22:31
Done.
| |
99 | |
104 //! \brief Calls ProcessPendingReports() in response to ReportPending() having | 100 //! \brief Calls ProcessPendingReports() in response to ReportPending() having |
105 //! been called on any thread, as well as periodically on a timer. | 101 //! been called on any thread, as well as periodically on a timer. |
106 void ThreadMain(); | 102 void DoWork(const WorkerThread* thread) override; |
107 | 103 |
108 //! \brief Obtains all pending reports from the database, and calls | 104 //! \brief Obtains all pending reports from the database, and calls |
109 //! ProcessPendingReport() to process each one. | 105 //! ProcessPendingReport() to process each one. |
110 void ProcessPendingReports(); | 106 void ProcessPendingReports(); |
111 | 107 |
112 //! \brief Processes a single pending report from the database. | 108 //! \brief Processes a single pending report from the database. |
113 //! | 109 //! |
114 //! \param[in] report The crash report to process. | 110 //! \param[in] report The crash report to process. |
115 //! | 111 //! |
116 //! If report upload is enabled, this method attempts to upload \a report by | 112 //! If report upload is enabled, this method attempts to upload \a report by |
(...skipping 16 matching lines...) Expand all Loading... | |
133 //! be set to the response body sent by the server. Breakpad-type servers | 129 //! 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. | 130 //! provide the crash ID assigned by the server in the response body. |
135 //! | 131 //! |
136 //! \return A member of UploadResult indicating the result of the upload | 132 //! \return A member of UploadResult indicating the result of the upload |
137 //! attempt. | 133 //! attempt. |
138 UploadResult UploadReport(const CrashReportDatabase::Report* report, | 134 UploadResult UploadReport(const CrashReportDatabase::Report* report, |
139 std::string* response_body); | 135 std::string* response_body); |
140 | 136 |
141 std::string url_; | 137 std::string url_; |
142 CrashReportDatabase* database_; // weak | 138 CrashReportDatabase* database_; // weak |
143 Semaphore semaphore_; // TODO(mark): Use a condition variable instead? | 139 WorkerThread thread_; |
Mark Mentovai
2015/12/15 17:56:58
Sort before the pointer (before or after url_, as
Robert Sesek
2015/12/23 19:22:31
Done.
| |
144 scoped_ptr<internal::CrashReportUploadHelperThread> thread_; | |
145 bool running_; | |
146 }; | 140 }; |
147 | 141 |
148 } // namespace crashpad | 142 } // namespace crashpad |
149 | 143 |
150 #endif // CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ | 144 #endif // CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ |
OLD | NEW |