Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: sync/sessions/nudge_tracker.h

Issue 14963002: sync: Report GetUpdate triggers to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 10 #include <list>
11 #include <map>
11 12
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "sync/base/sync_export.h" 14 #include "sync/base/sync_export.h"
14 #include "sync/internal_api/public/sessions/sync_source_info.h" 15 #include "sync/internal_api/public/base/model_type.h"
16 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
17 #include "sync/protocol/sync.pb.h"
15 18
16 namespace syncer { 19 namespace syncer {
17 namespace sessions { 20 namespace sessions {
18 21
19 struct SyncSourceInfo; 22 struct SyncSourceInfo;
20 23
21 class SYNC_EXPORT_PRIVATE NudgeTracker { 24 class SYNC_EXPORT_PRIVATE NudgeTracker {
22 public: 25 public:
26 static size_t kMaxPayloadsPerType;
27
23 NudgeTracker(); 28 NudgeTracker();
24 ~NudgeTracker(); 29 ~NudgeTracker();
25 30
26 // Merges in the information from another nudge. 31 // Returns true if there is a good reason for performing a sync cycle.
27 void CoalesceSources(const SyncSourceInfo& source); 32 // This does not take into account whether or not this is a good *time* to
33 // perform a sync cycle; that's the scheduler's job.
34 bool SyncRequired();
tim (not reviewing) 2013/05/06 21:29:04 nit - IsSyncRequired()
rlarocque 2013/05/07 18:45:39 Done.
28 35
29 // Returns true if there are no unserviced nudges. 36 // Tells this class that all required update fetching and committing has
30 bool IsEmpty(); 37 // completed successfully.
38 void RecordSuccessfulSyncCycle();
31 39
32 // Clear all unserviced nudges. 40 // Takes note of a local change.
33 void Reset(); 41 void RecordLocalChange(ModelTypeSet types);
34 42
35 // Returns the coalesced source info. 43 // Takes note of a locally issued request to refresh a data type.
36 const SyncSourceInfo& source_info() const { 44 void RecordLocalRefreshRequest(ModelTypeSet types);
37 return source_info_;
38 }
39 45
40 // Returns the set of locally modified types, according to our tracked source 46 // Takes note of the receipt of an invalidation notice from the server.
41 // infos. The result is often wrong; see implementation comment for details. 47 void RecordRemoteInvalidation(
48 const ModelTypeInvalidationMap& invalidation_map);
49
50 // These functions should be called to keep this class informed of the status
51 // of the connection to the invalidations server.
52 void InvalidationsEnabled();
tim (not reviewing) 2013/05/06 21:29:04 Convention in Chrome for something like this would
rlarocque 2013/05/07 18:45:39 Done.
53 void InvalidationsDisabled();
54
55 // A helper to return an old-style source info. Used only to maintain
56 // compatibility with some old code.
57 SyncSourceInfo source_info() const;
58
59 // Returns the set of locally modified types, according to the nudges received
60 // since the last successful sync cycle.
42 ModelTypeSet GetLocallyModifiedTypes() const; 61 ModelTypeSet GetLocallyModifiedTypes() const;
43 62
63 // Returns the 'source' of the GetUpdate request.
64 //
65 // This flag is deprecated, but still used by the server. There can be more
66 // than one reason to perform a particular sync cycle. The GetUpdatesTrigger
67 // message will contain more reliable information about the reasons for
68 // performing a sync.
69 //
70 // See the implementation for important information about the coalesce logic.
71 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source() const;
72
73 // Fills a ProgressMarker for the next GetUpdates request. This is used by
74 // the DownloadUpdatesCommand to dump lots of useful per-type state
75 // information into the GetUpdate request before sending it off to the server.
76 void FillProtoMessage(
77 ModelType type,
78 sync_pb::GetUpdateTriggers* msg) const;
79
44 private: 80 private:
45 // Merged source info for the nudge(s). 81 typedef std::list<std::string> PayloadList;
46 SyncSourceInfo source_info_; 82 typedef std::map<ModelType, PayloadList> PayloadListMap;
83 typedef std::map<ModelType, int> NudgeMap;
84
85 // Merged updates source. This should be obsolete, but the server still
86 // relies on it for some heuristics.
87 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_;
88
89 // The number of times each type has been locally nudged since the last
90 // successful sync cycle. If a type is not in the map, the count is zero.
91 NudgeMap local_nudge_counts_;
92
93 // The number of times a refresh was requested each type, since the last
94 // successful sync cycle. If a type is not in the map, the count is zero.
95 NudgeMap refresh_requested_counts_;
96
97 // A map of datatypes to lists of hints. The hints are ordered from least
98 // recent to most recent.
99 PayloadListMap payload_list_map_;
100
101 // Tracks the types for which the list of pending hints has overflowed,
102 // causing us to drop the oldest hints.
103 ModelTypeSet locally_dropped_payload_types_;
104
105 // Tracks the types for which the invalidation server has notified us that it
106 // dropped some of its payloads.
107 ModelTypeSet server_dropped_payload_types_;
108
109 // Tracks whether or not invalidations are currently enabled.
110 bool invalidations_enabled_;
111
112 // This flag is set if suspect that some technical malfunction or known bug
113 // may have left us with some unserviced invalidations.
114 //
115 // Keeps track of whether or not we're fully in sync with the invalidation
116 // server. This can be false even if invalidations are enabled and working
117 // correctly. For example, until we get ack-tracking working properly, we
118 // won't persist invalidations between restarts, so we may be out of sync when
119 // we restart. The only way to get back into sync is to have invalidations
120 // enabled, then complete a sync cycle to make sure we're fully up to date.
121 bool invalidations_out_of_sync_;
47 122
48 DISALLOW_COPY_AND_ASSIGN(NudgeTracker); 123 DISALLOW_COPY_AND_ASSIGN(NudgeTracker);
49 }; 124 };
50 125
51 } // namespace sessions 126 } // namespace sessions
52 } // namespace syncer 127 } // namespace syncer
53 128
54 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_ 129 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698