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/time/time.h" | 11 #include "base/time/time.h" |
12 #include "components/domain_reliability/domain_reliability_export.h" | 12 #include "components/domain_reliability/domain_reliability_export.h" |
13 | 13 |
| 14 namespace base { |
| 15 class Value; |
| 16 } // namespace base |
| 17 |
14 namespace domain_reliability { | 18 namespace domain_reliability { |
15 | 19 |
16 class DomainReliabilityConfig; | 20 class DomainReliabilityConfig; |
17 class MockableTime; | 21 class MockableTime; |
18 | 22 |
19 // Determines when an upload should be scheduled. A domain's config will | 23 // Determines when an upload should be scheduled. A domain's config will |
20 // specify minimum and maximum upload delays; the minimum upload delay ensures | 24 // specify minimum and maximum upload delays; the minimum upload delay ensures |
21 // that Chrome will not send too many upload requests to a site by waiting at | 25 // that Chrome will not send too many upload requests to a site by waiting at |
22 // least that long after the first beacon, while the maximum upload delay makes | 26 // least that long after the first beacon, while the maximum upload delay makes |
23 // sure the server receives the reports while they are still fresh. | 27 // sure the server receives the reports while they are still fresh. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // be called exactly once during or after the ScheduleUploadCallback but | 62 // be called exactly once during or after the ScheduleUploadCallback but |
59 // before OnUploadComplete is called. (Also records the upload start time for | 63 // before OnUploadComplete is called. (Also records the upload start time for |
60 // future retries, if the upload ends up failing.) | 64 // future retries, if the upload ends up failing.) |
61 size_t OnUploadStart(); | 65 size_t OnUploadStart(); |
62 | 66 |
63 // 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 |
64 // called exactly once after |OnUploadStart|. |success| should be true if the | 68 // called exactly once after |OnUploadStart|. |success| should be true if the |
65 // upload was successful, and false otherwise. | 69 // upload was successful, and false otherwise. |
66 void OnUploadComplete(bool success); | 70 void OnUploadComplete(bool success); |
67 | 71 |
| 72 base::Value* GetWebUIData() const; |
| 73 |
68 private: | 74 private: |
69 struct CollectorState { | 75 struct CollectorState { |
70 CollectorState(); | 76 CollectorState(); |
71 | 77 |
72 // The number of consecutive failures to upload to this collector, or 0 if | 78 // The number of consecutive failures to upload to this collector, or 0 if |
73 // the most recent upload succeeded. | 79 // the most recent upload succeeded. |
74 unsigned failures; | 80 unsigned failures; |
75 base::TimeTicks next_upload; | 81 base::TimeTicks next_upload; |
76 }; | 82 }; |
77 | 83 |
(...skipping 26 matching lines...) Expand all Loading... |
104 // Index of the collector selected for the next upload. (Set in | 110 // Index of the collector selected for the next upload. (Set in |
105 // |OnUploadStart| and cleared in |OnUploadComplete|.) | 111 // |OnUploadStart| and cleared in |OnUploadComplete|.) |
106 size_t collector_index_; | 112 size_t collector_index_; |
107 | 113 |
108 // Time of the first beacon that was not included in the last successful | 114 // Time of the first beacon that was not included in the last successful |
109 // upload. | 115 // upload. |
110 base::TimeTicks first_beacon_time_; | 116 base::TimeTicks first_beacon_time_; |
111 | 117 |
112 // first_beacon_time_ saved during uploads. Restored if upload fails. | 118 // first_beacon_time_ saved during uploads. Restored if upload fails. |
113 base::TimeTicks old_first_beacon_time_; | 119 base::TimeTicks old_first_beacon_time_; |
| 120 |
| 121 // Extra bits to return in GetWebUIData. |
| 122 base::TimeTicks scheduled_min_time_; |
| 123 base::TimeTicks scheduled_max_time_; |
| 124 // Whether the other last_upload_* fields are populated. |
| 125 bool last_upload_finished_; |
| 126 base::TimeTicks last_upload_start_time_; |
| 127 base::TimeTicks last_upload_end_time_; |
| 128 size_t last_upload_collector_index_; |
| 129 bool last_upload_success_; |
114 }; | 130 }; |
115 | 131 |
116 } // namespace domain_reliability | 132 } // namespace domain_reliability |
117 | 133 |
118 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ | 134 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ |
OLD | NEW |