Chromium Code Reviews| 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 #include <memory> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 class BASE_EXPORT Data { | 31 class BASE_EXPORT Data { |
| 32 public: | 32 public: |
| 33 virtual ~Data() = default; | 33 virtual ~Data() = default; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // The user data allows the clients to associate data with this object. | 36 // The user data allows the clients to associate data with this object. |
| 37 // Multiple user data values can be stored under different keys. | 37 // Multiple user data values can be stored under different keys. |
| 38 // This object will TAKE OWNERSHIP of the given data pointer, and will | 38 // This object will TAKE OWNERSHIP of the given data pointer, and will |
| 39 // delete the object if it is changed or the object is destroyed. | 39 // delete the object if it is changed or the object is destroyed. |
| 40 Data* GetUserData(const void* key) const; | 40 Data* GetUserData(const void* key) const; |
| 41 void SetUserData(const void* key, Data* data); | 41 void SetUserData(const void* key, Data* data); |
|
Nico
2017/02/10 17:54:25
add a "// TODO: remove the raw ptr version once ev
| |
| 42 void SetUserData(const void* key, std::unique_ptr<Data> data); | |
| 42 void RemoveUserData(const void* key); | 43 void RemoveUserData(const void* key); |
| 43 | 44 |
| 44 // SupportsUserData is not thread-safe, and on debug build will assert it is | 45 // SupportsUserData is not thread-safe, and on debug build will assert it is |
| 45 // only used on one execution sequence. Calling this method allows the caller | 46 // only used on one execution sequence. Calling this method allows the caller |
| 46 // to hand the SupportsUserData instance across execution sequences. Use only | 47 // to hand the SupportsUserData instance across execution sequences. Use only |
| 47 // if you are taking full control of the synchronization of that hand over. | 48 // if you are taking full control of the synchronization of that hand over. |
| 48 void DetachFromSequence(); | 49 void DetachFromSequence(); |
| 49 | 50 |
| 50 protected: | 51 protected: |
| 51 virtual ~SupportsUserData(); | 52 virtual ~SupportsUserData(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 scoped_refptr<T> object_; | 80 scoped_refptr<T> object_; |
| 80 | 81 |
| 81 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); | 82 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 } // namespace base | 85 } // namespace base |
| 85 | 86 |
| 86 #endif // BASE_SUPPORTS_USER_DATA_H_ | 87 #endif // BASE_SUPPORTS_USER_DATA_H_ |
| OLD | NEW |