OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/feedback/feedback_uploader.h" | 5 #include "components/feedback/feedback_uploader.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/task_scheduler/post_task.h" |
15 #include "components/feedback/feedback_report.h" | 15 #include "components/feedback/feedback_report.h" |
16 | 16 |
17 namespace feedback { | 17 namespace feedback { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kFeedbackPostUrl[] = | 20 const char kFeedbackPostUrl[] = |
21 "https://www.google.com/tools/feedback/chrome/__submit"; | 21 "https://www.google.com/tools/feedback/chrome/__submit"; |
22 | 22 |
23 const int64_t kRetryDelayMinutes = 60; | 23 const int64_t kRetryDelayMinutes = 60; |
24 | 24 |
25 const base::FilePath::CharType kFeedbackReportPath[] = | 25 const base::FilePath::CharType kFeedbackReportPath[] = |
26 FILE_PATH_LITERAL("Feedback Reports"); | 26 FILE_PATH_LITERAL("Feedback Reports"); |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 bool FeedbackUploader::ReportsUploadTimeComparator::operator()( | 30 bool FeedbackUploader::ReportsUploadTimeComparator::operator()( |
31 const scoped_refptr<FeedbackReport>& a, | 31 const scoped_refptr<FeedbackReport>& a, |
32 const scoped_refptr<FeedbackReport>& b) const { | 32 const scoped_refptr<FeedbackReport>& b) const { |
33 return a->upload_at() > b->upload_at(); | 33 return a->upload_at() > b->upload_at(); |
34 } | 34 } |
35 | 35 |
36 FeedbackUploader::FeedbackUploader(const base::FilePath& path, | 36 FeedbackUploader::FeedbackUploader(const base::FilePath& path) |
37 base::SequencedWorkerPool* pool) | |
38 : report_path_(path.Append(kFeedbackReportPath)), | 37 : report_path_(path.Append(kFeedbackReportPath)), |
39 retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)), | 38 retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)), |
40 url_(kFeedbackPostUrl), | 39 url_(kFeedbackPostUrl) { |
41 pool_(pool) { | |
42 Init(); | 40 Init(); |
43 } | 41 } |
44 | 42 |
45 FeedbackUploader::FeedbackUploader(const base::FilePath& path, | 43 FeedbackUploader::FeedbackUploader(const base::FilePath& path, |
46 base::SequencedWorkerPool* pool, | |
47 const std::string& url) | 44 const std::string& url) |
48 : report_path_(path.Append(kFeedbackReportPath)), | 45 : report_path_(path.Append(kFeedbackReportPath)), |
49 retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)), | 46 retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)), |
50 url_(url), | 47 url_(url) { |
51 pool_(pool) { | |
52 Init(); | 48 Init(); |
53 } | 49 } |
54 | 50 |
55 FeedbackUploader::~FeedbackUploader() {} | 51 FeedbackUploader::~FeedbackUploader() {} |
56 | 52 |
57 void FeedbackUploader::Init() { | 53 void FeedbackUploader::Init() { |
58 dispatch_callback_ = base::Bind(&FeedbackUploader::DispatchReport, | 54 dispatch_callback_ = base::Bind(&FeedbackUploader::DispatchReport, |
59 AsWeakPtr()); | 55 AsWeakPtr()); |
60 } | 56 } |
61 | 57 |
(...skipping 23 matching lines...) Expand all Loading... |
85 | 81 |
86 void FeedbackUploader::RetryReport(const std::string& data) { | 82 void FeedbackUploader::RetryReport(const std::string& data) { |
87 QueueReportWithDelay(data, retry_delay_); | 83 QueueReportWithDelay(data, retry_delay_); |
88 } | 84 } |
89 | 85 |
90 void FeedbackUploader::QueueReportWithDelay(const std::string& data, | 86 void FeedbackUploader::QueueReportWithDelay(const std::string& data, |
91 base::TimeDelta delay) { | 87 base::TimeDelta delay) { |
92 // Uses a BLOCK_SHUTDOWN file task runner because we really don't want to | 88 // Uses a BLOCK_SHUTDOWN file task runner because we really don't want to |
93 // lose reports. | 89 // lose reports. |
94 scoped_refptr<base::SequencedTaskRunner> task_runner = | 90 scoped_refptr<base::SequencedTaskRunner> task_runner = |
95 pool_->GetSequencedTaskRunnerWithShutdownBehavior( | 91 base::CreateSequencedTaskRunnerWithTraits( |
96 pool_->GetSequenceToken(), | 92 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
97 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 93 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
98 | 94 |
99 reports_queue_.push(new FeedbackReport(report_path_, | 95 reports_queue_.push(new FeedbackReport(report_path_, |
100 base::Time::Now() + delay, | 96 base::Time::Now() + delay, |
101 data, | 97 data, |
102 task_runner)); | 98 task_runner)); |
103 UpdateUploadTimer(); | 99 UpdateUploadTimer(); |
104 } | 100 } |
105 | 101 |
106 void FeedbackUploader::setup_for_test( | 102 void FeedbackUploader::setup_for_test( |
107 const ReportDataCallback& dispatch_callback, | 103 const ReportDataCallback& dispatch_callback, |
108 const base::TimeDelta& retry_delay) { | 104 const base::TimeDelta& retry_delay) { |
109 dispatch_callback_ = dispatch_callback; | 105 dispatch_callback_ = dispatch_callback; |
110 retry_delay_ = retry_delay; | 106 retry_delay_ = retry_delay; |
111 } | 107 } |
112 | 108 |
113 } // namespace feedback | 109 } // namespace feedback |
OLD | NEW |