| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // An InvalidationVersionTracker is an interface that handles getting | 5 // An InvalidationStateTracker is an interface that handles persisting state | 
| 6 // and setting (persisting) max invalidation versions. | 6 // needed for invalidations. Currently, it is responsible for managing the | 
|  | 7 // following information: | 
|  | 8 // - Max version seen from the invalidation server to help dedupe invalidations. | 
|  | 9 // - Bootstrap data for the invalidation client. | 
|  | 10 // - Payloads and locally generated ack handles, to support local acking. | 
| 7 | 11 | 
| 8 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 12 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 
| 9 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 13 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 
| 10 | 14 | 
| 11 #include <map> | 15 #include <map> | 
|  | 16 #include <string> | 
| 12 | 17 | 
| 13 #include "base/basictypes.h" | 18 #include "base/basictypes.h" | 
|  | 19 #include "base/callback_forward.h" | 
|  | 20 #include "base/memory/ref_counted.h" | 
| 14 #include "google/cacheinvalidation/include/types.h" | 21 #include "google/cacheinvalidation/include/types.h" | 
|  | 22 #include "sync/internal_api/public/base/invalidation.h" | 
| 15 #include "sync/notifier/invalidation_util.h" | 23 #include "sync/notifier/invalidation_util.h" | 
| 16 | 24 | 
|  | 25 namespace base { | 
|  | 26 class TaskRunner; | 
|  | 27 }  // namespace base | 
|  | 28 | 
| 17 namespace syncer { | 29 namespace syncer { | 
| 18 | 30 | 
| 19 struct InvalidationState { | 31 struct InvalidationState { | 
|  | 32   InvalidationState(); | 
|  | 33   ~InvalidationState(); | 
|  | 34 | 
| 20   int64 version; | 35   int64 version; | 
|  | 36   std::string payload; | 
|  | 37   AckHandle expected; | 
|  | 38   AckHandle current; | 
| 21 }; | 39 }; | 
| 22 | 40 | 
| 23 // TODO(dcheng): Remove this in favor of adding an Equals() method. | 41 // TODO(dcheng): Remove this in favor of adding an Equals() method. | 
| 24 bool operator==(const InvalidationState& lhs, const InvalidationState& rhs); | 42 bool operator==(const InvalidationState& lhs, const InvalidationState& rhs); | 
| 25 | 43 | 
| 26 typedef std::map<invalidation::ObjectId, InvalidationState, ObjectIdLessThan> | 44 typedef std::map<invalidation::ObjectId, InvalidationState, ObjectIdLessThan> | 
| 27     InvalidationStateMap; | 45     InvalidationStateMap; | 
|  | 46 typedef std::map<invalidation::ObjectId, AckHandle, ObjectIdLessThan> | 
|  | 47     AckHandleMap; | 
| 28 | 48 | 
| 29 class InvalidationStateTracker { | 49 class InvalidationStateTracker { | 
| 30  public: | 50  public: | 
| 31   InvalidationStateTracker() {} | 51   InvalidationStateTracker() {} | 
| 32 | 52 | 
| 33   virtual InvalidationStateMap GetAllInvalidationStates() const = 0; | 53   virtual InvalidationStateMap GetAllInvalidationStates() const = 0; | 
| 34 | 54 | 
| 35   // |max_version| should be strictly greater than any existing max | 55   // |max_version| should be strictly greater than any existing max | 
| 36   // version for |model_type|. | 56   // version for |model_type|. | 
| 37   virtual void SetMaxVersion(const invalidation::ObjectId& id, | 57   virtual void SetMaxVersionAndPayload(const invalidation::ObjectId& id, | 
| 38                              int64 max_version) = 0; | 58                                        int64 max_version, | 
|  | 59                                        const std::string& payload) = 0; | 
| 39   // Removes all state tracked for |ids|. | 60   // Removes all state tracked for |ids|. | 
| 40   virtual void Forget(const ObjectIdSet& ids) = 0; | 61   virtual void Forget(const ObjectIdSet& ids) = 0; | 
| 41 | 62 | 
| 42   // Used by invalidation::InvalidationClient for persistence. |data| is an | 63   // Used by invalidation::InvalidationClient for persistence. |data| is an | 
| 43   // opaque blob that an invalidation client can use after a restart to | 64   // opaque blob that an invalidation client can use after a restart to | 
| 44   // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, | 65   // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, | 
| 45   // etc). | 66   // etc). | 
| 46   virtual void SetBootstrapData(const std::string& data) = 0; | 67   virtual void SetBootstrapData(const std::string& data) = 0; | 
| 47   virtual std::string GetBootstrapData() const = 0; | 68   virtual std::string GetBootstrapData() const = 0; | 
| 48 | 69 | 
|  | 70   // Used for generating our own local ack handles. Generates a new ack handle | 
|  | 71   // for each object id in |ids|. The result is returned via |callback| posted | 
|  | 72   // to |task_runner|. | 
|  | 73   virtual void GenerateAckHandles( | 
|  | 74       const ObjectIdSet& ids, | 
|  | 75       const scoped_refptr<base::TaskRunner>& task_runner, | 
|  | 76       base::Callback<void(const AckHandleMap&)> callback) = 0; | 
|  | 77 | 
|  | 78   // Records an acknowledgement for |id|. Note that no attempt at ordering is | 
|  | 79   // made. Acknowledge() only records the last ack_handle it received, even if | 
|  | 80   // the last ack_handle it received was generated before the value currently | 
|  | 81   // recorded. | 
|  | 82   virtual void Acknowledge(const invalidation::ObjectId& id, | 
|  | 83                            const AckHandle& ack_handle) = 0; | 
|  | 84 | 
| 49  protected: | 85  protected: | 
| 50   virtual ~InvalidationStateTracker() {} | 86   virtual ~InvalidationStateTracker() {} | 
| 51 }; | 87 }; | 
| 52 | 88 | 
| 53 }  // namespace syncer | 89 }  // namespace syncer | 
| 54 | 90 | 
| 55 #endif  // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 91 #endif  // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 
| OLD | NEW | 
|---|