[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / sync / sessions / data_type_tracker.h
blob8d78cde2bd020877e5b3f25693a9b26262f4546d
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 void RecordLocalChange();
36 // Tracks that a local refresh request has been made for this type.
37 void RecordLocalRefreshRequest();
39 // Tracks that we received invalidation notifications for this type.
40 void RecordRemoteInvalidation(scoped_ptr<InvalidationInterface> incoming);
42 // Records that a sync cycle has been performed successfully.
43 // Generally, this means that all local changes have been committed and all
44 // remote changes have been downloaded, so we can clear any flags related to
45 // pending work.
46 void RecordSuccessfulSyncCycle();
48 // Updates the size of the invalidations payload buffer.
49 void UpdatePayloadBufferSize(size_t new_size);
51 // Returns true if there is a good reason to perform a sync cycle. This does
52 // not take into account whether or not now is a good time to perform a sync
53 // cycle. That's for the scheduler to decide.
54 bool IsSyncRequired() const;
56 // Returns true if there is a good reason to fetch updates for this type as
57 // part of the next sync cycle.
58 bool IsGetUpdatesRequired() const;
60 // Returns true if there is an uncommitted local change.
61 bool HasLocalChangePending() const;
63 // Returns true if we've received an invalidation since we last fetched
64 // updates.
65 bool HasPendingInvalidation() const;
67 // Returns true if an explicit refresh request is still outstanding.
68 bool HasRefreshRequestPending() 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
76 // handle a request.
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);
93 private:
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_.
106 // This list takes ownership of its contents.
107 ScopedVector<InvalidationInterface> pending_invalidations_;
109 size_t payload_buffer_size_;
111 // If !unthrottle_time_.is_null(), this type is throttled and may not download
112 // or commit data until the specified time.
113 base::TimeTicks unthrottle_time_;
115 // A helper to keep track invalidations we dropped due to overflow.
116 scoped_ptr<InvalidationInterface> last_dropped_invalidation_;
118 DISALLOW_COPY_AND_ASSIGN(DataTypeTracker);
121 } // namespace sessions
122 } // namespace syncer
124 #endif // SYNC_SESSIONS_DATA_TYPE_TRACKER_H_