OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/loader/upload_progress_tracker.h" | 5 #include "content/browser/loader/upload_progress_tracker.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/upload_progress.h" | 8 #include "net/base/upload_progress.h" |
9 #include "net/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 namespace { | 12 namespace { |
13 // The interval for calls to ReportUploadProgress. | 13 // The interval for calls to ReportUploadProgress. |
14 constexpr base::TimeDelta kUploadProgressInterval = | 14 constexpr base::TimeDelta kUploadProgressInterval = |
15 base::TimeDelta::FromMilliseconds(100); | 15 base::TimeDelta::FromMilliseconds(100); |
16 } // namespace | 16 } // namespace |
17 | 17 |
18 UploadProgressTracker::UploadProgressTracker( | 18 UploadProgressTracker::UploadProgressTracker( |
19 const tracked_objects::Location& location, | 19 const tracked_objects::Location& location, |
20 UploadProgressReportCallback report_progress, | 20 UploadProgressReportCallback report_progress, |
21 net::URLRequest* request, | 21 net::URLRequest* request, |
22 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 22 scoped_refptr<base::SequencedTaskRunner> task_runner) |
23 : request_(request), report_progress_(std::move(report_progress)) { | 23 : request_(request), report_progress_(std::move(report_progress)) { |
24 DCHECK(report_progress_); | 24 DCHECK(report_progress_); |
25 | 25 |
26 progress_timer_.SetTaskRunner(std::move(task_runner)); | 26 progress_timer_.SetTaskRunner(std::move(task_runner)); |
27 progress_timer_.Start(location, kUploadProgressInterval, this, | 27 progress_timer_.Start(location, kUploadProgressInterval, this, |
28 &UploadProgressTracker::ReportUploadProgressIfNeeded); | 28 &UploadProgressTracker::ReportUploadProgressIfNeeded); |
29 } | 29 } |
30 | 30 |
31 UploadProgressTracker::~UploadProgressTracker() {} | 31 UploadProgressTracker::~UploadProgressTracker() {} |
32 | 32 |
33 void UploadProgressTracker::OnAckReceived() { | 33 void UploadProgressTracker::OnAckReceived() { |
34 waiting_for_upload_progress_ack_ = false; | 34 waiting_for_upload_progress_ack_ = false; |
35 } | 35 } |
36 | 36 |
37 void UploadProgressTracker::OnUploadCompleted() { | 37 void UploadProgressTracker::OnUploadCompleted() { |
38 waiting_for_upload_progress_ack_ = false; | 38 waiting_for_upload_progress_ack_ = false; |
39 ReportUploadProgressIfNeeded(); | 39 ReportUploadProgressIfNeeded(); |
40 progress_timer_.Stop(); | 40 progress_timer_.Stop(); |
41 } | 41 } |
42 | 42 |
| 43 // static |
| 44 base::TimeDelta UploadProgressTracker::GetUploadProgressIntervalForTesting() { |
| 45 return kUploadProgressInterval; |
| 46 } |
| 47 |
43 base::TimeTicks UploadProgressTracker::GetCurrentTime() const { | 48 base::TimeTicks UploadProgressTracker::GetCurrentTime() const { |
44 return base::TimeTicks::Now(); | 49 return base::TimeTicks::Now(); |
45 } | 50 } |
46 | 51 |
47 net::UploadProgress UploadProgressTracker::GetUploadProgress() const { | 52 net::UploadProgress UploadProgressTracker::GetUploadProgress() const { |
48 return request_->GetUploadProgress(); | 53 return request_->GetUploadProgress(); |
49 } | 54 } |
50 | 55 |
51 void UploadProgressTracker::ReportUploadProgressIfNeeded() { | 56 void UploadProgressTracker::ReportUploadProgressIfNeeded() { |
52 if (waiting_for_upload_progress_ack_) | 57 if (waiting_for_upload_progress_ack_) |
(...skipping 22 matching lines...) Expand all Loading... |
75 | 80 |
76 if (is_finished || enough_new_progress || too_much_time_passed) { | 81 if (is_finished || enough_new_progress || too_much_time_passed) { |
77 report_progress_.Run(progress); | 82 report_progress_.Run(progress); |
78 waiting_for_upload_progress_ack_ = true; | 83 waiting_for_upload_progress_ack_ = true; |
79 last_upload_ticks_ = now; | 84 last_upload_ticks_ = now; |
80 last_upload_position_ = progress.position(); | 85 last_upload_position_ = progress.position(); |
81 } | 86 } |
82 } | 87 } |
83 | 88 |
84 } // namespace content | 89 } // namespace content |
OLD | NEW |