Chromium Code Reviews| 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 #ifndef CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ | 6 #define CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "content/common/content_export.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SingleThreadTaskRunner; | |
| 18 } | |
| 14 | 19 |
| 15 namespace tracked_objects { | 20 namespace tracked_objects { |
| 16 class Location; | 21 class Location; |
| 17 } | 22 } |
| 18 | 23 |
| 19 namespace net { | 24 namespace net { |
| 20 class URLRequest; | 25 class UploadProgress; |
| 21 } | 26 } |
| 22 | 27 |
| 23 namespace content { | 28 namespace content { |
| 24 | 29 |
| 25 // UploadProgressTracker watches the upload progress of a URL loading, and sends | 30 // UploadProgressTracker watches the upload progress of a URL loading, and sends |
| 26 // the progress to the client in a suitable granularity and frequency. | 31 // the progress to the client in a suitable granularity and frequency. |
| 27 class UploadProgressTracker final { | 32 class CONTENT_EXPORT UploadProgressTracker final { |
| 28 public: | 33 public: |
| 29 using UploadProgressReportCallback = | 34 class Client { |
| 30 base::RepeatingCallback<void(int64_t, int64_t)>; | 35 public: |
| 36 virtual net::UploadProgress GetUploadProgress() = 0; | |
| 37 virtual void ReportUploadProgress(int64_t current_position, | |
| 38 int64_t total_size) = 0; | |
| 31 | 39 |
| 32 UploadProgressTracker(const tracked_objects::Location& location, | 40 protected: |
| 33 UploadProgressReportCallback report_progress, | 41 Client(); |
| 34 net::URLRequest* request); | 42 virtual ~Client(); |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(Client); | |
| 46 }; | |
| 47 | |
| 48 UploadProgressTracker( | |
| 49 const tracked_objects::Location& location, | |
| 50 Client* client, | |
| 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 35 ~UploadProgressTracker(); | 52 ~UploadProgressTracker(); |
| 36 | 53 |
| 37 void OnAckReceived(); | 54 void OnAckReceived(); |
| 38 void OnUploadCompleted(); | 55 void OnUploadCompleted(); |
| 39 | 56 |
| 57 void SetLastUploadTicksForTesting(const base::TimeTicks& ticks) { | |
|
mmenke
2017/01/06 15:54:53
Think this delves too much into the underlying cod
tzik
2017/01/10 06:54:41
Done.
| |
| 58 last_upload_ticks_ = ticks; | |
| 59 } | |
| 60 | |
| 40 private: | 61 private: |
| 41 void ReportUploadProgressIfNeeded(); | 62 void ReportUploadProgressIfNeeded(); |
| 42 | 63 |
| 43 net::URLRequest* request_; // Not owned. | 64 Client* client_; // Not owned. |
| 44 | 65 |
| 45 uint64_t last_upload_position_ = 0; | 66 uint64_t last_upload_position_ = 0; |
| 46 bool waiting_for_upload_progress_ack_ = false; | 67 bool waiting_for_upload_progress_ack_ = false; |
| 47 base::TimeTicks last_upload_ticks_; | 68 base::TimeTicks last_upload_ticks_; |
| 48 base::RepeatingTimer progress_timer_; | 69 base::RepeatingTimer progress_timer_; |
| 49 | 70 |
| 50 UploadProgressReportCallback report_progress_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); | 71 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); |
| 53 }; | 72 }; |
| 54 | 73 |
| 55 } // namespace content | 74 } // namespace content |
| 56 | 75 |
| 57 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ | 76 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ |
| OLD | NEW |