OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |
| 7 |
| 8 #include <queue> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" |
| 15 #include "base/timer/timer.h" |
| 16 #include "chrome/browser/feedback/feedback_uploader_delegate.h" |
| 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 18 |
| 19 namespace content { |
| 20 class BrowserContext; |
| 21 } |
| 22 |
| 23 namespace feedback { |
| 24 |
| 25 struct FeedbackReport; |
| 26 |
| 27 // FeedbackUploader is used to add a feedback report to the queue of reports |
| 28 // being uploaded. In case uploading a report fails, it is written to disk and |
| 29 // tried again when it's turn comes up next in the queue. |
| 30 class FeedbackUploader : public BrowserContextKeyedService, |
| 31 public base::SupportsWeakPtr<FeedbackUploader> { |
| 32 public: |
| 33 explicit FeedbackUploader(content::BrowserContext* context); |
| 34 virtual ~FeedbackUploader(); |
| 35 |
| 36 void QueueReport(scoped_ptr<std::string> data); |
| 37 |
| 38 private: |
| 39 friend class FeedbackUploaderTest; |
| 40 struct ReportsUploadTimeComparator { |
| 41 bool operator()(const FeedbackReport& a, const FeedbackReport& b) const; |
| 42 }; |
| 43 |
| 44 // Dispatches the report to be uploaded. |
| 45 void DispatchReport(scoped_ptr<std::string> data); |
| 46 |
| 47 // Update our timer for uploading the next report. |
| 48 void UpdateUploadTimer(); |
| 49 |
| 50 // Requeue this report with a delay. |
| 51 void RetryReport(scoped_ptr<std::string> data); |
| 52 |
| 53 void setup_for_test(const ReportDataCallback& dispatch_callback, |
| 54 const base::TimeDelta& retry_delay); |
| 55 |
| 56 // Browser context this uploader was created for. |
| 57 content::BrowserContext* context_; |
| 58 // Timer to upload the next report at. |
| 59 base::OneShotTimer<FeedbackUploader> upload_timer_; |
| 60 // Priority queue of reports prioritized by the time the report is supposed |
| 61 // to be uploaded at. |
| 62 std::priority_queue<FeedbackReport, |
| 63 std::vector<FeedbackReport>, |
| 64 ReportsUploadTimeComparator> reports_queue_; |
| 65 |
| 66 std::vector<FeedbackReport> loaded_reports_; |
| 67 |
| 68 ReportDataCallback dispatch_callback_; |
| 69 base::TimeDelta retry_delay_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(FeedbackUploader); |
| 72 }; |
| 73 |
| 74 } // namespace feedback |
| 75 |
| 76 #endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |
OLD | NEW |