| 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 <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 kDefaultMaxPayloadsPerType; | 
|  | 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 IsSyncRequired(); | 
| 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 OnInvalidationsEnabled(); | 
|  | 53   void OnInvalidationsDisabled(); | 
|  | 54 | 
|  | 55   // A helper to return an old-style source info.  Used only to maintain | 
|  | 56   // compatibility with some old code. | 
|  | 57   SyncSourceInfo GetSourceInfo() 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 | 
|  | 80   // Adjusts the number of hints that can be stored locally. | 
|  | 81   void SetHintBufferSize(size_t size); | 
|  | 82 | 
| 44  private: | 83  private: | 
| 45   // Merged source info for the nudge(s). | 84   typedef std::list<std::string> PayloadList; | 
| 46   SyncSourceInfo source_info_; | 85   typedef std::map<ModelType, PayloadList> PayloadListMap; | 
|  | 86   typedef std::map<ModelType, int> NudgeMap; | 
|  | 87 | 
|  | 88   // Merged updates source.  This should be obsolete, but the server still | 
|  | 89   // relies on it for some heuristics. | 
|  | 90   sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_; | 
|  | 91 | 
|  | 92   // The number of times each type has been locally nudged since the last | 
|  | 93   // successful sync cycle.  If a type is not in the map, the count is zero. | 
|  | 94   NudgeMap local_nudge_counts_; | 
|  | 95 | 
|  | 96   // The number of times a refresh was requested each type, since the last | 
|  | 97   // successful sync cycle.  If a type is not in the map, the count is zero. | 
|  | 98   NudgeMap refresh_requested_counts_; | 
|  | 99 | 
|  | 100   // A map of datatypes to lists of hints.  The hints are ordered from least | 
|  | 101   // recent to most recent. | 
|  | 102   PayloadListMap payload_list_map_; | 
|  | 103 | 
|  | 104   // Tracks the types for which the list of pending hints has overflowed, | 
|  | 105   // causing us to drop the oldest hints. | 
|  | 106   ModelTypeSet locally_dropped_payload_types_; | 
|  | 107 | 
|  | 108   // Tracks the types for which the invalidation server has notified us that it | 
|  | 109   // dropped some of its payloads. | 
|  | 110   ModelTypeSet server_dropped_payload_types_; | 
|  | 111 | 
|  | 112   // Tracks whether or not invalidations are currently enabled. | 
|  | 113   bool invalidations_enabled_; | 
|  | 114 | 
|  | 115   // This flag is set if suspect that some technical malfunction or known bug | 
|  | 116   // may have left us with some unserviced invalidations. | 
|  | 117   // | 
|  | 118   // Keeps track of whether or not we're fully in sync with the invalidation | 
|  | 119   // server.  This can be false even if invalidations are enabled and working | 
|  | 120   // correctly.  For example, until we get ack-tracking working properly, we | 
|  | 121   // won't persist invalidations between restarts, so we may be out of sync when | 
|  | 122   // we restart.  The only way to get back into sync is to have invalidations | 
|  | 123   // enabled, then complete a sync cycle to make sure we're fully up to date. | 
|  | 124   bool invalidations_out_of_sync_; | 
|  | 125 | 
|  | 126   size_t num_payloads_per_type_; | 
| 47 | 127 | 
| 48   DISALLOW_COPY_AND_ASSIGN(NudgeTracker); | 128   DISALLOW_COPY_AND_ASSIGN(NudgeTracker); | 
| 49 }; | 129 }; | 
| 50 | 130 | 
| 51 }  // namespace sessions | 131 }  // namespace sessions | 
| 52 }  // namespace syncer | 132 }  // namespace syncer | 
| 53 | 133 | 
| 54 #endif  // SYNC_SESSIONS_NUDGE_TRACKER_H_ | 134 #endif  // SYNC_SESSIONS_NUDGE_TRACKER_H_ | 
| OLD | NEW | 
|---|