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

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

Issue 2612903008: Add UploadProgressTracker unittest (Closed)
Patch Set: -gmock 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"
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 {
28 public: 33 public:
29 using UploadProgressReportCallback = 34 class CONTENT_EXPORT Client {
30 base::RepeatingCallback<void(int64_t, int64_t)>; 35 public:
36 virtual net::UploadProgress GetUploadProgress() = 0;
mmenke 2017/01/11 19:31:13 Since we're returning this (And not just by ref or
tzik 2017/01/12 13:00:57 Done.
37 virtual void ReportUploadProgress(int64_t current_position,
38 int64_t total_size) = 0;
mmenke 2017/01/11 19:31:13 Should document these. Also, why doesn't Reporter
tzik 2017/01/12 13:00:56 Done. Updated the reporting function to take a ne
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 protected:
58 virtual base::TimeTicks GetCurrentTime();
mmenke 2017/01/11 19:31:13 Maybe add a comment that this can be overridden fo
mmenke 2017/01/11 19:31:13 const?
mmenke 2017/01/11 19:31:13 nit: Can be private (Subclasses can override priv
tzik 2017/01/12 13:00:56 Done.
tzik 2017/01/12 13:00:56 Done.
tzik 2017/01/12 13:00:57 Done.
59
40 private: 60 private:
41 void ReportUploadProgressIfNeeded(); 61 void ReportUploadProgressIfNeeded();
42 62
43 net::URLRequest* request_; // Not owned. 63 Client* client_; // Not owned.
44 64
45 uint64_t last_upload_position_ = 0; 65 uint64_t last_upload_position_ = 0;
46 bool waiting_for_upload_progress_ack_ = false; 66 bool waiting_for_upload_progress_ack_ = false;
47 base::TimeTicks last_upload_ticks_; 67 base::TimeTicks last_upload_ticks_;
48 base::RepeatingTimer progress_timer_; 68 base::RepeatingTimer progress_timer_;
49 69
50 UploadProgressReportCallback report_progress_;
51
52 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); 70 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker);
53 }; 71 };
54 72
55 } // namespace content 73 } // namespace content
56 74
57 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ 75 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698