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