| 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..58f5ccea85bc3d7db49f93824350de6c827ab097 100644
|
| --- a/sync/internal_api/public/base/invalidation.cc
|
| +++ b/sync/internal_api/public/base/invalidation.cc
|
| @@ -4,22 +4,67 @@
|
|
|
| #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 random_bytes[kBytesInHandle];
|
| + base::RandBytes(random_bytes, sizeof(random_bytes));
|
| + return AckHandle(base::HexEncode(random_bytes, sizeof(random_bytes)),
|
| + base::Time::Now());
|
| +}
|
| +
|
| +AckHandle AckHandle::InvalidAckHandle() {
|
| + return AckHandle(std::string(), base::Time());
|
| +}
|
| +
|
| bool AckHandle::Equals(const AckHandle& other) const {
|
| - return true;
|
| + return state_ == other.state_ && timestamp_ == other.timestamp_;
|
| }
|
|
|
| -scoped_ptr<base::Value> AckHandle::ToValue() const {
|
| - return scoped_ptr<base::Value>(new DictionaryValue());
|
| +scoped_ptr<base::DictionaryValue> AckHandle::ToValue() const {
|
| + scoped_ptr<DictionaryValue> value(new DictionaryValue());
|
| + value->SetString("state", state_);
|
| + value->SetString("timestamp",
|
| + base::Int64ToString(timestamp_.ToInternalValue()));
|
| + return value.Pass();
|
| }
|
|
|
| -bool AckHandle::ResetFromValue(const base::Value& value) {
|
| +bool AckHandle::ResetFromValue(const base::DictionaryValue& value) {
|
| + if (!value.GetString("state", &state_))
|
| + return false;
|
| + std::string timestamp_as_string;
|
| + if (!value.GetString("timestamp", ×tamp_as_string))
|
| + return false;
|
| + int64 timestamp_value;
|
| + if (!base::StringToInt64(timestamp_as_string, ×tamp_value))
|
| + return false;
|
| + timestamp_ = base::Time::FromInternalValue(timestamp_value);
|
| return true;
|
| }
|
|
|
| +bool AckHandle::IsValid() const {
|
| + return !state_.empty();
|
| +}
|
| +
|
| +AckHandle::AckHandle(const std::string& state, base::Time timestamp)
|
| + : state_(state), timestamp_(timestamp) {
|
| +}
|
| +
|
| +Invalidation::Invalidation()
|
| + : ack_handle(AckHandle::InvalidAckHandle()) {
|
| +}
|
| +
|
| bool Invalidation::Equals(const Invalidation& other) const {
|
| return (payload == other.payload) && ack_handle.Equals(other.ack_handle);
|
| }
|
| @@ -32,10 +77,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);
|
| }
|
|
|
|
|