Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/feedback/feedback_uploader.h

Issue 116863002: Add feedback uploader to upload reports in a sequenced manner with retries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 {
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
26 FeedbackReport(const base::Time& upload_at, scoped_ptr<std::string> data)
27 : upload_at(upload_at), data(data.Pass()) {}
28
29 FeedbackReport(const FeedbackReport& report) {
30 upload_at = report.upload_at;
31 data = report.data.Pass();
32 }
33
34 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.
35 const FeedbackReport& report) {
36 upload_at = report.upload_at;
37 data = report.data.Pass();
38 return *this;
39 }
40
41 base::Time upload_at; // Upload this report at or after this time.
42 mutable scoped_ptr<std::string> data;
43 };
44
45 // FeedbackUploader is used to add a feedback report to the queue of reports
46 // being uploaded. In case uploading a report fails, it is written to disk and
47 // tried again when it's turn comes up next in the queue.
48 class FeedbackUploader : public BrowserContextKeyedService,
49 public base::SupportsWeakPtr<FeedbackUploader> {
50 public:
51 explicit FeedbackUploader(content::BrowserContext* context);
52 virtual ~FeedbackUploader();
53
54 void QueueReport(scoped_ptr<std::string> data);
55
56 private:
57 friend class FeedbackUploaderTest;
58 struct ReportsUploadTimeComparator {
59 bool operator()(const FeedbackReport& a,
60 const FeedbackReport& b) const {
61 return a.upload_at > b.upload_at;
62 }
63 };
64
65 // Dispatches the report to be uploaded.
66 void DispatchReport(scoped_ptr<std::string> data);
67
68 // Update our timer for uploading the next report.
69 void UpdateUploadTimer();
70
71 // Requeue this report with a delay.
72 void RetryReport(scoped_ptr<std::string> data);
73
74 void setup_for_test(const ReportDataCallback& dispatch_callback,
75 const base::TimeDelta& retry_delay);
76
77 // Browser context this uploader was created for.
78 content::BrowserContext* context_;
79 // Timer to upload the next report at.
80 base::OneShotTimer<FeedbackUploader> upload_timer_;
81 // Priority queue of reports prioritized by the time the report is supposed
82 // to be uploaded at.
83 std::priority_queue<FeedbackReport,
84 std::vector<FeedbackReport>,
85 ReportsUploadTimeComparator> reports_queue_;
86
87 std::vector<FeedbackReport> loaded_reports_;
88
89 ReportDataCallback dispatch_callback_;
90 base::TimeDelta retry_delay_;
91
92 DISALLOW_COPY_AND_ASSIGN(FeedbackUploader);
93 };
94
95 } // namespace feedback
96
97 #endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698