Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: chrome/browser/sync/util/shared_value.h

Issue 7904021: [Sync] Rework SharedValue<T> into Immutable<T> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/util/immutable_unittest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/immutable_unittest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698