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

Side by Side Diff: third_party/crashpad/crashpad/handler/crash_report_upload_thread.cc

Issue 1568553002: Update Crashpad to 54048cfd78af0a54cf4a2d2ecfb83881f5c54590 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: OWN Created 4 years, 11 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
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 #include "handler/crash_report_upload_thread.h" 15 #include "handler/crash_report_upload_thread.h"
16 16
17 #include <errno.h> 17 #include <errno.h>
18 #include <time.h> 18 #include <time.h>
19 19
20 #include <map> 20 #include <map>
21 #include <vector> 21 #include <vector>
22 22
23 #include "base/logging.h" 23 #include "base/logging.h"
24 #include "base/macros.h"
25 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
26 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
27 #include "build/build_config.h" 26 #include "build/build_config.h"
28 #include "client/settings.h" 27 #include "client/settings.h"
29 #include "snapshot/minidump/process_snapshot_minidump.h" 28 #include "snapshot/minidump/process_snapshot_minidump.h"
30 #include "snapshot/module_snapshot.h" 29 #include "snapshot/module_snapshot.h"
31 #include "util/file/file_reader.h" 30 #include "util/file/file_reader.h"
32 #include "util/misc/uuid.h" 31 #include "util/misc/uuid.h"
33 #include "util/net/http_body.h" 32 #include "util/net/http_body.h"
34 #include "util/net/http_multipart_builder.h" 33 #include "util/net/http_multipart_builder.h"
35 #include "util/net/http_transport.h" 34 #include "util/net/http_transport.h"
36 #include "util/stdlib/map_insert.h" 35 #include "util/stdlib/map_insert.h"
37 #include "util/thread/thread.h"
38 36
39 namespace crashpad { 37 namespace crashpad {
40 38
41 namespace { 39 namespace {
42 40
43 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map, 41 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map,
44 const std::string& key, 42 const std::string& key,
45 const std::string& value) { 43 const std::string& value) {
46 std::string old_value; 44 std::string old_value;
47 if (!MapInsertOrReplace(map, key, value, &old_value)) { 45 if (!MapInsertOrReplace(map, key, value, &old_value)) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 129
132 private: 130 private:
133 CrashReportDatabase* database_; // weak 131 CrashReportDatabase* database_; // weak
134 const CrashReportDatabase::Report* report_; // weak 132 const CrashReportDatabase::Report* report_; // weak
135 133
136 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt); 134 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt);
137 }; 135 };
138 136
139 } // namespace 137 } // namespace
140 138
141 namespace internal {
142
143 class CrashReportUploadHelperThread final : public Thread {
144 public:
145 explicit CrashReportUploadHelperThread(CrashReportUploadThread* self)
146 : self_(self) {}
147 ~CrashReportUploadHelperThread() override {}
148
149 void ThreadMain() override {
150 self_->ThreadMain();
151 }
152
153 private:
154 CrashReportUploadThread* self_;
155
156 DISALLOW_COPY_AND_ASSIGN(CrashReportUploadHelperThread);
157 };
158
159 } // namespace internal
160
161 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, 139 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database,
162 const std::string& url) 140 const std::string& url)
163 : url_(url), 141 : url_(url),
164 database_(database), 142 // Check for pending reports every 15 minutes, even in the absence of a
165 semaphore_(0), 143 // signal from the handler thread. This allows for failed uploads to be
166 thread_(), 144 // retried periodically, and for pending reports written by other
167 running_(false) { 145 // processes to be recognized.
146 thread_(15 * 60, this),
147 database_(database) {
168 } 148 }
169 149
170 CrashReportUploadThread::~CrashReportUploadThread() { 150 CrashReportUploadThread::~CrashReportUploadThread() {
171 DCHECK(!running_);
172 DCHECK(!thread_);
173 } 151 }
174 152
175 void CrashReportUploadThread::Start() { 153 void CrashReportUploadThread::Start() {
176 DCHECK(!running_); 154 thread_.Start(0);
177 DCHECK(!thread_);
178
179 running_ = true;
180 thread_.reset(new internal::CrashReportUploadHelperThread(this));
181 thread_->Start();
182 } 155 }
183 156
184 void CrashReportUploadThread::Stop() { 157 void CrashReportUploadThread::Stop() {
185 DCHECK(running_); 158 thread_.Stop();
186 DCHECK(thread_);
187
188 if (!running_) {
189 return;
190 }
191
192 running_ = false;
193 semaphore_.Signal();
194
195 thread_->Join();
196 thread_.reset();
197 } 159 }
198 160
199 void CrashReportUploadThread::ReportPending() { 161 void CrashReportUploadThread::ReportPending() {
200 semaphore_.Signal(); 162 thread_.DoWorkNow();
201 }
202
203 void CrashReportUploadThread::ThreadMain() {
204 while (running_) {
205 ProcessPendingReports();
206
207 // Check for pending reports every 15 minutes, even in the absence of a
208 // signal from the handler thread. This allows for failed uploads to be
209 // retried periodically, and for pending reports written by other processes
210 // to be recognized.
211 semaphore_.TimedWait(15 * 60);
212 }
213 } 163 }
214 164
215 void CrashReportUploadThread::ProcessPendingReports() { 165 void CrashReportUploadThread::ProcessPendingReports() {
216 std::vector<CrashReportDatabase::Report> reports; 166 std::vector<CrashReportDatabase::Report> reports;
217 if (database_->GetPendingReports(&reports) != CrashReportDatabase::kNoError) { 167 if (database_->GetPendingReports(&reports) != CrashReportDatabase::kNoError) {
218 // The database is sick. It might be prudent to stop trying to poke it from 168 // The database is sick. It might be prudent to stop trying to poke it from
219 // this thread by abandoning the thread altogether. On the other hand, if 169 // this thread by abandoning the thread altogether. On the other hand, if
220 // the problem is transient, it might be possible to talk to it again on the 170 // the problem is transient, it might be possible to talk to it again on the
221 // next pass. For now, take the latter approach. 171 // next pass. For now, take the latter approach.
222 return; 172 return;
223 } 173 }
224 174
225 for (const CrashReportDatabase::Report& report : reports) { 175 for (const CrashReportDatabase::Report& report : reports) {
226 ProcessPendingReport(report); 176 ProcessPendingReport(report);
227 177
228 // Respect Stop() being called after at least one attempt to process a 178 // Respect Stop() being called after at least one attempt to process a
229 // report. 179 // report.
230 if (!running_) { 180 if (!thread_.is_running()) {
231 return; 181 return;
232 } 182 }
233 } 183 }
234 } 184 }
235 185
236 void CrashReportUploadThread::ProcessPendingReport( 186 void CrashReportUploadThread::ProcessPendingReport(
237 const CrashReportDatabase::Report& report) { 187 const CrashReportDatabase::Report& report) {
238 Settings* const settings = database_->GetSettings(); 188 Settings* const settings = database_->GetSettings();
239 189
240 bool uploads_enabled; 190 bool uploads_enabled;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // TODO(mark): The timeout should be configurable by the client. 321 // TODO(mark): The timeout should be configurable by the client.
372 http_transport->SetTimeout(60.0); // 1 minute. 322 http_transport->SetTimeout(60.0); // 1 minute.
373 323
374 if (!http_transport->ExecuteSynchronously(response_body)) { 324 if (!http_transport->ExecuteSynchronously(response_body)) {
375 return UploadResult::kRetry; 325 return UploadResult::kRetry;
376 } 326 }
377 327
378 return UploadResult::kSuccess; 328 return UploadResult::kSuccess;
379 } 329 }
380 330
331 void CrashReportUploadThread::DoWork(const WorkerThread* thread) {
332 ProcessPendingReports();
333 }
334
381 } // namespace crashpad 335 } // namespace crashpad
OLDNEW
« no previous file with comments | « third_party/crashpad/crashpad/handler/crash_report_upload_thread.h ('k') | third_party/crashpad/crashpad/handler/handler.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698