| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ | 5 #ifndef COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ |
| 6 #define COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ | 6 #define COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "components/invalidation/public/ack_handle.h" | 16 #include "components/invalidation/public/ack_handle.h" |
| 16 #include "components/invalidation/public/invalidation_export.h" | 17 #include "components/invalidation/public/invalidation_export.h" |
| 17 #include "google/cacheinvalidation/include/types.h" | 18 #include "google/cacheinvalidation/include/types.h" |
| 18 | 19 |
| 19 namespace syncer { | 20 namespace syncer { |
| 20 | 21 |
| 21 class DroppedInvalidationTracker; | 22 class DroppedInvalidationTracker; |
| 22 class AckHandler; | 23 class AckHandler; |
| 23 | 24 |
| 24 // Represents a local invalidation, and is roughly analogous to | 25 // Represents a local invalidation, and is roughly analogous to |
| 25 // invalidation::Invalidation. Unlike invalidation::Invalidation, this class | 26 // invalidation::Invalidation. Unlike invalidation::Invalidation, this class |
| 26 // supports "local" ack-tracking and simple serialization to pref values. | 27 // supports "local" ack-tracking and simple serialization to pref values. |
| 27 class INVALIDATION_EXPORT Invalidation { | 28 class INVALIDATION_EXPORT Invalidation { |
| 28 public: | 29 public: |
| 29 // Factory functions. | 30 // Factory functions. |
| 30 static Invalidation Init(const invalidation::ObjectId& id, | 31 static Invalidation Init(const invalidation::ObjectId& id, |
| 31 int64 version, | 32 int64_t version, |
| 32 const std::string& payload); | 33 const std::string& payload); |
| 33 static Invalidation InitUnknownVersion(const invalidation::ObjectId& id); | 34 static Invalidation InitUnknownVersion(const invalidation::ObjectId& id); |
| 34 static Invalidation InitFromDroppedInvalidation(const Invalidation& dropped); | 35 static Invalidation InitFromDroppedInvalidation(const Invalidation& dropped); |
| 35 static scoped_ptr<Invalidation> InitFromValue( | 36 static scoped_ptr<Invalidation> InitFromValue( |
| 36 const base::DictionaryValue& value); | 37 const base::DictionaryValue& value); |
| 37 | 38 |
| 38 ~Invalidation(); | 39 ~Invalidation(); |
| 39 | 40 |
| 40 // Compares two invalidations. The comparison ignores ack-tracking state. | 41 // Compares two invalidations. The comparison ignores ack-tracking state. |
| 41 bool Equals(const Invalidation& other) const; | 42 bool Equals(const Invalidation& other) const; |
| 42 | 43 |
| 43 invalidation::ObjectId object_id() const; | 44 invalidation::ObjectId object_id() const; |
| 44 bool is_unknown_version() const; | 45 bool is_unknown_version() const; |
| 45 | 46 |
| 46 // Safe to call only if is_unknown_version() returns false. | 47 // Safe to call only if is_unknown_version() returns false. |
| 47 int64 version() const; | 48 int64_t version() const; |
| 48 | 49 |
| 49 // Safe to call only if is_unknown_version() returns false. | 50 // Safe to call only if is_unknown_version() returns false. |
| 50 const std::string& payload() const; | 51 const std::string& payload() const; |
| 51 | 52 |
| 52 const AckHandle& ack_handle() const; | 53 const AckHandle& ack_handle() const; |
| 53 | 54 |
| 54 // Sets the AckHandler to be used to track this Invalidation. | 55 // Sets the AckHandler to be used to track this Invalidation. |
| 55 // | 56 // |
| 56 // This should be set by the class that generates the invalidation. Clients | 57 // This should be set by the class that generates the invalidation. Clients |
| 57 // of the Invalidations API should not need to call this. | 58 // of the Invalidations API should not need to call this. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // To indicate recovery from a drop event, the client should call | 90 // To indicate recovery from a drop event, the client should call |
| 90 // Acknowledge() on the most recently dropped inavlidation. | 91 // Acknowledge() on the most recently dropped inavlidation. |
| 91 void Drop(); | 92 void Drop(); |
| 92 | 93 |
| 93 scoped_ptr<base::DictionaryValue> ToValue() const; | 94 scoped_ptr<base::DictionaryValue> ToValue() const; |
| 94 std::string ToString() const; | 95 std::string ToString() const; |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 Invalidation(const invalidation::ObjectId& id, | 98 Invalidation(const invalidation::ObjectId& id, |
| 98 bool is_unknown_version, | 99 bool is_unknown_version, |
| 99 int64 version, | 100 int64_t version, |
| 100 const std::string& payload, | 101 const std::string& payload, |
| 101 AckHandle ack_handle); | 102 AckHandle ack_handle); |
| 102 | 103 |
| 103 // The ObjectId to which this invalidation belongs. | 104 // The ObjectId to which this invalidation belongs. |
| 104 invalidation::ObjectId id_; | 105 invalidation::ObjectId id_; |
| 105 | 106 |
| 106 // This flag is set to true if this is an unknown version invalidation. | 107 // This flag is set to true if this is an unknown version invalidation. |
| 107 bool is_unknown_version_; | 108 bool is_unknown_version_; |
| 108 | 109 |
| 109 // The version number of this invalidation. Should not be accessed if this is | 110 // The version number of this invalidation. Should not be accessed if this is |
| 110 // an unkown version invalidation. | 111 // an unkown version invalidation. |
| 111 int64 version_; | 112 int64_t version_; |
| 112 | 113 |
| 113 // The payaload associated with this invalidation. Should not be accessed if | 114 // The payaload associated with this invalidation. Should not be accessed if |
| 114 // this is an unknown version invalidation. | 115 // this is an unknown version invalidation. |
| 115 std::string payload_; | 116 std::string payload_; |
| 116 | 117 |
| 117 // A locally generated unique ID used to manage local acknowledgements. | 118 // A locally generated unique ID used to manage local acknowledgements. |
| 118 AckHandle ack_handle_; | 119 AckHandle ack_handle_; |
| 119 | 120 |
| 120 // The acknowledgement tracking handler and its thread. | 121 // The acknowledgement tracking handler and its thread. |
| 121 base::WeakPtr<AckHandler> ack_handler_; | 122 base::WeakPtr<AckHandler> ack_handler_; |
| 122 scoped_refptr<base::SequencedTaskRunner> ack_handler_task_runner_; | 123 scoped_refptr<base::SequencedTaskRunner> ack_handler_task_runner_; |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 } // namespace syncer | 126 } // namespace syncer |
| 126 | 127 |
| 127 #endif // COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ | 128 #endif // COMPONENTS_INVALIDATION_PUBLIC_INVALIDATION_H_ |
| OLD | NEW |