Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // | 88 // |
| 89 // Note that reattachThread() does nothing if assertion is not enabled. | 89 // Note that reattachThread() does nothing if assertion is not enabled. |
| 90 // | 90 // |
| 91 | 91 |
| 92 template <typename T> | 92 template <typename T> |
| 93 class Supplementable; | 93 class Supplementable; |
| 94 | 94 |
| 95 template <typename T> | 95 template <typename T> |
| 96 class Supplement : public GarbageCollectedMixin { | 96 class Supplement : public GarbageCollectedMixin { |
| 97 public: | 97 public: |
| 98 // TODO(haraken): Remove the default constructor. | |
|
sof
2017/01/19 07:38:39
I'd argue that this isn't a natural goal for all s
| |
| 99 // All Supplement objects should be instantiated with m_host. | |
| 100 Supplement() {} | |
| 101 explicit Supplement(T& host) : m_host(&host) {} | |
| 102 T* host() const { return m_host; } | |
| 103 | |
| 98 static void provideTo(Supplementable<T>& host, | 104 static void provideTo(Supplementable<T>& host, |
| 99 const char* key, | 105 const char* key, |
| 100 Supplement<T>* supplement) { | 106 Supplement<T>* supplement) { |
| 101 host.provideSupplement(key, supplement); | 107 host.provideSupplement(key, supplement); |
| 102 } | 108 } |
| 103 | 109 |
| 104 static Supplement<T>* from(Supplementable<T>& host, const char* key) { | 110 static Supplement<T>* from(Supplementable<T>& host, const char* key) { |
| 105 return host.requireSupplement(key); | 111 return host.requireSupplement(key); |
| 106 } | 112 } |
| 107 | 113 |
| 108 static Supplement<T>* from(Supplementable<T>* host, const char* key) { | 114 static Supplement<T>* from(Supplementable<T>* host, const char* key) { |
| 109 return host ? host->requireSupplement(key) : 0; | 115 return host ? host->requireSupplement(key) : 0; |
| 110 } | 116 } |
| 111 | 117 |
| 112 DEFINE_INLINE_VIRTUAL_TRACE() {} | 118 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_host); } |
| 119 | |
| 120 private: | |
| 121 Member<T> m_host; | |
| 113 }; | 122 }; |
| 114 | 123 |
| 115 // Supplementable<T> inherits from GarbageCollectedMixin virtually | 124 // Supplementable<T> inherits from GarbageCollectedMixin virtually |
| 116 // to allow ExecutionContext to derive from two GC mixin classes. | 125 // to allow ExecutionContext to derive from two GC mixin classes. |
| 117 template <typename T> | 126 template <typename T> |
| 118 class Supplementable : public virtual GarbageCollectedMixin { | 127 class Supplementable : public virtual GarbageCollectedMixin { |
| 119 WTF_MAKE_NONCOPYABLE(Supplementable); | 128 WTF_MAKE_NONCOPYABLE(Supplementable); |
| 120 | 129 |
| 121 public: | 130 public: |
| 122 void provideSupplement(const char* key, Supplement<T>* supplement) { | 131 void provideSupplement(const char* key, Supplement<T>* supplement) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 }; | 183 }; |
| 175 | 184 |
| 176 template <typename T> | 185 template <typename T> |
| 177 struct ThreadingTrait<Supplementable<T>> { | 186 struct ThreadingTrait<Supplementable<T>> { |
| 178 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 187 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 179 }; | 188 }; |
| 180 | 189 |
| 181 } // namespace blink | 190 } // namespace blink |
| 182 | 191 |
| 183 #endif // Supplementable_h | 192 #endif // Supplementable_h |
| OLD | NEW |