Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Unified Diff: sync/internal_api/public/base/invalidation.cc

Issue 11415049: Implement features needed for local ack handling in InvalidationStateTracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/public/base/invalidation.cc
diff --git a/sync/internal_api/public/base/invalidation.cc b/sync/internal_api/public/base/invalidation.cc
index 2ddaa63adea9d3fa91ea5afa4c01c12bd73826a4..4de2e7b53746dc9c9a325bb9234d8bba42274055 100644
--- a/sync/internal_api/public/base/invalidation.cc
+++ b/sync/internal_api/public/base/invalidation.cc
@@ -4,20 +4,52 @@
#include "sync/internal_api/public/base/invalidation.h"
+#include <cstddef>
+#include "base/rand_util.h"
+#include "base/string_number_conversions.h"
#include "base/values.h"
namespace syncer {
+namespace {
+// Hopefully enough bytes for uniqueness.
+const size_t kBytesInHandle = 16;
+} // namespace
+
+AckHandle AckHandle::CreateUnique() {
+ // This isn't a valid UUID, so we don't attempt to format it like one.
+ uint8_t random_bytes[kBytesInHandle];
+ base::RandBytes(random_bytes, sizeof(random_bytes));
+ return AckHandle(base::HexEncode(random_bytes, sizeof(random_bytes)));
+}
+
+AckHandle AckHandle::InvalidAckHandle() {
+ return AckHandle(std::string());
+}
+
bool AckHandle::Equals(const AckHandle& other) const {
- return true;
+ return state_ == other.state_;
+}
+
+scoped_ptr<base::DictionaryValue> AckHandle::ToValue() const {
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ value->SetString("state", state_);
+ return value.Pass();
+}
+
+bool AckHandle::ResetFromValue(const base::DictionaryValue& value) {
+ return value.GetString("state", &state_);
+}
+
+bool AckHandle::IsValid() const {
+ return !state_.empty();
}
-scoped_ptr<base::Value> AckHandle::ToValue() const {
- return scoped_ptr<base::Value>(new DictionaryValue());
+AckHandle::AckHandle(const std::string& state) : state_(state) {
}
-bool AckHandle::ResetFromValue(const base::Value& value) {
- return true;
+Invalidation::Invalidation()
+ : ack_handle(AckHandle::InvalidAckHandle()) {
}
bool Invalidation::Equals(const Invalidation& other) const {
@@ -32,10 +64,10 @@ scoped_ptr<base::DictionaryValue> Invalidation::ToValue() const {
}
bool Invalidation::ResetFromValue(const base::DictionaryValue& value) {
- const base::Value* ack_handle_value = NULL;
+ const DictionaryValue* ack_handle_value = NULL;
return
value.GetString("payload", &payload) &&
- value.Get("ackHandle", &ack_handle_value) &&
+ value.GetDictionary("ackHandle", &ack_handle_value) &&
ack_handle.ResetFromValue(*ack_handle_value);
}

Powered by Google App Engine
This is Rietveld 408576698