OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A class to track the outstanding work required to bring the client back into | 5 // A class to track the outstanding work required to bring the client back into |
6 // sync with the server. | 6 // sync with the server. |
7 #ifndef SYNC_SESSIONS_NUDGE_TRACKER_H_ | 7 #ifndef SYNC_SESSIONS_NUDGE_TRACKER_H_ |
8 #define SYNC_SESSIONS_NUDGE_TRACKER_H_ | 8 #define SYNC_SESSIONS_NUDGE_TRACKER_H_ |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/time/clock.h" |
14 #include "sync/base/sync_export.h" | 15 #include "sync/base/sync_export.h" |
15 #include "sync/internal_api/public/base/model_type.h" | 16 #include "sync/internal_api/public/base/model_type.h" |
16 #include "sync/protocol/sync.pb.h" | 17 #include "sync/protocol/sync.pb.h" |
17 #include "sync/sessions/data_type_tracker.h" | 18 #include "sync/sessions/data_type_tracker.h" |
18 | 19 |
19 namespace syncer { | 20 namespace syncer { |
20 | 21 |
21 class ObjectIdInvalidationMap; | 22 class ObjectIdInvalidationMap; |
22 | 23 |
23 namespace sessions { | 24 namespace sessions { |
24 | 25 |
25 class SYNC_EXPORT_PRIVATE NudgeTracker { | 26 class SYNC_EXPORT_PRIVATE NudgeTracker { |
26 public: | 27 public: |
27 static size_t kDefaultMaxPayloadsPerType; | 28 static size_t kDefaultMaxPayloadsPerType; |
28 | 29 |
29 NudgeTracker(); | 30 // Takes the ownership of |clock|. |
| 31 explicit NudgeTracker(base::Clock* clock); |
30 ~NudgeTracker(); | 32 ~NudgeTracker(); |
31 | 33 |
32 // Returns true if there is a good reason for performing a sync cycle. | 34 // Returns true if there is a good reason for performing a sync cycle. |
33 // This does not take into account whether or not this is a good *time* to | 35 // This does not take into account whether or not this is a good *time* to |
34 // perform a sync cycle; that's the scheduler's job. | 36 // perform a sync cycle; that's the scheduler's job. |
35 bool IsSyncRequired() const; | 37 bool IsSyncRequired() const; |
36 | 38 |
37 // Returns true if there is a good reason for performing a get updates | 39 // Returns true if there is a good reason for performing a get updates |
38 // request as part of the next sync cycle. | 40 // request as part of the next sync cycle. |
39 bool IsGetUpdatesRequired() const; | 41 bool IsGetUpdatesRequired() const; |
40 | 42 |
| 43 // Return true if should perform a sync cycle for GU retry. |
| 44 bool IsRetryRequired() const; |
| 45 |
41 // Tells this class that all required update fetching and committing has | 46 // Tells this class that all required update fetching and committing has |
42 // completed successfully. | 47 // completed successfully. |
43 void RecordSuccessfulSyncCycle(); | 48 void RecordSuccessfulSyncCycle(); |
44 | 49 |
45 // Takes note of a local change. | 50 // Takes note of a local change. |
46 void RecordLocalChange(ModelTypeSet types); | 51 void RecordLocalChange(ModelTypeSet types); |
47 | 52 |
48 // Takes note of a locally issued request to refresh a data type. | 53 // Takes note of a locally issued request to refresh a data type. |
49 void RecordLocalRefreshRequest(ModelTypeSet types); | 54 void RecordLocalRefreshRequest(ModelTypeSet types); |
50 | 55 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // Fills a ProgressMarker with single legacy notification hint expected by the | 103 // Fills a ProgressMarker with single legacy notification hint expected by the |
99 // sync server. Newer servers will rely on the data set by FillProtoMessage() | 104 // sync server. Newer servers will rely on the data set by FillProtoMessage() |
100 // instead of this. | 105 // instead of this. |
101 void SetLegacyNotificationHint( | 106 void SetLegacyNotificationHint( |
102 ModelType type, | 107 ModelType type, |
103 sync_pb::DataTypeProgressMarker* progress) const; | 108 sync_pb::DataTypeProgressMarker* progress) const; |
104 | 109 |
105 // Adjusts the number of hints that can be stored locally. | 110 // Adjusts the number of hints that can be stored locally. |
106 void SetHintBufferSize(size_t size); | 111 void SetHintBufferSize(size_t size); |
107 | 112 |
| 113 void set_next_retry_time(base::Time next_retry_time) { |
| 114 next_retry_time_ = next_retry_time; |
| 115 } |
| 116 |
108 private: | 117 private: |
109 typedef std::map<ModelType, DataTypeTracker> TypeTrackerMap; | 118 typedef std::map<ModelType, DataTypeTracker> TypeTrackerMap; |
110 | 119 |
| 120 scoped_ptr<base::Clock> clock_; |
| 121 |
111 TypeTrackerMap type_trackers_; | 122 TypeTrackerMap type_trackers_; |
112 | 123 |
113 // Merged updates source. This should be obsolete, but the server still | 124 // Merged updates source. This should be obsolete, but the server still |
114 // relies on it for some heuristics. | 125 // relies on it for some heuristics. |
115 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_; | 126 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_; |
116 | 127 |
117 // Tracks whether or not invalidations are currently enabled. | 128 // Tracks whether or not invalidations are currently enabled. |
118 bool invalidations_enabled_; | 129 bool invalidations_enabled_; |
119 | 130 |
120 // This flag is set if suspect that some technical malfunction or known bug | 131 // This flag is set if suspect that some technical malfunction or known bug |
121 // may have left us with some unserviced invalidations. | 132 // may have left us with some unserviced invalidations. |
122 // | 133 // |
123 // Keeps track of whether or not we're fully in sync with the invalidation | 134 // Keeps track of whether or not we're fully in sync with the invalidation |
124 // server. This can be false even if invalidations are enabled and working | 135 // server. This can be false even if invalidations are enabled and working |
125 // correctly. For example, until we get ack-tracking working properly, we | 136 // correctly. For example, until we get ack-tracking working properly, we |
126 // won't persist invalidations between restarts, so we may be out of sync when | 137 // won't persist invalidations between restarts, so we may be out of sync when |
127 // we restart. The only way to get back into sync is to have invalidations | 138 // we restart. The only way to get back into sync is to have invalidations |
128 // enabled, then complete a sync cycle to make sure we're fully up to date. | 139 // enabled, then complete a sync cycle to make sure we're fully up to date. |
129 bool invalidations_out_of_sync_; | 140 bool invalidations_out_of_sync_; |
130 | 141 |
131 size_t num_payloads_per_type_; | 142 size_t num_payloads_per_type_; |
132 | 143 |
| 144 base::Time last_successful_sync_time_; |
| 145 |
| 146 // A retry GU should be issued after this time. |
| 147 base::Time next_retry_time_; |
| 148 |
133 DISALLOW_COPY_AND_ASSIGN(NudgeTracker); | 149 DISALLOW_COPY_AND_ASSIGN(NudgeTracker); |
134 }; | 150 }; |
135 | 151 |
136 } // namespace sessions | 152 } // namespace sessions |
137 } // namespace syncer | 153 } // namespace syncer |
138 | 154 |
139 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_ | 155 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_ |
OLD | NEW |