| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef WTF_WeakPtr_h | 26 #ifndef WTF_WeakPtr_h |
| 27 #define WTF_WeakPtr_h | 27 #define WTF_WeakPtr_h |
| 28 | 28 |
| 29 #include "base/memory/weak_ptr.h" | 29 #include "base/memory/weak_ptr.h" |
| 30 #include "wtf/Noncopyable.h" | 30 #include "wtf/Noncopyable.h" |
| 31 | 31 |
| 32 namespace WTF { | 32 namespace WTF { |
| 33 | 33 |
| 34 template<typename T> | 34 template <typename T, typename Traits = base::DefaultWeakPtrTraits> |
| 35 using WeakPtr = base::WeakPtr<T>; | 35 using WeakPtr = base::WeakPtr<T, Traits>; |
| 36 | 36 |
| 37 template<typename T> | 37 template <typename T, typename Traits = base::DefaultWeakPtrTraits> |
| 38 class WeakPtrFactory { | 38 class WeakPtrFactory : public base::WeakPtrFactory<T, Traits> { |
| 39 WTF_MAKE_NONCOPYABLE(WeakPtrFactory<T>); | 39 WTF_MAKE_NONCOPYABLE(WeakPtrFactory); |
| 40 USING_FAST_MALLOC(WeakPtrFactory); | 40 DISALLOW_NEW(); |
| 41 |
| 42 private: |
| 43 using Base = base::WeakPtrFactory<T, Traits>; |
| 44 |
| 41 public: | 45 public: |
| 42 explicit WeakPtrFactory(T* ptr) : m_factory(ptr) { } | 46 explicit WeakPtrFactory(T* ptr) |
| 47 : Base(ptr) |
| 48 { |
| 49 } |
| 43 | 50 |
| 44 WeakPtr<T> createWeakPtr() { return m_factory.GetWeakPtr(); } | 51 WeakPtr<T, Traits> createWeakPtr() { return this->GetWeakPtr(); } |
| 45 | 52 |
| 46 void revokeAll() | 53 void revokeAll() |
| 47 { | 54 { |
| 48 m_factory.InvalidateWeakPtrs(); | 55 this->InvalidateWeakPtrs(); |
| 49 } | 56 } |
| 50 | 57 |
| 51 bool hasWeakPtrs() const | 58 bool hasWeakPtrs() const |
| 52 { | 59 { |
| 53 return m_factory.HasWeakPtrs(); | 60 return this->HasWeakPtrs(); |
| 54 } | 61 } |
| 55 | |
| 56 private: | |
| 57 base::WeakPtrFactory<T> m_factory; | |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace WTF | 64 } // namespace WTF |
| 61 | 65 |
| 62 using WTF::WeakPtr; | 66 using WTF::WeakPtr; |
| 63 using WTF::WeakPtrFactory; | 67 using WTF::WeakPtrFactory; |
| 64 | 68 |
| 65 #endif | 69 #endif |
| OLD | NEW |