Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/values.h" |
| 13 #include "google/cacheinvalidation/include/types.h" | |
| 13 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
| 14 | 15 #include "sync/internal_api/public/base/ack_handle.h" |
| 15 namespace base { | |
| 16 class DictionaryValue; | |
| 17 } // namespace | |
| 18 | 16 |
| 19 namespace syncer { | 17 namespace syncer { |
| 20 | 18 |
| 21 // Opaque class that represents a local ack handle. We don't reuse the | 19 class DroppedInvalidationTracker; |
| 22 // invalidation ack handles to avoid unnecessary dependencies. | 20 class AckHandler; |
| 23 class SYNC_EXPORT AckHandle { | |
| 24 public: | |
| 25 static AckHandle CreateUnique(); | |
| 26 static AckHandle InvalidAckHandle(); | |
| 27 | |
| 28 bool Equals(const AckHandle& other) const; | |
| 29 | |
| 30 scoped_ptr<base::DictionaryValue> ToValue() const; | |
| 31 bool ResetFromValue(const base::DictionaryValue& value); | |
| 32 | |
| 33 bool IsValid() const; | |
| 34 | |
| 35 ~AckHandle(); | |
| 36 | |
| 37 private: | |
| 38 // Explicitly copyable and assignable for STL containers. | |
| 39 AckHandle(const std::string& state, base::Time timestamp); | |
| 40 | |
| 41 std::string state_; | |
| 42 base::Time timestamp_; | |
| 43 }; | |
| 44 | 21 |
| 45 // Represents a local invalidation, and is roughly analogous to | 22 // Represents a local invalidation, and is roughly analogous to |
| 46 // invalidation::Invalidation. It contains a version (which may be | 23 // invalidation::Invalidation. |
|
tim (not reviewing)
2013/09/20 21:53:46
This comment raises the question of why we need it
rlarocque
2013/09/23 18:38:19
Added some comments.
The main difference is suppo
| |
| 47 // kUnknownVersion), a payload (which may be empty) and an | 24 class SYNC_EXPORT Invalidation { |
| 48 // associated ack handle that an InvalidationHandler implementation can use to | 25 public: |
| 49 // acknowledge receipt of the invalidation. It does not embed the object ID, | 26 // Factory functions. |
| 50 // since it is typically associated with it through ObjectIdInvalidationMap. | 27 static Invalidation Init( |
| 51 struct SYNC_EXPORT Invalidation { | 28 const invalidation::ObjectId& id, |
| 52 static const int64 kUnknownVersion; | 29 int64 version, |
| 30 const std::string& payload); | |
| 31 static Invalidation InitWithAckHandle( | |
| 32 const invalidation::ObjectId& id, | |
| 33 int64 version, | |
| 34 const std::string& payload); | |
| 35 static Invalidation InitUnknownVersion(const invalidation::ObjectId& id); | |
| 36 static Invalidation InitUnknownVersionWithAckHandle( | |
| 37 const invalidation::ObjectId& id); | |
| 53 | 38 |
| 54 Invalidation(); | 39 Invalidation(); |
|
tim (not reviewing)
2013/09/20 21:53:46
Remove this?
rlarocque
2013/09/23 18:38:19
I can't remove support for the zero-argument const
tim (not reviewing)
2013/09/24 21:16:54
You don't need a default constructor for statement
rlarocque
2013/09/25 00:40:00
Right. That was a bad example.
I might have reme
| |
| 55 ~Invalidation(); | 40 ~Invalidation(); |
| 56 | 41 |
| 57 bool Equals(const Invalidation& other) const; | 42 // Compares two invalidations. The comparison ignores ack-tracking state. |
| 43 bool operator==(const Invalidation& other) const; | |
| 44 | |
| 45 invalidation::ObjectId GetObjectId() const; | |
| 46 bool IsUnknownVersion() const; | |
| 47 | |
| 48 // Safe to call only if IsUnknownVersion() returns false. | |
| 49 int64 GetVersion() const; | |
| 50 | |
| 51 // Safe to call only if IsUnknownVersion() returns false. | |
| 52 const std::string& GetPayload() const; | |
| 53 | |
| 54 const AckHandle& GetAckHandle() const; | |
| 55 void SetAckHandle(const AckHandle& ack_handle); | |
| 58 | 56 |
| 59 scoped_ptr<base::DictionaryValue> ToValue() const; | 57 scoped_ptr<base::DictionaryValue> ToValue() const; |
| 60 bool ResetFromValue(const base::DictionaryValue& value); | 58 bool ResetFromValue(const base::DictionaryValue& value); |
| 59 std::string ToString() const; | |
| 61 | 60 |
| 62 int64 version; | 61 private: |
| 63 std::string payload; | 62 Invalidation(const invalidation::ObjectId& id, |
| 64 AckHandle ack_handle; | 63 bool is_unknown_version, |
| 64 int64 version, | |
| 65 const std::string& payload, | |
| 66 AckHandle ack_handle); | |
| 67 | |
| 68 invalidation::ObjectId id_; | |
| 69 bool is_unknown_version_; | |
| 70 int64 version_; | |
| 71 std::string payload_; | |
| 72 | |
| 73 AckHandle ack_handle_; | |
|
tim (not reviewing)
2013/09/20 21:53:46
It's worth commenting these fields (some, at least
rlarocque
2013/09/23 18:38:19
Done.
| |
| 65 }; | 74 }; |
| 66 | 75 |
| 67 } // namespace syncer | 76 } // namespace syncer |
| 68 | 77 |
| 69 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ | 78 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ |
| OLD | NEW |