| 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 getting |
| 6 // and setting (persisting) max invalidation versions. | 6 // and setting (persisting) max invalidation versions and our local ack |
| 7 // handles. |
| 7 | 8 |
| 8 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 9 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ |
| 9 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 10 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ |
| 10 | 11 |
| 11 #include <map> | 12 #include <map> |
| 13 #include <string> |
| 12 | 14 |
| 13 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback_forward.h" |
| 17 #include "base/memory/ref_counted.h" |
| 14 #include "google/cacheinvalidation/include/types.h" | 18 #include "google/cacheinvalidation/include/types.h" |
| 19 #include "sync/internal_api/public/base/invalidation.h" |
| 15 #include "sync/notifier/invalidation_util.h" | 20 #include "sync/notifier/invalidation_util.h" |
| 16 | 21 |
| 22 namespace base { |
| 23 class TaskRunner; |
| 24 } // namespace base |
| 25 |
| 17 namespace syncer { | 26 namespace syncer { |
| 18 | 27 |
| 19 struct InvalidationState { | 28 struct InvalidationState { |
| 29 InvalidationState(); |
| 30 ~InvalidationState(); |
| 31 |
| 20 int64 version; | 32 int64 version; |
| 33 std::string payload; |
| 34 AckHandle expected; |
| 35 AckHandle current; |
| 21 }; | 36 }; |
| 22 | 37 |
| 23 // TODO(dcheng): Remove this in favor of adding an Equals() method. | 38 // TODO(dcheng): Remove this in favor of adding an Equals() method. |
| 24 bool operator==(const InvalidationState& lhs, const InvalidationState& rhs); | 39 bool operator==(const InvalidationState& lhs, const InvalidationState& rhs); |
| 25 | 40 |
| 26 typedef std::map<invalidation::ObjectId, InvalidationState, ObjectIdLessThan> | 41 typedef std::map<invalidation::ObjectId, InvalidationState, ObjectIdLessThan> |
| 27 InvalidationStateMap; | 42 InvalidationStateMap; |
| 43 typedef std::map<invalidation::ObjectId, AckHandle, ObjectIdLessThan> |
| 44 AckHandleMap; |
| 28 | 45 |
| 29 class InvalidationStateTracker { | 46 class InvalidationStateTracker { |
| 30 public: | 47 public: |
| 31 InvalidationStateTracker() {} | 48 InvalidationStateTracker() {} |
| 32 | 49 |
| 33 virtual InvalidationStateMap GetAllInvalidationStates() const = 0; | 50 virtual InvalidationStateMap GetAllInvalidationStates() const = 0; |
| 34 | 51 |
| 35 // |max_version| should be strictly greater than any existing max | 52 // |max_version| should be strictly greater than any existing max |
| 36 // version for |model_type|. | 53 // version for |model_type|. |
| 37 virtual void SetMaxVersion(const invalidation::ObjectId& id, | 54 virtual void SetMaxVersionAndPayload(const invalidation::ObjectId& id, |
| 38 int64 max_version) = 0; | 55 int64 max_version, |
| 56 const std::string& payload) = 0; |
| 39 // Removes all state tracked for |ids|. | 57 // Removes all state tracked for |ids|. |
| 40 virtual void Forget(const ObjectIdSet& ids) = 0; | 58 virtual void Forget(const ObjectIdSet& ids) = 0; |
| 41 | 59 |
| 42 // Used by invalidation::InvalidationClient for persistence. |data| is an | 60 // Used by invalidation::InvalidationClient for persistence. |data| is an |
| 43 // opaque blob that an invalidation client can use after a restart to | 61 // opaque blob that an invalidation client can use after a restart to |
| 44 // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, | 62 // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, |
| 45 // etc). | 63 // etc). |
| 46 virtual void SetBootstrapData(const std::string& data) = 0; | 64 virtual void SetBootstrapData(const std::string& data) = 0; |
| 47 virtual std::string GetBootstrapData() const = 0; | 65 virtual std::string GetBootstrapData() const = 0; |
| 48 | 66 |
| 67 // Used for generating our own local ack handles. Generates a new ack handle |
| 68 // for each object id in |ids|. The result is returned via |callback| posted |
| 69 // to |task_runner|. |
| 70 virtual void GenerateAckHandles( |
| 71 const ObjectIdSet& ids, |
| 72 const scoped_refptr<base::TaskRunner>& task_runner, |
| 73 base::Callback<void(const AckHandleMap&)> callback) = 0; |
| 74 virtual void Acknowledge(const invalidation::ObjectId& id, |
| 75 const AckHandle& ack_handle) = 0; |
| 76 |
| 49 protected: | 77 protected: |
| 50 virtual ~InvalidationStateTracker() {} | 78 virtual ~InvalidationStateTracker() {} |
| 51 }; | 79 }; |
| 52 | 80 |
| 53 } // namespace syncer | 81 } // namespace syncer |
| 54 | 82 |
| 55 #endif // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ | 83 #endif // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ |
| OLD | NEW |