| 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_MAC_CRASH_REPORT_UPLOAD_THREAD_H_ | 15 #ifndef CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ |
| 16 #define CRASHPAD_HANDLER_MAC_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 <pthread.h> | |
| 21 | |
| 22 #include <string> | 20 #include <string> |
| 23 | 21 |
| 22 #include "base/memory/scoped_ptr.h" |
| 24 #include "client/crash_report_database.h" | 23 #include "client/crash_report_database.h" |
| 25 #include "util/synchronization/semaphore.h" | 24 #include "util/synchronization/semaphore.h" |
| 26 | 25 |
| 27 namespace crashpad { | 26 namespace crashpad { |
| 28 | 27 |
| 28 namespace internal { |
| 29 class CrashReportUploadHelperThread; |
| 30 } // namespace internal |
| 31 |
| 29 //! \brief A thread that processes pending crash reports in a | 32 //! \brief A thread that processes pending crash reports in a |
| 30 //! CrashReportDatabase by uploading them or marking them as completed | 33 //! CrashReportDatabase by uploading them or marking them as completed |
| 31 //! without upload, as desired. | 34 //! without upload, as desired. |
| 32 //! | 35 //! |
| 33 //! A producer of crash reports should notify an object of this class that a new | 36 //! A producer of crash reports should notify an object of this class that a new |
| 34 //! report has been added to the database by calling ReportPending(). | 37 //! report has been added to the database by calling ReportPending(). |
| 35 //! | 38 //! |
| 36 //! Independently of being triggered by ReportPending(), objects of this class | 39 //! Independently of being triggered by ReportPending(), objects of this class |
| 37 //! periodically examine the database for pending reports. This allows failed | 40 //! periodically examine the database for pending reports. This allows failed |
| 38 //! upload attempts for reports left in the pending state to be retried. It also | 41 //! upload attempts for reports left in the pending state to be retried. It also |
| (...skipping 30 matching lines...) Expand all Loading... |
| 69 //! It is expected to only be called from the same thread that called Start(). | 72 //! It is expected to only be called from the same thread that called Start(). |
| 70 void Stop(); | 73 void Stop(); |
| 71 | 74 |
| 72 //! \brief Informs the upload thread that a new pending report has been added | 75 //! \brief Informs the upload thread that a new pending report has been added |
| 73 //! to the database. | 76 //! to the database. |
| 74 //! | 77 //! |
| 75 //! This method may be called from any thread. | 78 //! This method may be called from any thread. |
| 76 void ReportPending(); | 79 void ReportPending(); |
| 77 | 80 |
| 78 private: | 81 private: |
| 82 friend internal::CrashReportUploadHelperThread; |
| 83 |
| 79 //! \brief The result code from UploadReport(). | 84 //! \brief The result code from UploadReport(). |
| 80 enum class UploadResult { | 85 enum class UploadResult { |
| 81 //! \brief The crash report was uploaded successfully. | 86 //! \brief The crash report was uploaded successfully. |
| 82 kSuccess, | 87 kSuccess, |
| 83 | 88 |
| 84 //! \brief The crash report upload failed in such a way that recovery is | 89 //! \brief The crash report upload failed in such a way that recovery is |
| 85 //! impossible. | 90 //! impossible. |
| 86 //! | 91 //! |
| 87 //! No further upload attempts should be made for the report. | 92 //! No further upload attempts should be made for the report. |
| 88 kPermanentFailure, | 93 kPermanentFailure, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 //! CrashReportDatabase::RecordUploadAttempt() after calling this method. | 131 //! CrashReportDatabase::RecordUploadAttempt() after calling this method. |
| 127 //! \param[out] response_body If the upload attempt is successful, this will | 132 //! \param[out] response_body If the upload attempt is successful, this will |
| 128 //! be set to the response body sent by the server. Breakpad-type servers | 133 //! be set to the response body sent by the server. Breakpad-type servers |
| 129 //! provide the crash ID assigned by the server in the response body. | 134 //! provide the crash ID assigned by the server in the response body. |
| 130 //! | 135 //! |
| 131 //! \return A member of UploadResult indicating the result of the upload | 136 //! \return A member of UploadResult indicating the result of the upload |
| 132 //! attempt. | 137 //! attempt. |
| 133 UploadResult UploadReport(const CrashReportDatabase::Report* report, | 138 UploadResult UploadReport(const CrashReportDatabase::Report* report, |
| 134 std::string* response_body); | 139 std::string* response_body); |
| 135 | 140 |
| 136 //! \brief Cals ThreadMain(). | |
| 137 //! | |
| 138 //! \param[in] arg A pointer to the object on which to invoke ThreadMain(). | |
| 139 //! | |
| 140 //! \return `nullptr`. | |
| 141 static void* RunThreadMain(void* arg); | |
| 142 | |
| 143 std::string url_; | 141 std::string url_; |
| 144 CrashReportDatabase* database_; // weak | 142 CrashReportDatabase* database_; // weak |
| 145 Semaphore semaphore_; // TODO(mark): Use a condition variable instead? | 143 Semaphore semaphore_; // TODO(mark): Use a condition variable instead? |
| 146 pthread_t thread_; | 144 scoped_ptr<internal::CrashReportUploadHelperThread> thread_; |
| 147 bool running_; | 145 bool running_; |
| 148 }; | 146 }; |
| 149 | 147 |
| 150 } // namespace crashpad | 148 } // namespace crashpad |
| 151 | 149 |
| 152 #endif // CRASHPAD_HANDLER_MAC_CRASH_REPORT_UPLOAD_THREAD_H_ | 150 #endif // CRASHPAD_HANDLER_CRASH_REPORT_UPLOAD_THREAD_H_ |
| OLD | NEW |