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

Side by Side Diff: components/sync/sessions_impl/nudge_tracker.h

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A class to track the outstanding work required to bring the client back into
6 // sync with the server.
7 #ifndef COMPONENTS_SYNC_SESSIONS_IMPL_NUDGE_TRACKER_H_
8 #define COMPONENTS_SYNC_SESSIONS_IMPL_NUDGE_TRACKER_H_
9
10 #include <stddef.h>
11
12 #include <list>
13 #include <map>
14 #include <memory>
15
16 #include "base/compiler_specific.h"
17 #include "base/macros.h"
18 #include "base/time/time.h"
19 #include "components/sync/base/invalidation_interface.h"
20 #include "components/sync/base/model_type.h"
21 #include "components/sync/protocol/sync.pb.h"
22 #include "components/sync/sessions_impl/data_type_tracker.h"
23
24 namespace syncer {
25
26 class ObjectIdInvalidationMap;
27
28 namespace sessions {
29
30 class NudgeTracker {
31 public:
32 static size_t kDefaultMaxPayloadsPerType;
33
34 NudgeTracker();
35 ~NudgeTracker();
36
37 // Returns true if there is a good reason for performing a sync cycle.
38 // This does not take into account whether or not this is a good *time* to
39 // perform a sync cycle; that's the scheduler's job.
40 bool IsSyncRequired() const;
41
42 // Returns true if there is a good reason for performing a get updates
43 // request as part of the next sync cycle.
44 bool IsGetUpdatesRequired() const;
45
46 // Return true if should perform a sync cycle for GU retry.
47 //
48 // This is sensitive to changes in 'current time'. Its value can be affected
49 // by SetSyncCycleStartTime(), SetNextRetryTime(), and
50 // RecordSuccessfulSyncCycle(). Please refer to those functions for more
51 // information on how this flag is maintained.
52 bool IsRetryRequired() const;
53
54 // Tells this class that all required update fetching or committing has
55 // completed successfully.
56 void RecordSuccessfulSyncCycle();
57
58 // Takes note of a local change.
59 // Returns the shortest nudge delay from the tracker of each type in |types|.
60 base::TimeDelta RecordLocalChange(ModelTypeSet types);
61
62 // Takes note of a locally issued request to refresh a data type.
63 // Returns the current nudge delay for a local refresh.
64 base::TimeDelta RecordLocalRefreshRequest(ModelTypeSet types);
65
66 // Takes note of the receipt of an invalidation notice from the server.
67 // Returns the current nudge delay for a remote invalidation.
68 base::TimeDelta RecordRemoteInvalidation(
69 syncer::ModelType type,
70 std::unique_ptr<InvalidationInterface> invalidation);
71
72 // Take note that an initial sync is pending for this type.
73 void RecordInitialSyncRequired(syncer::ModelType type);
74
75 // Takes note that the conflict happended for this type, need to sync to
76 // resolve conflict locally.
77 void RecordCommitConflict(syncer::ModelType type);
78
79 // These functions should be called to keep this class informed of the status
80 // of the connection to the invalidations server.
81 void OnInvalidationsEnabled();
82 void OnInvalidationsDisabled();
83
84 // Marks |types| as being throttled from |now| until |now| + |length|.
85 void SetTypesThrottledUntil(ModelTypeSet types,
86 base::TimeDelta length,
87 base::TimeTicks now);
88
89 // Removes any throttling that have expired by time |now|.
90 void UpdateTypeThrottlingState(base::TimeTicks now);
91
92 // Returns the time of the next type unthrottling, relative to
93 // the input |now| value.
94 base::TimeDelta GetTimeUntilNextUnthrottle(base::TimeTicks now) const;
95
96 // Returns true if any type is currenlty throttled.
97 bool IsAnyTypeThrottled() const;
98
99 // Returns true if |type| is currently throttled.
100 bool IsTypeThrottled(ModelType type) const;
101
102 // Returns the set of currently throttled types.
103 ModelTypeSet GetThrottledTypes() const;
104
105 // Returns the set of types with local changes pending.
106 ModelTypeSet GetNudgedTypes() const;
107
108 // Returns the set of types that have pending invalidations.
109 ModelTypeSet GetNotifiedTypes() const;
110
111 // Returns the set of types that have pending refresh requests.
112 ModelTypeSet GetRefreshRequestedTypes() const;
113
114 // Returns the 'source' of the GetUpdate request.
115 //
116 // This flag is deprecated, but still used by the server. There can be more
117 // than one reason to perform a particular sync cycle. The GetUpdatesTrigger
118 // message will contain more reliable information about the reasons for
119 // performing a sync.
120 //
121 // See the implementation for important information about the coalesce logic.
122 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource GetLegacySource() const;
123
124 // Fills a GetUpdatesTrigger message for the next GetUpdates request. This is
125 // used by the DownloadUpdatesCommand to dump lots of useful per-type state
126 // information into the GetUpdate request before sending it off to the server.
127 void FillProtoMessage(ModelType type, sync_pb::GetUpdateTriggers* msg) const;
128
129 // Fills a ProgressMarker with single legacy notification hint expected by the
130 // sync server. Newer servers will rely on the data set by FillProtoMessage()
131 // instead of this.
132 void SetLegacyNotificationHint(
133 ModelType type,
134 sync_pb::DataTypeProgressMarker* progress) const;
135
136 // Flips the flag if we're due for a retry.
137 void SetSyncCycleStartTime(base::TimeTicks now);
138
139 // Adjusts the number of hints that can be stored locally.
140 void SetHintBufferSize(size_t size);
141
142 // Schedules a retry GetUpdate request for some time in the future.
143 //
144 // This is a request sent to us as part of a server response requesting
145 // that the client perform a GetUpdate request at |next_retry_time| to
146 // fetch any updates it may have missed in the first attempt.
147 //
148 // To avoid strange results from IsRetryRequired() during a sync cycle, the
149 // effects of this change are not guaranteed to take effect until
150 // SetSyncCycleStartTime() is called at the start of the *next* sync cycle.
151 void SetNextRetryTime(base::TimeTicks next_retry_time);
152
153 // Update the per-datatype local change nudge delays.
154 void OnReceivedCustomNudgeDelays(
155 const std::map<ModelType, base::TimeDelta>& delay_map);
156
157 // Update the default nudge delay.
158 void SetDefaultNudgeDelay(base::TimeDelta nudge_delay);
159
160 private:
161 using TypeTrackerMap = std::map<ModelType, std::unique_ptr<DataTypeTracker>>;
162
163 TypeTrackerMap type_trackers_;
164
165 // Tracks whether or not invalidations are currently enabled.
166 bool invalidations_enabled_;
167
168 // This flag is set if suspect that some technical malfunction or known bug
169 // may have left us with some unserviced invalidations.
170 //
171 // Keeps track of whether or not we're fully in sync with the invalidation
172 // server. This can be false even if invalidations are enabled and working
173 // correctly. For example, until we get ack-tracking working properly, we
174 // won't persist invalidations between restarts, so we may be out of sync when
175 // we restart. The only way to get back into sync is to have invalidations
176 // enabled, then complete a sync cycle to make sure we're fully up to date.
177 bool invalidations_out_of_sync_;
178
179 base::TimeTicks last_successful_sync_time_;
180
181 // A pending update to the current_retry_time_.
182 //
183 // The GU retry time is specified by a call to SetNextRetryTime, but we don't
184 // want that change to take effect right away, since it could happen in the
185 // middle of a sync cycle. We delay the update until the start of the next
186 // sync cycle, which is indicated by a call to SetSyncCycleStartTime().
187 base::TimeTicks next_retry_time_;
188
189 // The currently active retry GU time. Will be null if there is no retry GU
190 // pending at this time.
191 base::TimeTicks current_retry_time_;
192
193 // The time when the sync cycle started. This value is maintained by
194 // SetSyncCycleStartTime(). This may contain a stale value if we're not
195 // currently in a sync cycle.
196 base::TimeTicks sync_cycle_start_time_;
197
198 // Nudge delays for various events.
199 base::TimeDelta minimum_local_nudge_delay_;
200 base::TimeDelta local_refresh_nudge_delay_;
201 base::TimeDelta remote_invalidation_nudge_delay_;
202
203 DISALLOW_COPY_AND_ASSIGN(NudgeTracker);
204 };
205
206 } // namespace sessions
207 } // namespace syncer
208
209 #endif // COMPONENTS_SYNC_SESSIONS_IMPL_NUDGE_TRACKER_H_
OLDNEW
« no previous file with comments | « components/sync/sessions_impl/directory_type_debug_info_emitter.cc ('k') | components/sync/sessions_impl/nudge_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698