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.
5 #ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_
6 #define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_
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"
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
> {
33 explicit FeedbackUploader(content::BrowserContext
* context
);
34 virtual ~FeedbackUploader();
36 // Queues a report for uploading.
37 void QueueReport(const std::string
& data
);
40 friend class FeedbackUploaderTest
;
41 struct ReportsUploadTimeComparator
{
42 bool operator()(FeedbackReport
* a
, FeedbackReport
* b
) const;
45 // Dispatches the report to be uploaded.
46 void DispatchReport(const std::string
& data
);
48 // Loads any unsent reports from disk and queues them to be uploaded in
49 // the given browser context.
50 void QueueUnsentReports(content::BrowserContext
* context
);
52 // Update our timer for uploading the next report.
53 void UpdateUploadTimer();
55 // Requeue this report with a delay.
56 void RetryReport(const std::string
& data
);
58 void setup_for_test(const ReportDataCallback
& dispatch_callback
,
59 const base::TimeDelta
& retry_delay
);
61 // Browser context this uploader was created for.
62 content::BrowserContext
* context_
;
63 // Timer to upload the next report at.
64 base::OneShotTimer
<FeedbackUploader
> upload_timer_
;
65 // Priority queue of reports prioritized by the time the report is supposed
67 std::priority_queue
<scoped_refptr
<FeedbackReport
>,
68 std::vector
<scoped_refptr
<FeedbackReport
> >,
69 ReportsUploadTimeComparator
> reports_queue_
;
71 ReportDataCallback dispatch_callback_
;
72 base::TimeDelta retry_delay_
;
74 DISALLOW_COPY_AND_ASSIGN(FeedbackUploader
);
77 } // namespace feedback
79 #endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_