#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_
#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_
#include <queue>
#include <string>
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
namespace feedback {
typedef base::Callback<void(const std::string&)> ReportDataCallback;
class FeedbackReport;
class FeedbackUploader : public base::SupportsWeakPtr<FeedbackUploader> {
public:
explicit FeedbackUploader(const base::FilePath& path,
base::SequencedWorkerPool* pool);
virtual ~FeedbackUploader();
void QueueReport(const std::string& data);
base::FilePath GetFeedbackReportsPath() { return report_path_; }
protected:
friend class FeedbackUploaderTest;
struct ReportsUploadTimeComparator {
bool operator()(FeedbackReport* a, FeedbackReport* b) const;
};
virtual void DispatchReport(const std::string& data) = 0;
void UpdateUploadTimer();
void RetryReport(const std::string& data);
void QueueReportWithDelay(const std::string& data, base::TimeDelta delay);
void setup_for_test(const ReportDataCallback& dispatch_callback,
const base::TimeDelta& retry_delay);
base::FilePath report_path_;
base::OneShotTimer<FeedbackUploader> upload_timer_;
std::priority_queue<scoped_refptr<FeedbackReport>,
std::vector<scoped_refptr<FeedbackReport> >,
ReportsUploadTimeComparator> reports_queue_;
ReportDataCallback dispatch_callback_;
base::TimeDelta retry_delay_;
std::string url_;
base::SequencedWorkerPool* pool_;
DISALLOW_COPY_AND_ASSIGN(FeedbackUploader);
};
}
#endif