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 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ThreadChecker thread_checker_; | 54 ThreadChecker thread_checker_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(SupportsUserData); | 56 DISALLOW_COPY_AND_ASSIGN(SupportsUserData); |
57 }; | 57 }; |
58 | 58 |
59 // Adapter class that releases a refcounted object when the | 59 // Adapter class that releases a refcounted object when the |
60 // SupportsUserData::Data object is deleted. | 60 // SupportsUserData::Data object is deleted. |
61 template <typename T> | 61 template <typename T> |
62 class UserDataAdapter : public base::SupportsUserData::Data { | 62 class UserDataAdapter : public base::SupportsUserData::Data { |
63 public: | 63 public: |
64 static T* Get(SupportsUserData* supports_user_data, const void* key) { | 64 static T* Get(const SupportsUserData* supports_user_data, const void* key) { |
65 UserDataAdapter* data = | 65 UserDataAdapter* data = |
66 static_cast<UserDataAdapter*>(supports_user_data->GetUserData(key)); | 66 static_cast<UserDataAdapter*>(supports_user_data->GetUserData(key)); |
67 return data ? static_cast<T*>(data->object_.get()) : NULL; | 67 return data ? static_cast<T*>(data->object_.get()) : NULL; |
68 } | 68 } |
69 | 69 |
70 UserDataAdapter(T* object) : object_(object) {} | 70 UserDataAdapter(T* object) : object_(object) {} |
71 T* release() { return object_.release(); } | 71 T* release() { return object_.release(); } |
72 | 72 |
73 private: | 73 private: |
74 scoped_refptr<T> object_; | 74 scoped_refptr<T> object_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); | 76 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); |
77 }; | 77 }; |
78 | 78 |
79 } // namespace base | 79 } // namespace base |
80 | 80 |
81 #endif // BASE_SUPPORTS_USER_DATA_H_ | 81 #endif // BASE_SUPPORTS_USER_DATA_H_ |
OLD | NEW |