| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ | 5 #ifndef SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ |
| 6 #define SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ | 6 #define SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // Copying ProtoValuePtr results in ref-counted sharing of the | 45 // Copying ProtoValuePtr results in ref-counted sharing of the |
| 46 // underlying wrapper and the value contained in the wrapper. | 46 // underlying wrapper and the value contained in the wrapper. |
| 47 // | 47 // |
| 48 // The public interface includes only immutable access to the wrapped value. | 48 // The public interface includes only immutable access to the wrapped value. |
| 49 // The only way to assign a value to ProtoValuePtr is through a | 49 // The only way to assign a value to ProtoValuePtr is through a |
| 50 // private SetValue function which is called from EntryKernel. That results | 50 // private SetValue function which is called from EntryKernel. That results |
| 51 // in stopping sharing the previous value and creating a wrapper to the new | 51 // in stopping sharing the previous value and creating a wrapper to the new |
| 52 // value. | 52 // value. |
| 53 template <typename T, typename Traits = DefaultProtoValuePtrTraits<T>> | 53 template <typename T, typename Traits = DefaultProtoValuePtrTraits<T>> |
| 54 class ProtoValuePtr { | 54 class ProtoValuePtr { |
| 55 TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ProtoValuePtr) | |
| 56 | |
| 57 private: | 55 private: |
| 58 // Immutable shareable ref-counted wrapper that embeds the value. | 56 // Immutable shareable ref-counted wrapper that embeds the value. |
| 59 class Wrapper : public base::RefCountedThreadSafe<Wrapper> { | 57 class Wrapper : public base::RefCountedThreadSafe<Wrapper> { |
| 60 public: | 58 public: |
| 61 Wrapper(const T& value) { Traits::CopyValue(&value_, value); } | 59 Wrapper(const T& value) { Traits::CopyValue(&value_, value); } |
| 62 Wrapper(T* value) { Traits::SwapValue(&value_, value); } | 60 Wrapper(T* value) { Traits::SwapValue(&value_, value); } |
| 63 | 61 |
| 64 const T& value() const { return value_; } | 62 const T& value() const { return value_; } |
| 65 // Create wrapper by deserializing a BLOB. | 63 // Create wrapper by deserializing a BLOB. |
| 66 static Wrapper* ParseFromBlob(const void* blob, int length) { | 64 static Wrapper* ParseFromBlob(const void* blob, int length) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void load(const void* blob, int length) { | 119 void load(const void* blob, int length) { |
| 122 wrapper_ = Wrapper::ParseFromBlob(blob, length); | 120 wrapper_ = Wrapper::ParseFromBlob(blob, length); |
| 123 } | 121 } |
| 124 | 122 |
| 125 scoped_refptr<Wrapper> wrapper_; | 123 scoped_refptr<Wrapper> wrapper_; |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 } // namespace syncer | 126 } // namespace syncer |
| 129 | 127 |
| 130 #endif // SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ | 128 #endif // SYNC_SYNCABLE_ENTRY_PROTO_FIELD_PTR_H_ |
| OLD | NEW |