| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYNC_UTIL_SHARED_VALUE_H_ | |
| 6 #define CHROME_BROWSER_SYNC_UTIL_SHARED_VALUE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 | |
| 11 namespace browser_sync { | |
| 12 | |
| 13 template <class ValueType> | |
| 14 struct HasSwapMemFnTraits { | |
| 15 static void Swap(ValueType* t1, ValueType* t2) { | |
| 16 t1->Swap(t2); | |
| 17 } | |
| 18 }; | |
| 19 | |
| 20 // A ref-counted thread-safe wrapper around an immutable value. | |
| 21 template <class ValueType, class Traits> | |
| 22 class SharedValue | |
| 23 : public base::RefCountedThreadSafe<SharedValue<ValueType, Traits> > { | |
| 24 public: | |
| 25 SharedValue() {} | |
| 26 // Takes over the data in |value|, leaving |value| empty. | |
| 27 explicit SharedValue(ValueType* value) { | |
| 28 Traits::Swap(&value_, value); | |
| 29 } | |
| 30 | |
| 31 const ValueType& Get() const { | |
| 32 return value_; | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 ~SharedValue() {} | |
| 37 friend class base::RefCountedThreadSafe<SharedValue<ValueType, Traits> >; | |
| 38 | |
| 39 ValueType value_; | |
| 40 }; | |
| 41 | |
| 42 } // namespace browser_sync | |
| 43 | |
| 44 #endif // CHROME_BROWSER_SYNC_UTIL_SHARED_VALUE_H_ | |
| OLD | NEW |