| 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 19 matching lines...) Expand all Loading... |
| 30 // class to any class with a virtual destructor. | 30 // class to any class with a virtual destructor. |
| 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 // TODO: remove the raw ptr version of SetUserData once everything uses |
| 41 // the unique_ptr version, see crbug.com/690937. |
| 40 Data* GetUserData(const void* key) const; | 42 Data* GetUserData(const void* key) const; |
| 41 void SetUserData(const void* key, Data* data); | 43 void SetUserData(const void* key, Data* data); |
| 44 void SetUserData(const void* key, std::unique_ptr<Data> data); |
| 42 void RemoveUserData(const void* key); | 45 void RemoveUserData(const void* key); |
| 43 | 46 |
| 44 // SupportsUserData is not thread-safe, and on debug build will assert it is | 47 // 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 | 48 // only used on one execution sequence. Calling this method allows the caller |
| 46 // to hand the SupportsUserData instance across execution sequences. Use only | 49 // to hand the SupportsUserData instance across execution sequences. Use only |
| 47 // if you are taking full control of the synchronization of that hand over. | 50 // if you are taking full control of the synchronization of that hand over. |
| 48 void DetachFromSequence(); | 51 void DetachFromSequence(); |
| 49 | 52 |
| 50 protected: | 53 protected: |
| 51 virtual ~SupportsUserData(); | 54 virtual ~SupportsUserData(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 77 | 80 |
| 78 private: | 81 private: |
| 79 scoped_refptr<T> object_; | 82 scoped_refptr<T> object_; |
| 80 | 83 |
| 81 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); | 84 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); |
| 82 }; | 85 }; |
| 83 | 86 |
| 84 } // namespace base | 87 } // namespace base |
| 85 | 88 |
| 86 #endif // BASE_SUPPORTS_USER_DATA_H_ | 89 #endif // BASE_SUPPORTS_USER_DATA_H_ |
| OLD | NEW |