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

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

Issue 225183018: Move feedback files into src/components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps, merge gyp targets, sync with latest Created 6 years, 8 months 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
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 #include "chrome/browser/feedback/feedback_uploader.h"
6
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/sequenced_task_runner.h"
11 #include "base/task_runner_util.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/feedback/feedback_report.h"
14
15 namespace feedback {
16 namespace {
17
18 const char kFeedbackPostUrl[] =
19 "https://www.google.com/tools/feedback/chrome/__submit";
20
21 const int64 kRetryDelayMinutes = 60;
22
23 const base::FilePath::CharType kFeedbackReportPath[] =
24 FILE_PATH_LITERAL("Feedback Reports");
25
26 } // namespace
27
28 bool FeedbackUploader::ReportsUploadTimeComparator::operator()(
29 FeedbackReport* a, FeedbackReport* b) const {
30 return a->upload_at() > b->upload_at();
31 }
32
33 FeedbackUploader::FeedbackUploader(const base::FilePath& path,
34 base::SequencedWorkerPool* pool)
35 : report_path_(path.Append(kFeedbackReportPath)),
36 retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)),
37 url_(kFeedbackPostUrl),
38 pool_(pool) {
39 dispatch_callback_ = base::Bind(&FeedbackUploader::DispatchReport,
40 AsWeakPtr());
41 }
42
43 FeedbackUploader::~FeedbackUploader() {}
44
45 void FeedbackUploader::QueueReport(const std::string& data) {
46 QueueReportWithDelay(data, base::TimeDelta());
47 }
48
49 void FeedbackUploader::UpdateUploadTimer() {
50 if (reports_queue_.empty())
51 return;
52
53 scoped_refptr<FeedbackReport> report = reports_queue_.top();
54 base::Time now = base::Time::Now();
55 if (report->upload_at() <= now) {
56 reports_queue_.pop();
57 dispatch_callback_.Run(report->data());
58 report->DeleteReportOnDisk();
59 } else {
60 // Stop the old timer and start an updated one.
61 if (upload_timer_.IsRunning())
62 upload_timer_.Stop();
63 upload_timer_.Start(
64 FROM_HERE, report->upload_at() - now, this,
65 &FeedbackUploader::UpdateUploadTimer);
66 }
67 }
68
69 void FeedbackUploader::RetryReport(const std::string& data) {
70 QueueReportWithDelay(data, retry_delay_);
71 }
72
73 void FeedbackUploader::QueueReportWithDelay(const std::string& data,
74 base::TimeDelta delay) {
75 // Uses a BLOCK_SHUTDOWN file task runner because we really don't want to
76 // lose reports.
77 scoped_refptr<base::SequencedTaskRunner> task_runner =
78 pool_->GetSequencedTaskRunnerWithShutdownBehavior(
79 pool_->GetSequenceToken(),
80 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
81
82 reports_queue_.push(new FeedbackReport(report_path_,
83 base::Time::Now() + delay,
84 data,
85 task_runner));
86 UpdateUploadTimer();
87 }
88
89 void FeedbackUploader::setup_for_test(
90 const ReportDataCallback& dispatch_callback,
91 const base::TimeDelta& retry_delay) {
92 dispatch_callback_ = dispatch_callback;
93 retry_delay_ = retry_delay;
94 }
95
96 } // namespace feedback
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698