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

Side by Side Diff: components/domain_reliability/scheduler.h

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/&*config/config.get()/g Created 6 years, 7 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 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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 static Params GetFromFieldTrialsOrDefaults(); 43 static Params GetFromFieldTrialsOrDefaults();
44 }; 44 };
45 45
46 DomainReliabilityScheduler(MockableTime* time, 46 DomainReliabilityScheduler(MockableTime* time,
47 size_t num_collectors, 47 size_t num_collectors,
48 const Params& params, 48 const Params& params,
49 const ScheduleUploadCallback& callback); 49 const ScheduleUploadCallback& callback);
50 ~DomainReliabilityScheduler(); 50 ~DomainReliabilityScheduler();
51 51
52 // Called when a beacon is added to the context. May call the provided 52 // If there is no upload pending, schedules an upload based on the provided
53 // ScheduleUploadCallback (if all previous beacons have been uploaded). 53 // parameters (some time between the minimum and maximum delay from now).
54 // May call the ScheduleUploadCallback.
54 void OnBeaconAdded(); 55 void OnBeaconAdded();
55 56
56 // Called when an upload is about to start. 57 // Returns which collector to use for an upload that is about to start. Must
57 void OnUploadStart(int* collector_index_out); 58 // be called exactly once during or after the ScheduleUploadCallback but
59 // before OnUploadComplete is called. (Also records the upload start time for
60 // future retries, if the upload ends up failing.)
61 size_t OnUploadStart();
58 62
59 // Called when an upload has finished. May call the provided 63 // Updates the scheduler state based on the result of an upload. Must be
60 // ScheduleUploadCallback (if the upload failed, or if beacons arrived 64 // called exactly once after |OnUploadStart|. |success| should be true if the
61 // during the upload). 65 // upload was successful, and false otherwise.
62 void OnUploadComplete(bool success); 66 void OnUploadComplete(bool success);
63 67
64 private: 68 private:
65 struct CollectorState { 69 struct CollectorState {
66 CollectorState(); 70 CollectorState();
67 71
68 // The number of consecutive failures to upload to this collector, or 0 if 72 // The number of consecutive failures to upload to this collector, or 0 if
69 // the most recent upload succeeded. 73 // the most recent upload succeeded.
70 int failures; 74 unsigned failures;
71 base::TimeTicks next_upload; 75 base::TimeTicks next_upload;
72 }; 76 };
73 77
74 void MaybeScheduleUpload(); 78 void MaybeScheduleUpload();
75 79
76 void GetNextUploadTimeAndCollector(base::TimeTicks now, 80 void GetNextUploadTimeAndCollector(base::TimeTicks now,
77 base::TimeTicks* upload_time_out, 81 base::TimeTicks* upload_time_out,
78 int* collector_index_out); 82 size_t* collector_index_out);
79 base::TimeDelta GetUploadRetryInterval(int failures); 83
84 base::TimeDelta GetUploadRetryInterval(unsigned failures);
80 85
81 MockableTime* time_; 86 MockableTime* time_;
82 std::vector<CollectorState> collectors_; 87 std::vector<CollectorState> collectors_;
83 Params params_; 88 Params params_;
84 ScheduleUploadCallback callback_; 89 ScheduleUploadCallback callback_;
85 90
86 // Whether there are beacons that have not yet been uploaded. Set when a 91 // Whether there are beacons that have not yet been uploaded. Set when a
87 // beacon arrives or an upload fails, and cleared when an upload starts. 92 // beacon arrives or an upload fails, and cleared when an upload starts.
88 bool upload_pending_; 93 bool upload_pending_;
89 94
90 // Whether the scheduler has called the ScheduleUploadCallback to schedule 95 // Whether the scheduler has called the ScheduleUploadCallback to schedule
91 // the next upload. Set when an upload is scheduled and cleared when the 96 // the next upload. Set when an upload is scheduled and cleared when the
92 // upload starts. 97 // upload starts.
93 bool upload_scheduled_; 98 bool upload_scheduled_;
94 99
95 // Whether the last scheduled upload is in progress. Set when the upload 100 // Whether the last scheduled upload is in progress. Set when the upload
96 // starts and cleared when the upload completes (successfully or not). 101 // starts and cleared when the upload completes (successfully or not).
97 bool upload_running_; 102 bool upload_running_;
98 103
99 // Index of the collector selected for the next upload. (Set in 104 // Index of the collector selected for the next upload. (Set in
100 // |OnUploadStart| and cleared in |OnUploadComplete|.) 105 // |OnUploadStart| and cleared in |OnUploadComplete|.)
101 int collector_index_; 106 size_t collector_index_;
102 107
103 // Time of the first beacon that was not included in the last successful 108 // Time of the first beacon that was not included in the last successful
104 // upload. 109 // upload.
105 base::TimeTicks first_beacon_time_; 110 base::TimeTicks first_beacon_time_;
106 111
107 // first_beacon_time_ saved during uploads. Restored if upload fails. 112 // first_beacon_time_ saved during uploads. Restored if upload fails.
108 base::TimeTicks old_first_beacon_time_; 113 base::TimeTicks old_first_beacon_time_;
109 }; 114 };
110 115
111 } // namespace domain_reliability 116 } // namespace domain_reliability
112 117
113 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_ 118 #endif // COMPONENTS_DOMAIN_RELIABILITY_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698