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