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 COMPONENTS_SYNC_BASE_PROTO_VALUE_PTR_H_ | 5 #ifndef COMPONENTS_SYNC_BASE_PROTO_VALUE_PTR_H_ |
6 #define COMPONENTS_SYNC_BASE_PROTO_VALUE_PTR_H_ | 6 #define COMPONENTS_SYNC_BASE_PROTO_VALUE_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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 const T& value() const { | 83 const T& value() const { |
84 return wrapper_ ? wrapper_->value() : Traits::DefaultValue(); | 84 return wrapper_ ? wrapper_->value() : Traits::DefaultValue(); |
85 } | 85 } |
86 | 86 |
87 const T* operator->() const { | 87 const T* operator->() const { |
88 const T& wrapped_instance = value(); | 88 const T& wrapped_instance = value(); |
89 return &wrapped_instance; | 89 return &wrapped_instance; |
90 } | 90 } |
91 | 91 |
| 92 explicit operator bool () const { return wrapper_ != nullptr; } |
| 93 bool operator == (decltype(nullptr)) const { return wrapper_ == nullptr; } |
| 94 bool operator != (decltype(nullptr)) const { return wrapper_ != nullptr; } |
| 95 |
92 private: | 96 private: |
93 friend struct syncable::EntryKernel; | 97 friend struct syncable::EntryKernel; |
94 friend struct syncer_v2::EntityData; | 98 friend struct syncer_v2::EntityData; |
95 friend class syncer_v2::ProcessorEntityTracker; | 99 friend class syncer_v2::ProcessorEntityTracker; |
96 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ValueAssignment); | 100 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ValueAssignment); |
97 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ValueSwap); | 101 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ValueSwap); |
98 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, SharingTest); | 102 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, SharingTest); |
99 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ParsingTest); | 103 FRIEND_TEST_ALL_PREFIXES(ProtoValuePtrTest, ParsingTest); |
100 | 104 |
101 // set the value to copy of |new_value|. | 105 // set the value to copy of |new_value|. |
(...skipping 18 matching lines...) Expand all Loading... |
120 } | 124 } |
121 } | 125 } |
122 | 126 |
123 void load(const void* blob, int length) { | 127 void load(const void* blob, int length) { |
124 wrapper_ = Wrapper::ParseFromBlob(blob, length); | 128 wrapper_ = Wrapper::ParseFromBlob(blob, length); |
125 } | 129 } |
126 | 130 |
127 scoped_refptr<Wrapper> wrapper_; | 131 scoped_refptr<Wrapper> wrapper_; |
128 }; | 132 }; |
129 | 133 |
| 134 template <typename T, typename Traits> |
| 135 size_t EstimateMemoryUsage(const ProtoValuePtr<T, Traits>& ptr) { |
| 136 return ptr? EstimateMemoryUsage(ptr.value()) : 0; |
| 137 } |
| 138 |
130 } // namespace syncer | 139 } // namespace syncer |
131 | 140 |
132 #endif // COMPONENTS_SYNC_BASE_PROTO_VALUE_PTR_H_ | 141 #endif // COMPONENTS_SYNC_BASE_PROTO_VALUE_PTR_H_ |
OLD | NEW |