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