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

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

Issue 2491613004: Make base::Timer sequence-friendly. (Closed)
Patch Set: add back commented out DCHECK in Stop() Created 3 years, 6 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" 12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/sequenced_task_runner_handle.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "net/base/upload_progress.h" 18 #include "net/base/upload_progress.h"
19 19
20 namespace base {
21 class SingleThreadTaskRunner;
22 }
23
24 namespace tracked_objects { 20 namespace tracked_objects {
25 class Location; 21 class Location;
26 } 22 }
27 23
28 namespace net { 24 namespace net {
29 class URLRequest; 25 class URLRequest;
30 } 26 }
31 27
32 namespace content { 28 namespace content {
33 29
34 // UploadProgressTracker watches the upload progress of a URL loading, and sends 30 // UploadProgressTracker watches the upload progress of a URL loading, and sends
35 // the progress to the client in a suitable granularity and frequency. 31 // the progress to the client in a suitable granularity and frequency.
36 class CONTENT_EXPORT UploadProgressTracker { 32 class CONTENT_EXPORT UploadProgressTracker {
37 public: 33 public:
38 using UploadProgressReportCallback = 34 using UploadProgressReportCallback =
39 base::RepeatingCallback<void(const net::UploadProgress&)>; 35 base::RepeatingCallback<void(const net::UploadProgress&)>;
40 36
41 UploadProgressTracker(const tracked_objects::Location& location, 37 UploadProgressTracker(const tracked_objects::Location& location,
42 UploadProgressReportCallback report_progress, 38 UploadProgressReportCallback report_progress,
43 net::URLRequest* request, 39 net::URLRequest* request,
44 scoped_refptr<base::SingleThreadTaskRunner> 40 scoped_refptr<base::SequencedTaskRunner> task_runner =
45 task_runner = base::ThreadTaskRunnerHandle::Get()); 41 base::SequencedTaskRunnerHandle::Get());
46 ~UploadProgressTracker(); 42 ~UploadProgressTracker();
47 43
48 void OnAckReceived(); 44 void OnAckReceived();
49 void OnUploadCompleted(); 45 void OnUploadCompleted();
50 46
47 static base::TimeDelta GetUploadProgressIntervalForTesting();
48
51 private: 49 private:
52 // Overridden by tests to use a fake time and progress. 50 // Overridden by tests to use a fake time and progress.
53 virtual base::TimeTicks GetCurrentTime() const; 51 virtual base::TimeTicks GetCurrentTime() const;
54 virtual net::UploadProgress GetUploadProgress() const; 52 virtual net::UploadProgress GetUploadProgress() const;
55 53
56 void ReportUploadProgressIfNeeded(); 54 void ReportUploadProgressIfNeeded();
57 55
58 net::URLRequest* request_; // Not owned. 56 net::URLRequest* request_; // Not owned.
59 57
60 uint64_t last_upload_position_ = 0; 58 uint64_t last_upload_position_ = 0;
61 bool waiting_for_upload_progress_ack_ = false; 59 bool waiting_for_upload_progress_ack_ = false;
62 base::TimeTicks last_upload_ticks_; 60 base::TimeTicks last_upload_ticks_;
63 base::RepeatingTimer progress_timer_; 61 base::RepeatingTimer progress_timer_;
64 62
65 UploadProgressReportCallback report_progress_; 63 UploadProgressReportCallback report_progress_;
66 64
67 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker); 65 DISALLOW_COPY_AND_ASSIGN(UploadProgressTracker);
68 }; 66 };
69 67
70 } // namespace content 68 } // namespace content
71 69
72 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_ 70 #endif // CONTENT_BROWSER_LOADER_UPLOAD_PROGRESS_TRACKER_H_
OLDNEW
« no previous file with comments | « build/sanitizers/tsan_suppressions.cc ('k') | content/browser/loader/upload_progress_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698