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

Side by Side Diff: content/browser/loader/upload_progress_tracker.h

Issue 2612903008: Add UploadProgressTracker unittest (Closed)
Patch Set: +#include Created 3 years, 11 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
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" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/time/time.h" 15 #include "base/time/time.h"
13 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "content/common/content_export.h"
18 #include "net/base/upload_progress.h"
19
20 namespace base {
21 class SingleThreadTaskRunner;
22 }
14 23
15 namespace tracked_objects { 24 namespace tracked_objects {
16 class Location; 25 class Location;
17 } 26 }
18 27
19 namespace net { 28 namespace net {
20 class URLRequest; 29 class URLRequest;
21 } 30 }
22 31
23 namespace content { 32 namespace content {
24 33
25 // UploadProgressTracker watches the upload progress of a URL loading, and sends 34 // UploadProgressTracker watches the upload progress of a URL loading, and sends
26 // the progress to the client in a suitable granularity and frequency. 35 // the progress to the client in a suitable granularity and frequency.
27 class UploadProgressTracker final { 36 class CONTENT_EXPORT UploadProgressTracker {
28 public: 37 public:
29 using UploadProgressReportCallback = 38 using UploadProgressReportCallback =
30 base::RepeatingCallback<void(int64_t, int64_t)>; 39 base::RepeatingCallback<void(const net::UploadProgress&)>;
31 40
32 UploadProgressTracker(const tracked_objects::Location& location, 41 UploadProgressTracker(const tracked_objects::Location& location,
33 UploadProgressReportCallback report_progress, 42 UploadProgressReportCallback report_progress,
34 net::URLRequest* request); 43 net::URLRequest* request,
44 scoped_refptr<base::SingleThreadTaskRunner>
45 task_runner = base::ThreadTaskRunnerHandle::Get());
35 ~UploadProgressTracker(); 46 ~UploadProgressTracker();
36 47
37 void OnAckReceived(); 48 void OnAckReceived();
38 void OnUploadCompleted(); 49 void OnUploadCompleted();
39 50
40 private: 51 private:
52 // Overridden by tests to use a fake time and progress.
53 virtual base::TimeTicks GetCurrentTime() const;
54 virtual net::UploadProgress GetUploadProgress() const;
55
41 void ReportUploadProgressIfNeeded(); 56 void ReportUploadProgressIfNeeded();
42 57
43 net::URLRequest* request_; // Not owned. 58 net::URLRequest* request_; // Not owned.
44 59
45 uint64_t last_upload_position_ = 0; 60 uint64_t last_upload_position_ = 0;
46 bool waiting_for_upload_progress_ack_ = false; 61 bool waiting_for_upload_progress_ack_ = false;
47 base::TimeTicks last_upload_ticks_; 62 base::TimeTicks last_upload_ticks_;
48 base::RepeatingTimer progress_timer_; 63 base::RepeatingTimer progress_timer_;
49 64
50 UploadProgressReportCallback report_progress_; 65 UploadProgressReportCallback report_progress_;
51 66
52 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); 67 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker);
53 }; 68 };
54 69
55 } // namespace content 70 } // namespace content
56 71
57 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ 72 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698