OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_SUPPORTS_USER_DATA_H_ | 5 #ifndef BASE_SUPPORTS_USER_DATA_H_ |
6 #define BASE_SUPPORTS_USER_DATA_H_ | 6 #define BASE_SUPPORTS_USER_DATA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 | 10 |
10 #include "base/base_export.h" | 11 #include "base/base_export.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 // This is a helper for classes that want to allow users to stash random data by | 18 // This is a helper for classes that want to allow users to stash random data by |
19 // key. At destruction all the objects will be destructed. | 19 // key. At destruction all the objects will be destructed. |
20 class BASE_EXPORT SupportsUserData { | 20 class BASE_EXPORT SupportsUserData { |
21 public: | 21 public: |
22 SupportsUserData(); | 22 SupportsUserData(); |
23 | 23 |
(...skipping 16 matching lines...) Expand all Loading... |
40 // SupportsUserData is not thread-safe, and on debug build will assert it is | 40 // SupportsUserData is not thread-safe, and on debug build will assert it is |
41 // only used on one thread. Calling this method allows the caller to hand | 41 // only used on one thread. Calling this method allows the caller to hand |
42 // the SupportsUserData instance across threads. Use only if you are taking | 42 // the SupportsUserData instance across threads. Use only if you are taking |
43 // full control of the synchronization of that hand over. | 43 // full control of the synchronization of that hand over. |
44 void DetachUserDataThread(); | 44 void DetachUserDataThread(); |
45 | 45 |
46 protected: | 46 protected: |
47 virtual ~SupportsUserData(); | 47 virtual ~SupportsUserData(); |
48 | 48 |
49 private: | 49 private: |
50 using DataMap = std::map<const void*, scoped_ptr<Data>>; | 50 using DataMap = std::map<const void*, std::unique_ptr<Data>>; |
51 | 51 |
52 // Externally-defined data accessible by key. | 52 // Externally-defined data accessible by key. |
53 DataMap user_data_; | 53 DataMap user_data_; |
54 // Guards usage of |user_data_| | 54 // Guards usage of |user_data_| |
55 ThreadChecker thread_checker_; | 55 ThreadChecker thread_checker_; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(SupportsUserData); | 57 DISALLOW_COPY_AND_ASSIGN(SupportsUserData); |
58 }; | 58 }; |
59 | 59 |
60 // Adapter class that releases a refcounted object when the | 60 // Adapter class that releases a refcounted object when the |
(...skipping 12 matching lines...) Expand all Loading... |
73 | 73 |
74 private: | 74 private: |
75 scoped_refptr<T> object_; | 75 scoped_refptr<T> object_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); | 77 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); |
78 }; | 78 }; |
79 | 79 |
80 } // namespace base | 80 } // namespace base |
81 | 81 |
82 #endif // BASE_SUPPORTS_USER_DATA_H_ | 82 #endif // BASE_SUPPORTS_USER_DATA_H_ |
OLD | NEW |