Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / sync / sessions / data_type_tracker.h
blob0842197a72846792e81fe0e8940c1dad53ef41d7
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 #ifndef SYNC_SESSIONS_DATA_TYPE_TRACKER_H_
6 #define SYNC_SESSIONS_DATA_TYPE_TRACKER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/time/time.h"
14 #include "sync/internal_api/public/base/invalidation_interface.h"
15 #include "sync/internal_api/public/base/model_type.h"
16 #include "sync/protocol/sync.pb.h"
18 namespace syncer {
20 class InvalidationInterface;
22 namespace sessions {
24 // A class to track the per-type scheduling data.
25 class DataTypeTracker {
26 public:
27 explicit DataTypeTracker();
28 ~DataTypeTracker();
30 // For STL compatibility, we do not forbid the creation of a default copy
31 // constructor and assignment operator.
33 // Tracks that a local change has been made to this type.
34 // Returns the current local change nudge delay for this type.
35 base::TimeDelta RecordLocalChange();
37 // Tracks that a local refresh request has been made for this type.
38 void RecordLocalRefreshRequest();
40 // Tracks that we received invalidation notifications for this type.
41 void RecordRemoteInvalidation(scoped_ptr<InvalidationInterface> incoming);
43 // Takes note that initial sync is pending for this type.
44 void RecordInitialSyncRequired();
46 // Takes note that the conflict happended for this type, need to sync to
47 // resolve conflict locally.
48 void RecordCommitConflict();
50 // Records that a sync cycle has been performed successfully.
51 // Generally, this means that all local changes have been committed and all
52 // remote changes have been downloaded, so we can clear any flags related to
53 // pending work.
54 void RecordSuccessfulSyncCycle();
56 // Updates the size of the invalidations payload buffer.
57 void UpdatePayloadBufferSize(size_t new_size);
59 // Returns true if there is a good reason to perform a sync cycle. This does
60 // not take into account whether or not now is a good time to perform a sync
61 // cycle. That's for the scheduler to decide.
62 bool IsSyncRequired() const;
64 // Returns true if there is a good reason to fetch updates for this type as
65 // part of the next sync cycle.
66 bool IsGetUpdatesRequired() const;
68 // Returns true if there is an uncommitted local change.
69 bool HasLocalChangePending() const;
71 // Returns true if we've received an invalidation since we last fetched
72 // updates.
73 bool HasPendingInvalidation() const;
75 // Returns true if an explicit refresh request is still outstanding.
76 bool HasRefreshRequestPending() const;
78 // Returns true if this type is requesting an initial sync.
79 bool IsInitialSyncRequired() const;
81 // Returns true if this type is requesting a sync to resolve conflict issue.
82 bool IsSyncRequiredToResolveConflict() const;
84 // Fills in the legacy invalidaiton payload information fields.
85 void SetLegacyNotificationHint(
86 sync_pb::DataTypeProgressMarker* progress) const;
88 // Fills some type-specific contents of a GetUpdates request protobuf. These
89 // messages provide the server with the information it needs to decide how to
90 // handle a request.
91 void FillGetUpdatesTriggersMessage(sync_pb::GetUpdateTriggers* msg) const;
93 // Returns true if the type is currently throttled.
94 bool IsThrottled() const;
96 // Returns the time until this type's throttling interval expires. Should not
97 // be called unless IsThrottled() returns true. The returned value will be
98 // increased to zero if it would otherwise have been negative.
99 base::TimeDelta GetTimeUntilUnthrottle(base::TimeTicks now) const;
101 // Throttles the type from |now| until |now| + |duration|.
102 void ThrottleType(base::TimeDelta duration, base::TimeTicks now);
104 // Unthrottles the type if |now| >= the throttle expiry time.
105 void UpdateThrottleState(base::TimeTicks now);
107 // Update the local change nudge delay for this type.
108 void UpdateLocalNudgeDelay(base::TimeDelta delay);
110 private:
111 // Number of local change nudges received for this type since the last
112 // successful sync cycle.
113 int local_nudge_count_;
115 // Number of local refresh requests received for this type since the last
116 // successful sync cycle.
117 int local_refresh_request_count_;
119 // The list of invalidations received since the last successful sync cycle.
120 // This list may be incomplete. See also:
121 // drop_tracker_.IsRecoveringFromDropEvent() and server_payload_overflow_.
123 // This list takes ownership of its contents.
124 ScopedVector<InvalidationInterface> pending_invalidations_;
126 size_t payload_buffer_size_;
128 // Set to true if this type is ready for, but has not yet completed initial
129 // sync.
130 bool initial_sync_required_;
132 // Set to true if this type need to get update to resolve conflict issue.
133 bool sync_required_to_resolve_conflict_;
135 // If !unthrottle_time_.is_null(), this type is throttled and may not download
136 // or commit data until the specified time.
137 base::TimeTicks unthrottle_time_;
139 // A helper to keep track invalidations we dropped due to overflow.
140 scoped_ptr<InvalidationInterface> last_dropped_invalidation_;
142 // The amount of time to delay a sync cycle by when a local change for this
143 // type occurs.
144 base::TimeDelta nudge_delay_;
146 DISALLOW_COPY_AND_ASSIGN(DataTypeTracker);
149 } // namespace sessions
150 } // namespace syncer
152 #endif // SYNC_SESSIONS_DATA_TYPE_TRACKER_H_