Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/internal_api/public/base/invalidation.h" | 5 #include "sync/internal_api/public/base/invalidation.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 return !state_.empty(); | 57 return !state_.empty(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 AckHandle::AckHandle(const std::string& state, base::Time timestamp) | 60 AckHandle::AckHandle(const std::string& state, base::Time timestamp) |
| 61 : state_(state), timestamp_(timestamp) { | 61 : state_(state), timestamp_(timestamp) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 AckHandle::~AckHandle() { | 64 AckHandle::~AckHandle() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 const int64 Invalidation::kUnknownVersion = -1; | |
|
rlarocque
2013/07/16 18:33:16
I wish this wasn't necessary. Looking at the prot
Steve Condie
2013/07/16 21:23:06
Ok. I will be doing that comparison in my code, bu
| |
| 68 | |
| 67 Invalidation::Invalidation() | 69 Invalidation::Invalidation() |
| 68 : ack_handle(AckHandle::InvalidAckHandle()) { | 70 : version(kUnknownVersion), ack_handle(AckHandle::InvalidAckHandle()) { |
| 69 } | 71 } |
| 70 | 72 |
| 71 Invalidation::~Invalidation() { | 73 Invalidation::~Invalidation() { |
| 72 } | 74 } |
| 73 | 75 |
| 74 bool Invalidation::Equals(const Invalidation& other) const { | 76 bool Invalidation::Equals(const Invalidation& other) const { |
| 75 return (payload == other.payload) && ack_handle.Equals(other.ack_handle); | 77 return (version == other.version) && (payload == other.payload) && |
| 78 ack_handle.Equals(other.ack_handle); | |
| 76 } | 79 } |
| 77 | 80 |
| 78 scoped_ptr<base::DictionaryValue> Invalidation::ToValue() const { | 81 scoped_ptr<base::DictionaryValue> Invalidation::ToValue() const { |
| 79 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 82 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 83 value->SetString("version", base::Int64ToString(version)); | |
| 80 value->SetString("payload", payload); | 84 value->SetString("payload", payload); |
| 81 value->Set("ackHandle", ack_handle.ToValue().release()); | 85 value->Set("ackHandle", ack_handle.ToValue().release()); |
| 82 return value.Pass(); | 86 return value.Pass(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 bool Invalidation::ResetFromValue(const base::DictionaryValue& value) { | 89 bool Invalidation::ResetFromValue(const base::DictionaryValue& value) { |
| 86 const base::DictionaryValue* ack_handle_value = NULL; | 90 const base::DictionaryValue* ack_handle_value = NULL; |
| 91 std::string version_as_string; | |
|
rlarocque
2013/07/16 18:33:16
nit: This function returns false when the parsing
Steve Condie
2013/07/16 21:23:06
Done.
| |
| 92 if (!value.GetString("version", &version_as_string) || | |
| 93 !base::StringToInt64(version_as_string, &version)) { | |
| 94 version = kUnknownVersion; | |
| 95 } | |
| 87 return | 96 return |
| 88 value.GetString("payload", &payload) && | 97 value.GetString("payload", &payload) && |
| 89 value.GetDictionary("ackHandle", &ack_handle_value) && | 98 value.GetDictionary("ackHandle", &ack_handle_value) && |
| 90 ack_handle.ResetFromValue(*ack_handle_value); | 99 ack_handle.ResetFromValue(*ack_handle_value); |
| 91 } | 100 } |
| 92 | 101 |
| 93 } // namespace syncer | 102 } // namespace syncer |
| OLD | NEW |