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.
5 // A class to track the per-type scheduling data.
6 #ifndef SYNC_SESSIONS_DATA_TYPE_TRACKER_H_
7 #define SYNC_SESSIONS_DATA_TYPE_TRACKER_H_
12 #include "base/basictypes.h"
13 #include "base/time/time.h"
14 #include "sync/notifier/dropped_invalidation_tracker.h"
15 #include "sync/notifier/single_object_invalidation_set.h"
16 #include "sync/protocol/sync.pb.h"
21 class SingleObjectInvalidationSet
;
25 typedef std::deque
<std::string
> PayloadList
;
27 class DataTypeTracker
{
29 explicit DataTypeTracker(const invalidation::ObjectId
& object_id
);
32 // For STL compatibility, we do not forbid the creation of a default copy
33 // constructor and assignment operator.
35 // Tracks that a local change has been made to this type.
36 void RecordLocalChange();
38 // Tracks that a local refresh request has been made for this type.
39 void RecordLocalRefreshRequest();
41 // Tracks that we received invalidation notifications for this type.
42 void RecordRemoteInvalidations(
43 const SingleObjectInvalidationSet
& invalidations
);
45 // Records that a sync cycle has been performed successfully.
46 // Generally, this means that all local changes have been committed and all
47 // remote changes have been downloaded, so we can clear any flags related to
49 void RecordSuccessfulSyncCycle();
51 // Updates the size of the invalidations payload buffer.
52 void UpdatePayloadBufferSize(size_t new_size
);
54 // Returns true if there is a good reason to perform a sync cycle. This does
55 // not take into account whether or not now is a good time to perform a sync
56 // cycle. That's for the scheduler to decide.
57 bool IsSyncRequired() const;
59 // Returns true if there is a good reason to fetch updates for this type as
60 // part of the next sync cycle.
61 bool IsGetUpdatesRequired() const;
63 // Returns true if there is an uncommitted local change.
64 bool HasLocalChangePending() const;
66 // Returns true if we've received an invalidation since we last fetched
68 bool HasPendingInvalidation() const;
70 // Fills in the legacy invalidaiton payload information fields.
71 void SetLegacyNotificationHint(
72 sync_pb::DataTypeProgressMarker
* progress
) const;
74 // Fills some type-specific contents of a GetUpdates request protobuf. These
75 // messages provide the server with the information it needs to decide how to
77 void FillGetUpdatesTriggersMessage(sync_pb::GetUpdateTriggers
* msg
) const;
79 // Returns true if the type is currently throttled.
80 bool IsThrottled() const;
82 // Returns the time until this type's throttling interval expires. Should not
83 // be called unless IsThrottled() returns true. The returned value will be
84 // increased to zero if it would otherwise have been negative.
85 base::TimeDelta
GetTimeUntilUnthrottle(base::TimeTicks now
) const;
87 // Throttles the type from |now| until |now| + |duration|.
88 void ThrottleType(base::TimeDelta duration
, base::TimeTicks now
);
90 // Unthrottles the type if |now| >= the throttle expiry time.
91 void UpdateThrottleState(base::TimeTicks now
);
94 // Number of local change nudges received for this type since the last
95 // successful sync cycle.
96 int local_nudge_count_
;
98 // Number of local refresh requests received for this type since the last
99 // successful sync cycle.
100 int local_refresh_request_count_
;
102 // The list of invalidations received since the last successful sync cycle.
103 // This list may be incomplete. See also:
104 // drop_tracker_.IsRecoveringFromDropEvent() and server_payload_overflow_.
105 SingleObjectInvalidationSet pending_invalidations_
;
107 size_t payload_buffer_size_
;
109 // If !unthrottle_time_.is_null(), this type is throttled and may not download
110 // or commit data until the specified time.
111 base::TimeTicks unthrottle_time_
;
113 // A helper to keep track invalidations we dropped due to overflow.
114 DroppedInvalidationTracker drop_tracker_
;
117 } // namespace syncer
118 } // namespace sessions
120 #endif // SYNC_SESSIONS_DATA_TYPE_TRACKER_H_