Chromium Code Reviews| 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 #include "handler/mac/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/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/strings/utf_string_conversions.h" | |
| 26 #include "build/build_config.h" | |
| 25 #include "client/settings.h" | 27 #include "client/settings.h" |
| 26 #include "snapshot/minidump/process_snapshot_minidump.h" | 28 #include "snapshot/minidump/process_snapshot_minidump.h" |
| 27 #include "snapshot/module_snapshot.h" | 29 #include "snapshot/module_snapshot.h" |
| 28 #include "util/file/file_reader.h" | 30 #include "util/file/file_reader.h" |
| 29 #include "util/misc/uuid.h" | 31 #include "util/misc/uuid.h" |
| 30 #include "util/net/http_body.h" | 32 #include "util/net/http_body.h" |
| 31 #include "util/net/http_multipart_builder.h" | 33 #include "util/net/http_multipart_builder.h" |
| 32 #include "util/net/http_transport.h" | 34 #include "util/net/http_transport.h" |
| 33 #include "util/stdlib/map_insert.h" | 35 #include "util/stdlib/map_insert.h" |
| 36 #include "util/thread/thread.h" | |
| 34 | 37 |
| 35 namespace crashpad { | 38 namespace crashpad { |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map, | 42 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map, |
| 40 const std::string& key, | 43 const std::string& key, |
| 41 const std::string& value) { | 44 const std::string& value) { |
| 42 std::string old_value; | 45 std::string old_value; |
| 43 if (!MapInsertOrReplace(map, key, value, &old_value)) { | 46 if (!MapInsertOrReplace(map, key, value, &old_value)) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 130 |
| 128 private: | 131 private: |
| 129 CrashReportDatabase* database_; // weak | 132 CrashReportDatabase* database_; // weak |
| 130 const CrashReportDatabase::Report* report_; // weak | 133 const CrashReportDatabase::Report* report_; // weak |
| 131 | 134 |
| 132 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt); | 135 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt); |
| 133 }; | 136 }; |
| 134 | 137 |
| 135 } // namespace | 138 } // namespace |
| 136 | 139 |
| 140 class HelperThread : public Thread { | |
|
Mark Mentovai
2015/08/18 21:38:11
final (useful as a hint since this isn’t used outs
scottmg
2015/08/18 22:21:40
Done.
| |
| 141 public: | |
| 142 HelperThread(CrashReportUploadThread* self) : self_(self) {} | |
|
Mark Mentovai
2015/08/18 21:38:12
explicit
scottmg
2015/08/18 22:21:40
Done.
| |
| 143 ~HelperThread() override {} | |
| 144 | |
| 145 virtual void ThreadMain() { | |
| 146 self_->ThreadMain(); | |
| 147 } | |
| 148 | |
| 149 private: | |
| 150 CrashReportUploadThread* self_; | |
| 151 }; | |
|
Mark Mentovai
2015/08/18 21:38:11
DISALLOW_COPY_AND_ASSIGN
scottmg
2015/08/18 22:21:40
Done.
| |
| 152 | |
| 137 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, | 153 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, |
| 138 const std::string& url) | 154 const std::string& url) |
| 139 : url_(url), | 155 : url_(url), |
| 140 database_(database), | 156 database_(database), |
| 141 semaphore_(0), | 157 semaphore_(0), |
| 142 thread_(0), | 158 thread_(), |
| 143 running_(false) { | 159 running_(false) { |
| 144 } | 160 } |
| 145 | 161 |
| 146 CrashReportUploadThread::~CrashReportUploadThread() { | 162 CrashReportUploadThread::~CrashReportUploadThread() { |
| 147 DCHECK(!running_); | 163 DCHECK(!running_); |
| 148 DCHECK(!thread_); | 164 DCHECK(!thread_); |
| 149 } | 165 } |
| 150 | 166 |
| 151 void CrashReportUploadThread::Start() { | 167 void CrashReportUploadThread::Start() { |
| 152 DCHECK(!running_); | 168 DCHECK(!running_); |
| 153 DCHECK(!thread_); | 169 DCHECK(!thread_); |
| 154 | 170 |
| 155 running_ = true; | 171 running_ = true; |
| 156 if ((errno = pthread_create(&thread_, nullptr, RunThreadMain, this)) != 0) { | 172 thread_.reset(new HelperThread(this)); |
| 157 PLOG(ERROR) << "pthread_create"; | |
| 158 DCHECK(false); | |
| 159 running_ = false; | |
| 160 } | |
| 161 } | 173 } |
| 162 | 174 |
| 163 void CrashReportUploadThread::Stop() { | 175 void CrashReportUploadThread::Stop() { |
| 164 DCHECK(running_); | 176 DCHECK(running_); |
| 165 DCHECK(thread_); | 177 DCHECK(thread_); |
| 166 | 178 |
| 167 if (!running_) { | 179 if (!running_) { |
| 168 return; | 180 return; |
| 169 } | 181 } |
| 170 | 182 |
| 171 running_ = false; | 183 running_ = false; |
| 172 semaphore_.Signal(); | 184 semaphore_.Signal(); |
| 173 | 185 |
| 174 if ((errno = pthread_join(thread_, nullptr)) != 0) { | 186 thread_->Join(); |
| 175 PLOG(ERROR) << "pthread_join"; | 187 thread_.reset(); |
| 176 DCHECK(false); | |
| 177 } | |
| 178 | |
| 179 thread_ = 0; | |
| 180 } | 188 } |
| 181 | 189 |
| 182 void CrashReportUploadThread::ReportPending() { | 190 void CrashReportUploadThread::ReportPending() { |
| 183 semaphore_.Signal(); | 191 semaphore_.Signal(); |
| 184 } | 192 } |
| 185 | 193 |
| 186 void CrashReportUploadThread::ThreadMain() { | 194 void CrashReportUploadThread::ThreadMain() { |
| 187 while (running_) { | 195 while (running_) { |
| 188 ProcessPendingReports(); | 196 ProcessPendingReports(); |
| 189 | 197 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 336 |
| 329 for (const auto& kv : parameters) { | 337 for (const auto& kv : parameters) { |
| 330 if (kv.first == kMinidumpKey) { | 338 if (kv.first == kMinidumpKey) { |
| 331 LOG(WARNING) << "reserved key " << kv.first << ", discarding value " | 339 LOG(WARNING) << "reserved key " << kv.first << ", discarding value " |
| 332 << kv.second; | 340 << kv.second; |
| 333 } else { | 341 } else { |
| 334 http_multipart_builder.SetFormData(kv.first, kv.second); | 342 http_multipart_builder.SetFormData(kv.first, kv.second); |
| 335 } | 343 } |
| 336 } | 344 } |
| 337 | 345 |
| 338 http_multipart_builder.SetFileAttachment(kMinidumpKey, | 346 http_multipart_builder.SetFileAttachment( |
| 339 report->file_path.BaseName().value(), | 347 kMinidumpKey, |
| 340 report->file_path, | 348 #if defined(OS_WIN) |
| 341 "application/octet-stream"); | 349 base::UTF16ToUTF8(report->file_path.BaseName().value()), |
| 350 #else | |
| 351 report->file_path.BaseName().value(), | |
| 352 #endif | |
| 353 report->file_path, | |
| 354 "application/octet-stream"); | |
| 342 | 355 |
| 343 scoped_ptr<HTTPTransport> http_transport(HTTPTransport::Create()); | 356 scoped_ptr<HTTPTransport> http_transport(HTTPTransport::Create()); |
| 344 http_transport->SetURL(url_); | 357 http_transport->SetURL(url_); |
| 345 HTTPHeaders::value_type content_type = | 358 HTTPHeaders::value_type content_type = |
| 346 http_multipart_builder.GetContentType(); | 359 http_multipart_builder.GetContentType(); |
| 347 http_transport->SetHeader(content_type.first, content_type.second); | 360 http_transport->SetHeader(content_type.first, content_type.second); |
| 348 http_transport->SetBodyStream(http_multipart_builder.GetBodyStream().Pass()); | 361 http_transport->SetBodyStream(http_multipart_builder.GetBodyStream().Pass()); |
| 349 // TODO(mark): The timeout should be configurable by the client. | 362 // TODO(mark): The timeout should be configurable by the client. |
| 350 http_transport->SetTimeout(60.0); // 1 minute. | 363 http_transport->SetTimeout(60.0); // 1 minute. |
| 351 | 364 |
| 352 if (!http_transport->ExecuteSynchronously(response_body)) { | 365 if (!http_transport->ExecuteSynchronously(response_body)) { |
| 353 return UploadResult::kRetry; | 366 return UploadResult::kRetry; |
| 354 } | 367 } |
| 355 | 368 |
| 356 return UploadResult::kSuccess; | 369 return UploadResult::kSuccess; |
| 357 } | 370 } |
| 358 | 371 |
| 359 // static | |
| 360 void* CrashReportUploadThread::RunThreadMain(void* arg) { | |
| 361 CrashReportUploadThread* self = static_cast<CrashReportUploadThread*>(arg); | |
| 362 self->ThreadMain(); | |
| 363 return nullptr; | |
| 364 } | |
| 365 | |
| 366 } // namespace crashpad | 372 } // namespace crashpad |
| OLD | NEW |