OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ | 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ |
6 #define COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ | 6 #define COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_vector.h" | |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "components/domain_reliability/domain_reliability_export.h" | 12 #include "components/domain_reliability/domain_reliability_export.h" |
14 #include "net/base/backoff_entry.h" | |
15 | 13 |
16 namespace base { | 14 namespace base { |
17 class Value; | 15 class Value; |
18 } // namespace base | 16 } // namespace base |
19 | 17 |
20 namespace domain_reliability { | 18 namespace domain_reliability { |
21 | 19 |
22 class DomainReliabilityConfig; | 20 class DomainReliabilityConfig; |
23 class MockableTime; | 21 class MockableTime; |
24 | 22 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // future retries, if the upload ends up failing.) | 64 // future retries, if the upload ends up failing.) |
67 size_t OnUploadStart(); | 65 size_t OnUploadStart(); |
68 | 66 |
69 // Updates the scheduler state based on the result of an upload. Must be | 67 // Updates the scheduler state based on the result of an upload. Must be |
70 // called exactly once after |OnUploadStart|. |success| should be true if the | 68 // called exactly once after |OnUploadStart|. |success| should be true if the |
71 // upload was successful, and false otherwise. | 69 // upload was successful, and false otherwise. |
72 void OnUploadComplete(bool success); | 70 void OnUploadComplete(bool success); |
73 | 71 |
74 base::Value* GetWebUIData() const; | 72 base::Value* GetWebUIData() const; |
75 | 73 |
76 // Disables jitter in BackoffEntries to make scheduling deterministic for | 74 private: |
77 // unit tests. | 75 struct CollectorState { |
78 void MakeDeterministicForTesting(); | 76 CollectorState(); |
79 | 77 |
80 private: | 78 // The number of consecutive failures to upload to this collector, or 0 if |
| 79 // the most recent upload succeeded. |
| 80 unsigned failures; |
| 81 base::TimeTicks next_upload; |
| 82 }; |
| 83 |
81 void MaybeScheduleUpload(); | 84 void MaybeScheduleUpload(); |
82 | 85 |
83 void GetNextUploadTimeAndCollector(base::TimeTicks now, | 86 void GetNextUploadTimeAndCollector(base::TimeTicks now, |
84 base::TimeTicks* upload_time_out, | 87 base::TimeTicks* upload_time_out, |
85 size_t* collector_index_out); | 88 size_t* collector_index_out); |
86 | 89 |
| 90 base::TimeDelta GetUploadRetryInterval(unsigned failures); |
| 91 |
87 MockableTime* time_; | 92 MockableTime* time_; |
| 93 std::vector<CollectorState> collectors_; |
88 Params params_; | 94 Params params_; |
89 ScheduleUploadCallback callback_; | 95 ScheduleUploadCallback callback_; |
90 net::BackoffEntry::Policy backoff_policy_; | |
91 ScopedVector<net::BackoffEntry> collectors_; | |
92 | 96 |
93 // Whether there are beacons that have not yet been uploaded. Set when a | 97 // Whether there are beacons that have not yet been uploaded. Set when a |
94 // beacon arrives or an upload fails, and cleared when an upload starts. | 98 // beacon arrives or an upload fails, and cleared when an upload starts. |
95 bool upload_pending_; | 99 bool upload_pending_; |
96 | 100 |
97 // Whether the scheduler has called the ScheduleUploadCallback to schedule | 101 // Whether the scheduler has called the ScheduleUploadCallback to schedule |
98 // the next upload. Set when an upload is scheduled and cleared when the | 102 // the next upload. Set when an upload is scheduled and cleared when the |
99 // upload starts. | 103 // upload starts. |
100 bool upload_scheduled_; | 104 bool upload_scheduled_; |
101 | 105 |
(...skipping 19 matching lines...) Expand all Loading... |
121 bool last_upload_finished_; | 125 bool last_upload_finished_; |
122 base::TimeTicks last_upload_start_time_; | 126 base::TimeTicks last_upload_start_time_; |
123 base::TimeTicks last_upload_end_time_; | 127 base::TimeTicks last_upload_end_time_; |
124 size_t last_upload_collector_index_; | 128 size_t last_upload_collector_index_; |
125 bool last_upload_success_; | 129 bool last_upload_success_; |
126 }; | 130 }; |
127 | 131 |
128 } // namespace domain_reliability | 132 } // namespace domain_reliability |
129 | 133 |
130 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ | 134 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ |
OLD | NEW |