OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2012 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // | 86 // |
87 // Note that reattachThread() does nothing if assertion is not enabled. | 87 // Note that reattachThread() does nothing if assertion is not enabled. |
88 // | 88 // |
89 | 89 |
90 template<typename T> | 90 template<typename T> |
91 class Supplementable; | 91 class Supplementable; |
92 | 92 |
93 template<typename T> | 93 template<typename T> |
94 class Supplement : public GarbageCollectedMixin { | 94 class Supplement : public GarbageCollectedMixin { |
95 public: | 95 public: |
96 // TODO(haraken): Remove the default constructor. | |
97 // All Supplement objects should be instantiated with m_host. | |
98 Supplement() { } | |
99 explicit Supplement(T& host) : m_host(&host) { } | |
100 T* host() const { return m_host; } | |
101 | |
96 static void provideTo(Supplementable<T>& host, const char* key, Supplement<T >* supplement) | 102 static void provideTo(Supplementable<T>& host, const char* key, Supplement<T >* supplement) |
97 { | 103 { |
98 host.provideSupplement(key, supplement); | 104 host.provideSupplement(key, supplement); |
99 } | 105 } |
100 | 106 |
101 static Supplement<T>* from(Supplementable<T>& host, const char* key) | 107 static Supplement<T>* from(Supplementable<T>& host, const char* key) |
102 { | 108 { |
103 return host.requireSupplement(key); | 109 return host.requireSupplement(key); |
104 } | 110 } |
105 | 111 |
106 static Supplement<T>* from(Supplementable<T>* host, const char* key) | 112 static Supplement<T>* from(Supplementable<T>* host, const char* key) |
107 { | 113 { |
108 return host ? host->requireSupplement(key) : 0; | 114 return host ? host->requireSupplement(key) : 0; |
109 } | 115 } |
110 | 116 |
111 DEFINE_INLINE_VIRTUAL_TRACE() { } | 117 DEFINE_INLINE_VIRTUAL_TRACE() |
118 { | |
119 visitor->trace(m_host); | |
120 } | |
121 | |
122 private: | |
123 WeakMember<T> m_host; | |
sof
2016/07/13 07:20:41
Thinking about this some more, what value does it
haraken
2016/07/13 07:24:26
Many Supplement classes that inherit from DOMWindo
sof
2016/07/13 07:39:41
ok, thanks for clarifying the purpose, i.e., |m_ho
haraken
2016/07/13 07:42:12
Yes, right.
| |
112 }; | 124 }; |
113 | 125 |
114 // Supplementable<T> inherits from GarbageCollectedMixin virtually | 126 // Supplementable<T> inherits from GarbageCollectedMixin virtually |
115 // to allow ExecutionContext to derive from two GC mixin classes. | 127 // to allow ExecutionContext to derive from two GC mixin classes. |
116 template<typename T> | 128 template<typename T> |
117 class Supplementable : public virtual GarbageCollectedMixin { | 129 class Supplementable : public virtual GarbageCollectedMixin { |
118 WTF_MAKE_NONCOPYABLE(Supplementable); | 130 WTF_MAKE_NONCOPYABLE(Supplementable); |
119 public: | 131 public: |
120 void provideSupplement(const char* key, Supplement<T>* supplement) | 132 void provideSupplement(const char* key, Supplement<T>* supplement) |
121 { | 133 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 }; | 183 }; |
172 | 184 |
173 template<typename T> | 185 template<typename T> |
174 struct ThreadingTrait<Supplementable<T>> { | 186 struct ThreadingTrait<Supplementable<T>> { |
175 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 187 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
176 }; | 188 }; |
177 | 189 |
178 } // namespace blink | 190 } // namespace blink |
179 | 191 |
180 #endif // Supplementable_h | 192 #endif // Supplementable_h |
OLD | NEW |