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, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 private: | 130 private: |
131 CrashReportDatabase* database_; // weak | 131 CrashReportDatabase* database_; // weak |
132 const CrashReportDatabase::Report* report_; // weak | 132 const CrashReportDatabase::Report* report_; // weak |
133 | 133 |
134 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt); | 134 DISALLOW_COPY_AND_ASSIGN(CallRecordUploadAttempt); |
135 }; | 135 }; |
136 | 136 |
137 } // namespace | 137 } // namespace |
138 | 138 |
139 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, | 139 CrashReportUploadThread::CrashReportUploadThread(CrashReportDatabase* database, |
140 const std::string& url) | 140 const std::string& url, |
| 141 bool rate_limit) |
141 : url_(url), | 142 : url_(url), |
142 // Check for pending reports every 15 minutes, even in the absence of a | 143 // Check for pending reports every 15 minutes, even in the absence of a |
143 // signal from the handler thread. This allows for failed uploads to be | 144 // signal from the handler thread. This allows for failed uploads to be |
144 // retried periodically, and for pending reports written by other | 145 // retried periodically, and for pending reports written by other |
145 // processes to be recognized. | 146 // processes to be recognized. |
146 thread_(15 * 60, this), | 147 thread_(15 * 60, this), |
147 database_(database) { | 148 database_(database), |
| 149 rate_limit_(rate_limit) { |
148 } | 150 } |
149 | 151 |
150 CrashReportUploadThread::~CrashReportUploadThread() { | 152 CrashReportUploadThread::~CrashReportUploadThread() { |
151 } | 153 } |
152 | 154 |
153 void CrashReportUploadThread::Start() { | 155 void CrashReportUploadThread::Start() { |
154 thread_.Start(0); | 156 thread_.Start(0); |
155 } | 157 } |
156 | 158 |
157 void CrashReportUploadThread::Stop() { | 159 void CrashReportUploadThread::Stop() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return; | 199 return; |
198 } | 200 } |
199 | 201 |
200 // This currently implements very simplistic rate-limiting, compatible with | 202 // This currently implements very simplistic rate-limiting, compatible with |
201 // the Breakpad client, where the strategy is to permit one upload attempt per | 203 // the Breakpad client, where the strategy is to permit one upload attempt per |
202 // hour, and retire reports that would exceed this limit or for which the | 204 // hour, and retire reports that would exceed this limit or for which the |
203 // upload fails on the first attempt. | 205 // upload fails on the first attempt. |
204 // | 206 // |
205 // TODO(mark): Provide a proper rate-limiting strategy and allow for failed | 207 // TODO(mark): Provide a proper rate-limiting strategy and allow for failed |
206 // upload attempts to be retried. | 208 // upload attempts to be retried. |
207 time_t last_upload_attempt_time; | 209 if (rate_limit_) { |
208 if (settings->GetLastUploadAttemptTime(&last_upload_attempt_time)) { | 210 time_t last_upload_attempt_time; |
209 time_t now = time(nullptr); | 211 if (settings->GetLastUploadAttemptTime(&last_upload_attempt_time)) { |
210 if (now >= last_upload_attempt_time) { | 212 time_t now = time(nullptr); |
211 // If the most recent upload attempt occurred within the past hour, don’t | 213 if (now >= last_upload_attempt_time) { |
212 // attempt to upload the new report. If it happened longer ago, attempt to | 214 // If the most recent upload attempt occurred within the past hour, |
213 // upload the report. | 215 // don’t attempt to upload the new report. If it happened longer ago, |
214 const int kUploadAttemptIntervalSeconds = 60 * 60; // 1 hour | 216 // attempt to upload the report. |
215 if (now - last_upload_attempt_time < kUploadAttemptIntervalSeconds) { | 217 const int kUploadAttemptIntervalSeconds = 60 * 60; // 1 hour |
216 database_->SkipReportUpload(report.uuid); | 218 if (now - last_upload_attempt_time < kUploadAttemptIntervalSeconds) { |
217 return; | 219 database_->SkipReportUpload(report.uuid); |
218 } | 220 return; |
219 } else { | 221 } |
220 // The most recent upload attempt purportedly occurred in the future. If | 222 } else { |
221 // it “happened” at least one day in the future, assume that the last | 223 // The most recent upload attempt purportedly occurred in the future. If |
222 // upload attempt time is bogus, and attempt to upload the report. If the | 224 // it “happened” at least one day in the future, assume that the last |
223 // most recent upload time is in the future but within one day, accept it | 225 // upload attempt time is bogus, and attempt to upload the report. If |
224 // and don’t attempt to upload the report. | 226 // the most recent upload time is in the future but within one day, |
225 const int kBackwardsClockTolerance = 60 * 60 * 24; // 1 day | 227 // accept it and don’t attempt to upload the report. |
226 if (last_upload_attempt_time - now < kBackwardsClockTolerance) { | 228 const int kBackwardsClockTolerance = 60 * 60 * 24; // 1 day |
227 database_->SkipReportUpload(report.uuid); | 229 if (last_upload_attempt_time - now < kBackwardsClockTolerance) { |
228 return; | 230 database_->SkipReportUpload(report.uuid); |
| 231 return; |
| 232 } |
229 } | 233 } |
230 } | 234 } |
231 } | 235 } |
232 | 236 |
233 const CrashReportDatabase::Report* upload_report; | 237 const CrashReportDatabase::Report* upload_report; |
234 CrashReportDatabase::OperationStatus status = | 238 CrashReportDatabase::OperationStatus status = |
235 database_->GetReportForUploading(report.uuid, &upload_report); | 239 database_->GetReportForUploading(report.uuid, &upload_report); |
236 switch (status) { | 240 switch (status) { |
237 case CrashReportDatabase::kNoError: | 241 case CrashReportDatabase::kNoError: |
238 break; | 242 break; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 330 } |
327 | 331 |
328 return UploadResult::kSuccess; | 332 return UploadResult::kSuccess; |
329 } | 333 } |
330 | 334 |
331 void CrashReportUploadThread::DoWork(const WorkerThread* thread) { | 335 void CrashReportUploadThread::DoWork(const WorkerThread* thread) { |
332 ProcessPendingReports(); | 336 ProcessPendingReports(); |
333 } | 337 } |
334 | 338 |
335 } // namespace crashpad | 339 } // namespace crashpad |
OLD | NEW |