OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BLIMP_HELIUM_LWW_REGISTER_H_ | 5 #ifndef BLIMP_HELIUM_LWW_REGISTER_H_ |
6 #define BLIMP_HELIUM_LWW_REGISTER_H_ | 6 #define BLIMP_HELIUM_LWW_REGISTER_H_ |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "blimp/helium/blimp_helium_export.h" | 9 #include "blimp/helium/blimp_helium_export.h" |
10 #include "blimp/helium/coded_value_serializer.h" | 10 #include "blimp/helium/coded_value_serializer.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 CodedValueSerializer::Serialize(last_modified_, output_stream); | 79 CodedValueSerializer::Serialize(last_modified_, output_stream); |
80 CodedValueSerializer::Serialize(value_, output_stream); | 80 CodedValueSerializer::Serialize(value_, output_stream); |
81 } | 81 } |
82 | 82 |
83 template <class RegisterType> | 83 template <class RegisterType> |
84 Result LwwRegister<RegisterType>::ApplyChangeset( | 84 Result LwwRegister<RegisterType>::ApplyChangeset( |
85 Revision to, | 85 Revision to, |
86 google::protobuf::io::CodedInputStream* input_stream) { | 86 google::protobuf::io::CodedInputStream* input_stream) { |
87 VersionVector remote; | 87 VersionVector remote; |
88 if (!CodedValueSerializer::Deserialize(input_stream, &remote)) { | 88 if (!CodedValueSerializer::Deserialize(input_stream, &remote)) { |
89 return Result::ERR_INTERNAL_ERROR; | 89 return Result::ERR_PROTOCOL_ERROR; |
90 } | 90 } |
91 remote = remote.Invert(); | 91 remote = remote.Invert(); |
92 VersionVector::Comparison cmp = last_modified_.CompareTo(remote); | 92 VersionVector::Comparison cmp = last_modified_.CompareTo(remote); |
| 93 |
| 94 RegisterType input_value; |
| 95 if (!CodedValueSerializer::Deserialize(input_stream, &input_value)) { |
| 96 return Result::ERR_PROTOCOL_ERROR; |
| 97 } |
93 if (cmp == VersionVector::Comparison::LessThan || | 98 if (cmp == VersionVector::Comparison::LessThan || |
94 (cmp == VersionVector::Comparison::Conflict && !locally_owned_)) { | 99 (cmp == VersionVector::Comparison::Conflict && !locally_owned_)) { |
95 if (!CodedValueSerializer::Deserialize(input_stream, &value_)) { | 100 value_ = input_value; |
96 return Result::ERR_INTERNAL_ERROR; | |
97 } | |
98 value_set_ = true; | 101 value_set_ = true; |
99 } | 102 } |
| 103 |
100 last_modified_ = last_modified_.MergeWith(remote); | 104 last_modified_ = last_modified_.MergeWith(remote); |
101 return Result::SUCCESS; | 105 return Result::SUCCESS; |
102 } | 106 } |
103 | 107 |
104 template <class RegisterType> | 108 template <class RegisterType> |
105 void LwwRegister<RegisterType>::ReleaseBefore(Revision checkpoint) { | 109 void LwwRegister<RegisterType>::ReleaseBefore(Revision checkpoint) { |
106 // no-op | 110 // no-op |
107 } | 111 } |
108 | 112 |
109 } // namespace helium | 113 } // namespace helium |
110 } // namespace blimp | 114 } // namespace blimp |
111 | 115 |
112 #endif // BLIMP_HELIUM_LWW_REGISTER_H_ | 116 #endif // BLIMP_HELIUM_LWW_REGISTER_H_ |
OLD | NEW |