Chromium Code Reviews| Index: sync/internal_api/public/base/invalidation_state.cc |
| diff --git a/sync/internal_api/public/base/invalidation_state.cc b/sync/internal_api/public/base/invalidation_state.cc |
| index 6f71351ecda9da6a3c7a6e10e2901acfc7d2a985..f368641c6e561c4d706f2a4425759c7953ee3e46 100644 |
| --- a/sync/internal_api/public/base/invalidation_state.cc |
| +++ b/sync/internal_api/public/base/invalidation_state.cc |
| @@ -4,20 +4,48 @@ |
| #include "sync/internal_api/public/base/invalidation_state.h" |
| +#include "base/rand_util.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() { |
| + // We don't have a UUID generator, or else it'd be nice to use that instead. |
| + // TODO(dcheng): Do we want to base64 encode this? |
| + return AckHandle(base::RandBytesAsString(kBytesInHandle)); |
|
Pete Williamson
2012/09/14 18:28:22
Why not just something that increments by one? Do
dcheng
2012/09/14 19:08:49
I thought about doing that, but I think it's easie
|
| +} |
| + |
| +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_)); |
| } |
| 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) { |
| +} |
| + |
| +InvalidationState::InvalidationState() |
| + : ack_handle(AckHandle::InvalidAckHandle()) { |
| } |
| bool InvalidationState::Equals(const InvalidationState& other) const { |