Chromium Code Reviews| Index: chrome/browser/feedback/feedback_uploader.h |
| diff --git a/chrome/browser/feedback/feedback_uploader.h b/chrome/browser/feedback/feedback_uploader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..546fc315e4ad82a023905effcdbba4d20692c62a |
| --- /dev/null |
| +++ b/chrome/browser/feedback/feedback_uploader.h |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |
| +#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |
| + |
| +#include <queue> |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "chrome/browser/feedback/feedback_uploader_delegate.h" |
| +#include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace feedback { |
| + |
| +struct FeedbackReport { |
|
Zachary Kuznia
2013/12/17 01:12:57
I think this class could be implemented in the .cc
rkc
2013/12/17 23:26:00
The struct implementation itself is needed in this
|
| + FeedbackReport(const base::Time& upload_at, scoped_ptr<std::string> data) |
| + : upload_at(upload_at), data(data.Pass()) {} |
| + |
| + FeedbackReport(const FeedbackReport& report) { |
| + upload_at = report.upload_at; |
| + data = report.data.Pass(); |
| + } |
| + |
| + FeedbackReport& operator=( |
|
Zachary Kuznia
2013/12/17 01:12:57
I think this doesn't need a line break.
rkc
2013/12/17 23:26:00
Done.
|
| + const FeedbackReport& report) { |
| + upload_at = report.upload_at; |
| + data = report.data.Pass(); |
| + return *this; |
| + } |
| + |
| + base::Time upload_at; // Upload this report at or after this time. |
| + mutable scoped_ptr<std::string> data; |
| +}; |
| + |
| +// FeedbackUploader is used to add a feedback report to the queue of reports |
| +// being uploaded. In case uploading a report fails, it is written to disk and |
| +// tried again when it's turn comes up next in the queue. |
| +class FeedbackUploader : public BrowserContextKeyedService, |
| + public base::SupportsWeakPtr<FeedbackUploader> { |
| + public: |
| + explicit FeedbackUploader(content::BrowserContext* context); |
| + virtual ~FeedbackUploader(); |
| + |
| + void QueueReport(scoped_ptr<std::string> data); |
| + |
| + private: |
| + friend class FeedbackUploaderTest; |
| + struct ReportsUploadTimeComparator { |
| + bool operator()(const FeedbackReport& a, |
| + const FeedbackReport& b) const { |
| + return a.upload_at > b.upload_at; |
| + } |
| + }; |
| + |
| + // Dispatches the report to be uploaded. |
| + void DispatchReport(scoped_ptr<std::string> data); |
| + |
| + // Update our timer for uploading the next report. |
| + void UpdateUploadTimer(); |
| + |
| + // Requeue this report with a delay. |
| + void RetryReport(scoped_ptr<std::string> data); |
| + |
| + void setup_for_test(const ReportDataCallback& dispatch_callback, |
| + const base::TimeDelta& retry_delay); |
| + |
| + // Browser context this uploader was created for. |
| + content::BrowserContext* context_; |
| + // Timer to upload the next report at. |
| + base::OneShotTimer<FeedbackUploader> upload_timer_; |
| + // Priority queue of reports prioritized by the time the report is supposed |
| + // to be uploaded at. |
| + std::priority_queue<FeedbackReport, |
| + std::vector<FeedbackReport>, |
| + ReportsUploadTimeComparator> reports_queue_; |
| + |
| + std::vector<FeedbackReport> loaded_reports_; |
| + |
| + ReportDataCallback dispatch_callback_; |
| + base::TimeDelta retry_delay_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FeedbackUploader); |
| +}; |
| + |
| +} // namespace feedback |
| + |
| +#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ |