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

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

Issue 10911084: Implement Invalidator::Acknowledge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restart test + more cleanup Created 8 years, 2 months 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..002d700d569038888426cac5d5609ba8cd3fe89d 100644
--- a/sync/internal_api/public/base/invalidation.cc
+++ b/sync/internal_api/public/base/invalidation.cc
@@ -4,20 +4,51 @@
#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;
+// This is not a valid handle name, since all valid handles are 16 bytes long.
+const char kInvalidHandleName[] = "INVALIDHANDLENAME";
+COMPILE_ASSERT(kBytesInHandle != arraysize(kInvalidHandleName),
+ invalid_handle_name_must_differ_in_length_from_valid_handles);
+} // 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(kInvalidHandleName);
+}
+
bool AckHandle::Equals(const AckHandle& other) const {
- return true;
+ return state_ == other.state_;
}
scoped_ptr<base::Value> AckHandle::ToValue() const {
- return scoped_ptr<base::Value>(new DictionaryValue());
+ return scoped_ptr<base::Value>(new StringValue(state_));
akalin 2012/10/19 13:27:16 more future-proof to have a dictionary with a sing
dcheng 2012/10/19 19:38:11 Done.
}
bool AckHandle::ResetFromValue(const base::Value& value) {
- return true;
+ // TODO(dcheng): Add debug mode sanity checking?
+ return value.GetAsString(&state_);
+}
+
+AckHandle::AckHandle(const std::string& state) : state_(state) {
+}
+
+Invalidation::Invalidation()
+ : ack_handle(AckHandle::InvalidAckHandle()) {
}
bool Invalidation::Equals(const Invalidation& other) const {

Powered by Google App Engine
This is Rietveld 408576698