This source file includes following definitions.
- CreateUnique
- InvalidAckHandle
- Equals
- ToValue
- ResetFromValue
- IsValid
- timestamp_
#include "sync/internal_api/public/base/ack_handle.h"
#include <cstddef>
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
namespace syncer {
namespace {
const size_t kBytesInHandle = 16;
}
AckHandle AckHandle::CreateUnique() {
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 state_ == other.state_ && timestamp_ == other.timestamp_;
}
scoped_ptr<base::DictionaryValue> AckHandle::ToValue() const {
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
value->SetString("state", state_);
value->SetString("timestamp",
base::Int64ToString(timestamp_.ToInternalValue()));
return value.Pass();
}
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) {
}
AckHandle::~AckHandle() {
}
}