| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" |
| 14 |
| 15 namespace tracked_objects { |
| 16 class Location; |
| 17 } |
| 18 |
| 19 namespace net { |
| 20 class URLRequest; |
| 21 } |
| 22 |
| 23 namespace content { |
| 24 |
| 25 // UploadProgressTracker watches the upload progress of a URL loading, and sends |
| 26 // the progress to the client in a suitable granularity and frequency. |
| 27 class UploadProgressTracker final { |
| 28 public: |
| 29 using UploadProgressReportCallback = |
| 30 base::RepeatingCallback<void(int64_t, int64_t)>; |
| 31 |
| 32 UploadProgressTracker(const tracked_objects::Location& location, |
| 33 UploadProgressReportCallback report_progress, |
| 34 net::URLRequest* request); |
| 35 ~UploadProgressTracker(); |
| 36 |
| 37 void OnAckReceived(); |
| 38 void OnUploadCompleted(); |
| 39 |
| 40 private: |
| 41 void ReportUploadProgressIfNeeded(); |
| 42 |
| 43 net::URLRequest* request_; // Not owned. |
| 44 |
| 45 uint64_t last_upload_position_ = 0; |
| 46 bool waiting_for_upload_progress_ack_ = false; |
| 47 base::TimeTicks last_upload_ticks_; |
| 48 base::RepeatingTimer progress_timer_; |
| 49 |
| 50 UploadProgressReportCallback report_progress_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); |
| 53 }; |
| 54 |
| 55 } // namespace content |
| 56 |
| 57 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| OLD | NEW |